Anda di halaman 1dari 6

Monique Akpa

23 March 2017

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 side has to turn counterclockwise in order to go straight.
The right wheel has to go clockwise in order to straight.
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 right wheel is turning clockwise (forward), and the left wheel
is not moving.
servoLeft.writeMicroseconds(1500);
servoRight.writeMicroseconds(1300);

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?

Slow down the right wheel to correct a veer to the left, and slow
down the left wheel to correct a veer to the right. Slow down a wheel
by changing its servos writeMicroseconds us parameter, using values
closer to 1500. Start at the appropriate end of the linear speed
control range (14001600), gradually move towards 1500 in
increments of 10, and go back in smaller increments if you overshoot.

4. If your BOE Shield-Bot travels 11 in/s, how many milliseconds will it take to make it
travel 36 inches?

Given the data below, it should take about 3727 milliseconds to travel 36
inches:

BOE Shield-Bot speed = 11 in/s

BOE Shield-Bot distance = 36 in/s

time = (BOE Shield-Bot distance / BOE Shield-Bot speed) * (1000 ms / s)

= (36 / 11 ) * (1000)
= 3.727272s * 1000 ms/s

3727 ms

5. Why does a for loop that ramps servo speed need delay(20) in it?

Without that 20 ms (1/50th of a second) delay between each repetition of


the loop, it would ramp from 0 to 100 so quickly that it would seem like the BOE
Shield-Bot just stepped instantly into full speed. The ramping would not be
apparent.

6. What kind of variable is great for storing multiple values in lists?


An Array is great for storing multiple values in lists.
7. What kind of loops can you use for retrieving values from lists?

For loops and do-while loops can be used for retrieving values from lists

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 are statements that you could use to select a
particular variable and evaluate it on a case-by-case basis and execute
a different code block for each case.
9. What condition can you append to a do-loop?
The condition that you append to do a loop is 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);
servoRight.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 = 1/6, 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 = 1/4, so use 1200/4 = 300


servoLeft.writeMicroseconds(1700);
servoRight.writeMicroseconds(1700);
delay(300);

// 60/180 = 1/3, 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.
Projects
// forward 1 second
servoLeft.writeMicroseconds(1700);
servoRight.writeMicroseconds(1700);
delay(1000);

// ramp into pivot


for(int speed = 0; speed <= 100; speed+=2)
{
servoLeft.writeMicroseconds(1500);
servoRight.writeMicroseconds(1500+speed);
delay(20);
};

// ramp out of pivot


for(int speed = 100; speed >= 0; speed-=2)
{
servoLeft.writeMicroseconds(1500);
servoRight.writeMicroseconds(1500+speed);
delay(20);
}
// forward again
servoLeft.writeMicroseconds(1700);
servoRight.writeMicroseconds(1700);
delay(1000);

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.

Circle sketch:
// Robotics with the BOE Shield - Chapter 4, project 2 - Circle
// BOE Shield-Bot navigates a circle of 1 yard diameter.
#include <Servo.h> // Include servo library

Servo servoLeft; // Declare left and right servos


Servo servoRight;

void setup() // Built-in initialization block


{
tone(4, 3000, 1000); // Play tone for 1 second
delay(1000); // Delay to finish tone

servoLeft.attach(13); // Attach left signal to pin 13


servoRight.attach(12); // Attach right signal to pin 12

// Arc to the right


servoLeft.writeMicroseconds(1600); // Left wheel counterclockwise
servoRight.writeMicroseconds(1438); // Right wheel clockwise slower
delay(25500); // ...for 25.5 seconds

servoLeft.detach(); // Stop sending servo signals


servoRight.detach();
}

void loop() // Main loop auto-repeats


{ // Nothing needs repeating

Triangle sketch:
// 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

#include <Servo.h> // Include servo library

Servo servoLeft; // Declare left and right servos


Servo servoRight;

void setup() // Built-in initialization block


{
tone(4, 3000, 1000); // Play tone for 1 second
delay(1000); // Delay to finish tone

servoLeft.attach(13); // Attach left signal to pin 13


servoRight.attach(12); // Attach right signal to pin 12

for(int index = 1; index <= 3; index++)


{
// Full speed forward
servoLeft.writeMicroseconds(1700); // Left wheel counterclockwise
servoRight.writeMicroseconds(1300); // Right wheel clockwise slower
delay(5500); // ...for 5.5 seconds

// Turn left 120 degrees


servoLeft.writeMicroseconds(1300); // Left wheel counterclockwise
servoRight.writeMicroseconds(1300); // Right wheel clockwise slower
delay(700);
}
servoLeft.detach(); // Stop sending servo signals
servoRight.detach();
}

void loop() // Main loop auto-repeats


{ // Nothing needs repeating
}

Anda mungkin juga menyukai