ACTIVITIES

Turning on the Motors

Code for Testing the Motors

Turning on the Servo Motors

Steering the Servo Motors

Wheels and Navigation

Back to the main activity page

In robotics, motors are known as effectors. Effectors change the state of a robot. Additionally, robots use effectors to change the environment around them. Other examples of effectors are arms, thrusters, legs, voice synthesizers, buzzers, lights, serial lines, comm ports, and radios. The motors used in the Cyber Laboratory activities are DC motors or PMDC (permanent magnet, direct current). Britt Rorabaugh explains that, "Permanent-magnet DC motors are so named because they use permanent magnets instead of field windings to create the field flux for the motor. Toys and other inexpensive items often contain permanent-magnet DC motors. Therefore, this type of motor is one of the easiest for experimenters to obtain. The stator consists of permanent magnets that provide a constant magnetic field. Current is passed to the armature windings via brushes and commutator segments. Connections between the windings and the commutator segments are arranged so as to change the polarity of the armature at the appropriate times for continuous rotation of the armature" (Rorabaugh, 1995).

Magnets inside the motor cause it to spin one direction or another depending upon polarity. Some motors contain no gears and spin very fast, and have little if any torque. Torque is the measure of how hard the motor can twist its shaft. Torque varies with speed, from the maximum push when the motor is stalled, down to the minimum torque at the motor's maximum speed (Wise, 1999). To produce more torque, these motors must be geared down. Highly geared motors have a significant amount of torque, but are slow. The ideal motor maintains a good balance of torque and speed. The HandyBoard (HB) has four motor ports, numbered from 0 - 3. The RCX has three motor ports (1, 2, 3). Motors may be set in a forward direction (corresponding to the green motor LED being lit on the HB or > arrow on the RCX display) and a backward direction (corresponding to the motor red LED on the HB or < arrow on the RCX). Making a motor run forward, backwards, and turning it off are easy using Interactive C.

 

 

 

Figure 1. Three LEGO motors L to R: high torque/high speed motor, high speed motor, mini motor



ACTIVITY #1 TURNING ON THE MOTORS

Back to the top

The LEGO motors can be turned on easily using the IC software and the HandyBoard (HB) or RCX. In fact, you don't even have to write a complete program. You can send commands directly from the IC text box. The LEGO motors included with your kit must each be connected to a motor wire. The motor wire looks like a black 2x2 LEGO plate with a black wire coming out. The plate fits into the motor under or over the metal contacts on the motor (depending on the motor type). The plug end of the wire plugs into the DC motor outputs [3]) on the left front edge of the HB while for the RCX either end is a LEGO plate. For the HB each motor occupies three holes on the output header. Make sure that a motor is plugged into a full triplet, and is not displaced by one or two holes. The plug on the motors is symmetrical and can be inserted in any of four orientations, two for one polarity and two for the other. The polarity will effect which direction the motor rotates for a given command. The correct polarity depends on the application you choose, so some experimentation is needed. The motors can be started using the forward fd(n); backward bk(n); or desired speed motor(n,s); functions. We'll become familiar with these functions in the next few activities. Click here for a quick IC tutorial

MATERIALS NEEDED: HB setup, or [add RCX setup link] two LEGO geared motors, two motor wire connectors, PC or Mac computer

PROCEDURE

1. Attach the two motors to the connector wires. Next, attach the wire plugs to HB or RCX motor ports 1 and 3.
2. Turn the HB or RCX on.
3. Open your Interactive C software. Make sure the computer is talking to the controller.
4. In the text box you should see a (>). You can write commands in this text box in following the (>) notation.
5. To make the motor in port 1 go forward, write: fd(1);
6. The motor in port 1 is set to full speed. To stop the motor, type: off(1);
7. Turn on motors 1 and 3 in a forward direction.
8. Make motor 1 go backwards and motor 3 go forwards.
9. You can change the speed of your motors. For example motor(1,100) means motor 1 is turning at 100 or full speed. Using the motor(n,s); function type in these variables: a. (n=1,s=100), b. (n=1,s=50), c. (n=1,s=0). Is there much difference in motor speed?

ACTIVITY #2 CODE FOR TESTING MOTORS

Back to the top

In this activity, you will learn how to use the IC code below to test the forward and reverse statements and time variables for your robot's motors.

MATERIALS NEEDED: HB setup, or [add RCX setup link] two LEGO geared motors, two motor wire connectors, PC or Mac computer, and Interactive C application software

PROCEDURE

1. Connect your HB or RCX (via the tower) to the computer and prepare to download the motor test code
2. Copy the code below or cut and paste it into the IC text editor.
3. Save and download this file; turn off and then turn on your HB. The HB screen should be reading "Press START to test motors" On the RCX the five character screen should read “PrGn P” (start_button is equated to the prgm_button.)

 void main() {
printf("Press START to test motors\n");

// for RCX - printf(“prgmp”);
while(!start_button());
fd(1); msleep(5000L);
bk(1); msleep(5000L);
off(1);
fd(3); msleep(5000L);
bk(3); msleep(5000L);
off(3);

}

 

