P. 1
Robotics_StudentWorkbook_eng

# Robotics_StudentWorkbook_eng

|Views: 580|Likes:

### Availability:

See more
See less

05/09/2014

pdf

text

original

If the same value is added to the center pulse width of one servo and subtracted from the center pulse width
of the other, the Boe-Bot will travel in a straight line, either forward or backward. When the right servo gets
a pulsout period of 500 (1.0 ms) and the left servo gets a pulsout period of 1000 (2.0 ms), the Boe-Bot
goes forward. When the pulse periods for each servo are swapped, the Boe-Bot goes backward.

If both servos receive 1.0 ms pulses, they turn in the same direction and cause the Boe-Bot to rotate
counterclockwise. If many pulses are applied, the Boe-Bot will keep rotating. If 35 or so pulses are applied,
the net effect is in the neighborhood of a 90° left turn. The same principles apply if both servos receive 2.0
ms pulses, except that the Boe-Bot will rotate clockwise instead of counterclockwise.

Programming Left and Right Turns

Program Listing 2.3 illustrates how the forward and backward routines from Program Listing 2.2 can be
modified to make the Boe-Bot execute turns.

Enter and run Program Listing 2.3.

' Robotics! v1.5, Program Listing 2.3: Turning in place.
' {\$Stamp bs2}

' Stamp Directive.

'-----Declarations-------

pulse_count var word

' Declare a word size loop counter.

'-----Initialization-----

output 2

' Set P2 to output.

freqout 2, 2000, 3000

' Send a 3 kHz signal for 2 s.

low 12

' Set P12 and 13 to output-low.

low 13

'-----Main Routine-------

main:

' Main routine

Chapter #2: Programming the Boe-Bot to Go Places

Page 54 • Robotics! Version 1.5

left_turn:

' Left turn routine.

for pulse_count = 1 to 35

' Send 35 left rotate pulses.

pulsout 12, 500

' 1.0 ms pulse to right servo.

pulsout 13, 500

' 1.0 ms pulse to left servo.

pause 20

' Pause for 20 ms.

next

pause 500

' Pause for 0.5 s.

right_turn:

' right turn routine.

for pulse_count = 1 to 35

' Send 35 left rotate pulses.

pulsout 12, 1000

' 2.0 ms pulse to right servo.

pulsout 13, 1000

' 2.0 ms pulse to left servo.

pause 20

' Pause for 20 ms.

next

pause 500

' Pause for 0.5 ms.

stop

' Stop until reset.

How the Turning in Place Program Works

Only three changes were made to Program Listing 2.2 in order to make Program Listing 2.3. First, the
forward: and backward: labels were changed to left_turn: and right_turn: respectively. Then, the
left_turn routine had both pulsout period arguments set to 500. The pulsout arguments in the
right_turn routine were both set to 1000.

Add the forward and backward routines from Program Listing 2.2 to Program Listing 2.3. To make the
Boe-Bot go forward and backward before turning left and right, insert the forward and backward
routines between the main: label and the left_turn: label. Run the program and observe the results.

Instead of using an end argument of 35 for each turn for...next loop, try end arguments of 30, 31,
32,..., 39, 40. Record the value that makes the Boe-Bot do the most precise quarter turn. The values may
or may not be the same for both left_turn and right_turn routines.

Chapter #2: Programming the Boe-Bot to Go Places

Robotics! Version 1.5 • Page 55

scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->