Keily Portillo-Chapter 4 Challenges: Questions
Keily Portillo-Chapter 4 Challenges: Questions
Chapter 4 Challenges
Questions
1. What direction does the left wheel have to turn to make the BOE Shield-Bot go forward?
What direction does the right wheel have to turn?
The left wheel must go counterclockwise and the right wheel must go clockwise.
2. When the BOE Shield-Bot pivots on one wheel to the left, what are the wheels doing?
What code do you need to make the BOE Shield-Bot pivot left?
The left wheel stays unmoved while the right wheel moves clockwise.
3. If your BOE Shield-Bot veers slightly to one side when you are running a sketch to make
it go straight ahead, how do you correct this? What command needs to be adjusted and what
kind of adjustment should you make?
You correct this by slowing down the wheel that is veering off by changing the us parameter to a
number closer to 1500 and then keep raising it by increments until the bot no longer steers.
4. If your BOE Shield-Bot travels 11 in/s, how many milliseconds will it take to make it
travel 36 inches?
It will take 3727 milliseconds to travel 36 inches.
5. Why does a for loop that ramps servo speed need delay(20) in it?
Because it will make the ramp more apparent in that it will not speed up directly to 100.
6. What kind of variable is great for storing multiple values in lists?
An array.
7. What kind of loops can you use for retrieving values from lists?
for loops and do-while loops
8. What statement can you use to select a particular variable and evaluate it on a case-by-
case basis and execute a different code block for each case?
switch/case
9. What condition can you append to a do-loop?
do{...}loop while (condition)
Exercises
1. Write a routine that makes the BOE Shield-Bot back up at full speed for 2.5 seconds.
servoLeft.writeMicroseconds (1300) ;
servoLeft.writeMicroseconds (1700) ;
delay (2500) ;
2. Lets say that you tested your servos and discovered that it takes 1.2 seconds to make a
180 turn with right-rotate. With this information, write routines to make the BOE Shield-Bot
perform 30, 45, and 60 degree turns.
// 30/180 = , so use 1200/6 = 200
servoLeft.writeMicroseconds (1700) ;
servoRight.writeMicroseconds (1700) ;
delay (200) ;
// alternate approach
servoLeft.writeMicroseconds (1700) ;
servoRight.writeMicroseconds (1700) ;
delay (1200 * 30 / 180) ;
// 45/180 = , so use 1200/4 = 300
servoLeft.writeMicroseconds (1700) ;
servoRight.writeMicroseconds (1700) ;
delay (300) ;
// 60/180 = , so use 1200/3 = 400
servoLeft.writeMicroseconds (1700) ;
servoRight.writeMicroseconds (1700) ;
delay (400) ;
3. Write a routine that makes the BOE Shield-Bot go straight forward, then ramp into and
out of a pivoting turn, and then continue straight forward.
// forward 1 second
servoLeft.writeMicroseconds(1700);
servoRight.writeMicroseconds(1700);
delay(1000);
// forward again
servoLeft.writeMicroseconds(1700);
servoRight.writeMicroseconds(1700);
delay(1000);
Projects
1. It is time to fill in column 3 of Table 2-2. To do this, modify the us arguments in
the writeMicroseconds calls in the ForwardThreeSeconds sketch using each pair of values
from column 1. Record your BOE Shield-Bots resultant behavior for each pair in column 3.
Once completed, this table will serve as a reference guide when you design your own custom
BOE Shield-Bot maneuvers.
2. The diagram shows two simple courses. Write a sketch that will make your BOE Shield-
Bot navigate along each figure. Assume straight-line distances (the triangles sides and the
diameter of the circle) are either 1 yard or 1 meter.
For Circle:
// Robotics with the BOE Shield - Chapter 4, project 2 - Circle
// BOE Shield-Bot navigates a circle of 1 yard diameter.
For Triangle:
// Robotics with the BOE Shield - Chapter 4, project 2 - Triangle
// BOE Shield-Bot navigates a triangle with 1 yard sides and 120
// degree angles. Go straight 1 yard, turn 120 degrees, repeat 3 times