You are on page 1of 3

Your Turn Viewing the Full Speed Servo Signal

Remember the servo signal is 100 times as fast as the program you just ran. First, lets try running the program ten times as fast. That means divide all the Duration arguments (PULSOUT and PAUSE) by 10. Modify the program so that the commands look like this:
DO PULSOUT 13, 6500 PULSOUT 12, 6500 PAUSE 200 LOOP

Run it and verify that it makes the LEDs blink ten times as fast. Now, lets try 100 times as fast (one hundredth of the duration). Instead of appearing to flicker, the LED will just appear to be not as bright as it would when you send it a simple high signal. Thats because the LED is flashing on and off so quickly and for such brief periods of time that the human eye cannot detect the actual on/off flicker, just a change in brightness. Modify the program so that the commands look like this:
DO PULSOUT 13, 650 PULSOUT 12, 650 PAUSE 20 LOOP
Page 40 Robotics with the Boe-Bot

Run the modified program and verify that it makes both LEDs about the same brightness. Try substituting 850 in the Duration argument for the P13 PULSOUT command.
DO PULSOUT 13, 850 PULSOUT 12, 650 PAUSE 20 LOOP

Run the modified program and verify that the P13 LED now appears slightly brighter than the P12 LED. You may have to cup your hands around the LEDs and peek inside to see the difference. They differ because the amount of time the P13 LED stays on is longer than the amount of time the P12 LED stays on. Try substituting 750 in the Duration argument for both the PULSOUT commands.
DO PULSOUT 13, 750 PULSOUT 12, 750 PAUSE 20 LOOP

Run the modified program and verify that the brightness of both LEDs is the same again. It may not be obvious, but the brightness level is between those given by Duration arguments of 650 and 850. ACTIVITY #3: CONNECTING THE SERVO MOTORS In this activity, you will build a circuit that connects the servo to a power supply and a BASIC Stamp I/O pin. The LED circuits you developed in the last activity will be used later to monitor the signals the BASIC Stamp sends to the servos to control their motion.
Parts for Connecting the Servos

(2) Parallax Continuous Rotation servos (2) Built and tested LED circuits from the previous activity

Connecting the Servos to the Board of Education

Turn off the power by setting the 3-position switch on your Board of Education to position-0 (see Figure 2-11).

Reset

012

Turn Off Power

shows the servo header on the Board of Education. This board features a jumper that you can use to connect the servos power supply to either Vin or Vdd. To move it, you have to pull it upwards and off the pair of pins it rests on, then push it onto the pair of pins you want it to rest on. If you are using the 6 V battery pack, make sure the jumper between the servo ports on the Board of Education is set to Vin as shown on the left of Figure 2-12.
About Rechargeable Batteries. The Boe-Bot requires 6 V, easily obtained from 4 AA 1.5 V batteries. Alkaline AA batteries are 1.5 V. However, many rechargeable AA batteries supply only 1.2 V, giving a total of 4.8 V, which is not enough to power the BASIC Stamp and BoeBot. If you cannot find 1.5 V rechargeable batteries, you may use the inexpensive Boe-Boost (#30078) to add a 5th 1.2 V rechargeable battery, bringing the total back to 6 V.

Example Program: BothServosThreeSeconds.bs2

Heres an example of making the servos turn in one direction for three seconds, then reversing their direction. Enter, save, and run BothServosThreeSeconds.bs2.
' Robotics with the Boe-Bot - BothServosThreeSeconds.bs2 ' Run both servos in opposite directions for three seconds, then reverse ' the direction of both servos and run another three seconds. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!" counter VAR Byte FOR counter = 1 TO 122 PULSOUT 13, 850 PULSOUT 12, 650 PAUSE 20 NEXT FOR counter = 1 TO 122 PULSOUT 13, 650 PULSOUT 12, 850 PAUSE 20 NEXT END

Verify that each servo turned one direction for three seconds, and then reversed direction and turned for three more seconds. Did you notice that while the servos reversed at the same moment, they were always turning in opposite directions? Why would this be useful?
Your Boe-Bots Servo Motors Page 67

Your Turn Predict Servo Run Time

Pick a time (six seconds or less), that you want your servos to turn. Divide the number of seconds by 0.024. Your answer is the number of loops you will need. Modify BothServosThreeSeconds.bs2 so that it makes both servos run for the amount of time you selected. Compare your predicted run time to the actual run time. Remember to disconnect power from your system (board and servos) when you are done.
TIP To measure the run time, press and hold the Reset button on your Board of Education (or BASIC Stamp HomeWork Board). When you are ready to start timing, let go of the Reset button.

SUMMARY This chapter guided you through connecting, adjusting, and testing the Parallax Continuous Rotation servos. Along the way, a variety of PBASIC commands were introduced. The PAUSE command makes the program stop for brief or long periods of time, depending on the Duration argument you use. DOLOOP makes repeating a single or

group of PBASIC commands over and over again efficient. HIGH and LOW were introduced as a way of making the BASIC Stamp connect an I/O pin to Vdd or Vss. High and low signals were viewed with the help of an LED circuit. These signals were used to introduce timing diagrams. The PULSOUT command was introduced as a more precise way to deliver a high or low signal, and an LED circuit was also used to view signals sent by the PULSOUT command. DOLOOP, PULSOUT, and PAUSE were then used to send the Parallax Continuous Rotation servos the signal to stay still, which is 1.5 ms pulses every 20 ms. The servo was adjusted with a screwdriver while receiving the 1.5 ms pulses until it stayed still. This process is called centering the servo. After the servos were centered, variables were introduced as a way to store values. Variables can be used in math operations and counting. FORNEXT loops were introduced as a way to count. FORNEXT loops control the number of times the lines of code between the FOR and NEXT statements are executed. FORNEXT loops were then used to control the number of pulses delivered to a servo, which in turn controls the amount of time the servo runs.

You might also like