4. Again, the statement fd stands for forward movement of the motor. Within parenthesis is a number that represents the motor. Thus, fd(1) tells the HandyBoard to move motor 1 forward. Change the motor values within the test motor code and test motors in each port. Are your colored lights working? Which color is lit up when the motor turns clockwise? The statement off(1) means motor 1 stop.
5. Remember that the command bk stands for backwards movement of the motor. Which color bulb is lit up when the motor turns counterclockwise?
6. The statement msleep means controller sleep, or wait time in milliseconds. The Numerical time values are added as long integers (required by the function). For example 1000L stands for 1000 milliseconds or 1 second, 10000L stands for 10 seconds, etc. Experiment with different sleep variables.
7. Write a program that will make motor 2 spin forward for 12 seconds, then spin backwards for 7 seconds and turn off. Start off with the while(!start_button()) which tells the HandyBoard to wait in the while loop and continue the program only when the start button is pressed.

SERVO MOTORS

 

 

In the previous activities we explored LEGO DC motors which rotate open loop and continuously when voltage is applied. Servos only rotate to a commanded angle. In his book, "Applied Robotics", Edwin Wise describes the servo motor as a closed loop device. He says, "Given a signal, it adjusts itself until it matches the signal. If conditions change (such as the external force on the motor shifts), the motor changes to match them. Servos are used in radio control model airplanes and cars. They are simple DC motors with gearing and a feedback control system. Model servo motors are designed to oscillate about a fixed angle rather that rotate, though it is possible to physically modify them to serve as drive motors" (Wise, 1999).

 

 

 

 

Figure 2. Servo motor



The servo motors have a three pin female connector and can only be controlled by the HB. They plug onto the triplets of pins (male connectors) along the left side of the expansion board. Normally, the servo is turned on during the main routine and left on for the duration of the program. It can be turned off to save battery power, however the servo can be repositioned quite easily when power is removed. The servo motor can turn approximately 180 degrees. The HandyBoard expansion board provides outputs for six servo motors, numbered from 0 to 5. The following function is used to enable and disable the servo control signals:

init_expbd_servos(1); /* turns on the servo power */
init_expbd_servos(0); /* turns off the servo power */

The servos are turned off every time the HB is reset. Six predefined global variables are provided for controlling the position of the six servo motors. These globals are named: servo0, servo1, servo2, servo3, servo4, and servo5, for servo outputs 0 through 5 respectively. When the expansion board servo drivers are loaded, these variables are defined as globals in the Interactive C environment. The values determine the length of the timing pulse provided to each servo, which in turn corresponds to a rotational position of the servo motor. Valid values range from 0 to about 4000. You can modify these globals with simple assignment statements; e.g., servo3 = 1500. The servo motors can only be used with the HB, and are not compatible with the RCX controller.

ACTIVITY #3 TURNING ON THE SERVO MOTORS

Back to the top

This is a simple exercise that will instruct users on how to turn the servo motors on. Users will learn a basic computer program and will be encouraged to manipulate the motor variables. When plugging a servo motor into the HandyBoard, make sure the white wire is on the right side (the inside) of the servo motor input pins. Be very careful of the HandyBoard servo motor pins as they are very sharp.

MATERIALS NEEDED: HandyBoard setup, two servo motors, PC or Mac computer, Interactive C application software.

PROCEDURE

1. Plug the servo motors into servo ports 1 and 2.
2. Turn on the HandyBoard and make sure the computer is talking to the board.
3. Type or cut and paste the program below into a new IC program window.
4. Load the program, turn the HandyBoard off and on again to initiate the program.
5. Press Start
6. Change the servo1 variable to 3000 and the servo2 variable to 500. Did you see a difference in the distance turned for both?
7. Change the init_expbd_servos(1); to init_expbd_servos(0);
8. How did this change impact the servo behavior? Explain.

 void main() {

printf("Press START to set Servos 1&2\n"); /* prints Press START to set Servos 1&2 to display */
while(!start_button()); /* wait until the start button is pushed */
init_expbd_servos(1); /* turns on the servo power */
servo1= 1500; /* servo 1 will turn 1500 */
servo2= 1500; /* servo 2 will turn 1500 */
}

ACTIVITY #4 STEERING THE SERVO MOTORS

Back to the top

It is good to test the dynamics of your servo(s) before you put it on your robot. This allows you to see how the servo behaves so that you can develop a strategy for attaching it to your robot. In this activity, it is assumed the HB is attached to a three wheel robot with motors on two wheels a steering wheel attached to a servo; the user will write a simple program for turning on two LEGO motors and steering the servo. Users are encouraged to experiment with the variables and become familiar with the program structure.

MATERIALS NEEDED: HandyBoard setup, 2 LEGO motors, one servo motor, a three wheel LEGO robot, PC or Mac computer

PROCEDURE

1. Connect the two LEGO motors to motor ports 0 and 1.
2. Connect the servo motor to servo port 1. Make sure the white wire is on the right side of the servo inputs
3. Type or cut and paste the program below into a new IC program window.
4. Load the program, turn the HandyBoard off and on again to initiate the program.
5. Press the Start button. Describe your observations of the test.
6. Now change the sleep numbers and run the test.
7. Now change the servo motor variable assignments and run the test.
8. Switch lines of the program code around. How does this change the sequence of events for this task? Describe your observations following the changes.

 void main() {

printf("Servo Run\n");
while(!start_button());
init_expbd_servos(1);
servo1= 2000;
fd(0);
fd(1);
msleep(3000L);
off(0);
off(1);
msleep(1000L);
servo1=1000;
fd(0);
fd(1);
msleep(3000L);
off(0);
off(1);
}



Back to the Top

Back to the Main Activity Page

Please send any questions or comments to curriculum@kipr.org

 


Go to The Botball Home Page