ROBOTC Movement Speed and Direction Motor Power Levels In this lesson, you will modify the existing program to change the motor power level. This helps you to move your robot more consistently and precisely. Moving at slower speeds can help your robot to be more consistent. All you need to do is alter the motor commands to turn the motors on with a power level lower than full power. Open your “Labyrinth” program (if it is not open already) and adjust the motor power values to make your robot move at a slower speed. 1. Change the power levels in your motor commands to move at half power. 1 2 3 4 5 6 7 8 task main() { wait1Msec(2000); bMotorReflected[port2] = 1; motor[port3] = 63; motor[port2] = 63; wait1Msec(1000); } 1.Modify this code The motor’s power range is from -127 (full speed backward) to 127 (full speed forward). Half of that is approximately 63. To move forward at half speed, change both motor power levels to 63. 2. Compile, download and run your program. Note that downloading automatically saves your program. 2a.Compile and Download Choose Robot > Compile and Download Program. 2b. Run the Program © Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems Speed and Direction • 1 ROBOTC Movement Speed and Direction Motor Power Levels (cont.) Checkpoint The numeric value assigned to each motor in the motor commands represents the power that the motors run with. So far, we have changed them from full power (127) to approximately half power (63). Since your robot is now traveling more slowly, it will need to travel farther to go the same distance. Distance changed Traveling for the same amount of time but at a slower speed causes the robot to stop short of its destination. 3. Since the power has been halved, try doubling the time. 1 2 3 4 5 6 7 task main() { bMotorReflected[port2] = 1; motor[port3] = 63; motor[port2] = 63; wait1Msec(2000); } 3.Modify this code Since the motors are running at half power, double the amount of time from 1000 milliseconds to 2000. 4. Compile, download, and run the program again. 4a.Download the program to the robot Choose Robot > Compile and Download Program. 4b. Run the Program © Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems Speed and Direction • 2 ROBOTC Movement Speed and Direction Motor Power Levels (cont.) 5. Check the robot’s actual performance in the first corridor of the Labyrinth. If the robot moved to where you wanted it to stop, then go on to the next section. If not, continue to make adjustments to the wait1msec command until the robot stops where you want it to. End of Section Your robot is traveling approximately the same distance, but at a slower speed than before. Adjusting the values of the motor power levels to 63 creates a forward movement at half power. Doing so makes the robot move more precisely. However, when you give the robot less power, it takes longer to go a certain distance. You can compensate for this by giving the robot more time to perform the behavior. Traveling at this speed, the robot is able to maneuver more consistently, and its behaviors are easier to see and identify. © Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems Speed and Direction • 3 ROBOTC Movement Speed and Direction Turn and Reverse In this lesson, you will learn about zero and negative motor power levels, and how the robot responds to various combinations of powers on its two motors. Setting both motors to half power makes the robot go more slowly. What do other combinations of motor powers do? 1.. Negative power numbers make the motor spin in reverse. 1 2 3 4 5 6 7 8 task main() { wait1Msec(2000); bMotorReflected[port2] = 1; motor[port3] = -127; motor[port2] = -127; wait1Msec(2000); } 1a. Modify this code Change the motor power values from 63 to –127 to make the motors spin in reverse at full power. 1b. Compile and Download Choose Robot > Compile and Download Program to send your program to the robot. 1c. Run the Program 1d. Move in reverse When you run the program, the robot now moves in reverse! © Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems Speed and Direction • 4 ROBOTC Movement Speed and Direction Turn and Reverse (cont.) 2.. A motor power of 0 (zero) provides no power to the motors, so they do not turn. 1 2 3 4 5 6 7 8 task main() { wait1Msec(2000); bMotorReflected[port2] = 1; motor[port3] = 0; motor[port2] = 0; wait1Msec(2000); } 2a. Modify this code Change the motor power levels to 0 for both motors. 2b. Compile and Download Choose Robot > Compile and Download Program to send your program to the robot. 2c. Run the Program 2d. Robot does not move The robot appears to be doing nothing! Setting the motor power levels to 0 causes the motors to not turn. © Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems Speed and Direction • 5 ROBOTC Movement Speed and Direction Turn and Reverse (cont.) 3.. Giving different powers to the two motors causes the robot to turn in different ways. Giving them opposite powers causes the robot to turn in place, or perform a point turn. 1 2 3 4 5 6 7 task main() { bMotorReflected[port2] = 1; motor[port3] = -127; motor[port2] = 127; wait1Msec(2000); } 3a. Modify this code Change the motor power levels to –127 for motor port 3 and 127 for port 2. 3b. Compile and Download Choose Robot > Compile and Download Program to send your program to the robot. 3c. Run the Program 3d. Robot does a left point turn Making the motor on port 3 go backward while the motor on port 2 goes forward causes a point turn in place to the left. © Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems Speed and Direction • 6 ROBOTC Movement Speed and Direction Turn and Reverse (cont.) 4.. Making one wheel move while the other remains stationary causes the robot to perform a swing turn with the stationary wheel acting as a pivot. 1 2 3 4 5 6 7 task main() { bMotorReflected[port2] = 1; motor[port3] = 0; motor[port2] = 127; wait1Msec(2000); } 4a. Modify this code Change the motor power levels to 0 for motor port 3 and –127 for port 2. 4b. Compile and Download Choose Robot > Compile and Download Program to send your program to the robot. 4c. Run the Program 4d. Robot does a left swing turn Holding the motor on port 3 stationary while having the motor on port 2 move forward causes a swing turn to the left. © Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems Speed and Direction • 7 ROBOTC Speed and Direction Turn and Reverse (cont.) Checkpoint The following table shows the different types of movement that result from various combinations of motor powers. Remember, these commands only set the motor powers. A wait1Msec command is still needed to tell the robot how long to let them run. Motor commands Resulting movement motor[port3]=127; motor[port2]=127; motor[port3]=63; motor[port2]=63; motor[port3]=-127; motor[port2]=-127; motor[port3]=0; motor[port2]=0; motor[port3]=127; motor[port2]=-127; motor[port3]=127; motor[port2]=0; motor[port3]=127; motor[port2]=63; © Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems Speed and Direction • 8 ROBOTC Movement Speed and Direction Turn and Reverse (cont.) 5.. You now know all the necessary behaviors needed to navigate through the Labyrinth. Let’s see if we can improve upon the movement of the robot by making it turn left once it has reached the intersection. 1 2 3 4 5 6 7 8 9 10 11 12 task main() { wait1Msec(2000); bMotorReflected[port2] = 1; motor[port3] = 63; motor[port2] = 63; wait1Msec(2000); motor[port3] = -63; motor[port2] = 63; wait1Msec(400); } 5a. Modify this code Change the motor power levels back to having it go approximately half power, or 63. 5b. Add this code Add a left point turn behavior after the forward behavior. Have the robot turn left for 400 milliseconds (0.4 seconds). 5c. Compile and Download Choose Robot > Compile and Download Program to send your program to the robot. 8. Compile and download the program, then run it. 5d. Run the Program 5e. Robot does a left point turn The robot travels forward for two seconds, then executes a left point turn. © Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems Speed and Direction • 9 ROBOTC Movement Speed and Direction Turn and Reverse (cont.) End of Section You know how to make the robot move. You improved its performance by having it maneuver at a slower speed and turn. Even so, you have probably noticed by now that the robot’s idea of “straight” is anything but straight! Continue on to the next lesson to learn one simple way to remedy this problem. ff course O This robot has drifted noticeably to the left while running. © Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems Speed and Direction • 10 ROBOTC Movement Speed and Direction Manual Straightening In this lesson, you will manually adjust the power of the motors to make your robot go straight. Lesson note The example robot used in this lesson drifts slightly to the left. If your robot drifts in the other direction, simply apply the following steps to the other motor. Even when you set the motors to go the same speed, the robot turns a little. Recall that a turn results from two motors moving at different speeds. 1 2 3 4 5 6 7 8 9 10 11 12 13 task main() { wait1Msec(2000); bMotorReflected[port2] = 1; motor[port3] = 63; motor[port2] = 63; wait1Msec(2000); Same speed? If both motors are set to the same power level, shouldn’t they go the same speed and therefore move in a straight line? motor[port3] = -63; motor[port2] = 63; wait1Msec(400); } Actually, motor speeds aren’t set with the motor commands. Motor power is, but all motors are not created equal. Differences in the robot’s construction and the manufacturing process for the motors themselves can cause different amounts of energy to be lost to friction in each motor. This means that even though both motors start with the same power at the plug, the amount of power that reaches the wheel to move the robot can vary quite a bit! Even with the same power being applied, speeds may differ. And as you know, wheels moving at different speeds make the robot turn, even if just a little bit. To fix this situation, let’s do the logical thing: change the motor powers so that both motors are going the same speed. © Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems Speed and Direction • 11 ROBOTC Movement Speed and Direction Manual Straightening (cont.) 1.. To compensate for the differences between the motors, we could either speed up the slower motor or slow down the faster one. Let’s slow down the faster one. The robot shown in this example has veered to the left, indicating that the right motor is going faster than the left. 1 2 3 4 5 6 7 8 9 10 11 12 task main() { wait1Msec(2000); bMotorReflected[port2] = 1; motor[port3] = 63; motor[port2] = 53; wait1Msec(2000); 1a. Modify this code Reduce the power of the faster motor in the Moving Forward behavior. motor[motorC] = -63; motor[motorB] = 63; wait1Msec(400); 1b. Compile and Download Select Robot > Compile and Download Program. } 1c. Run the Program 1d. Observe the behavior of your robot Did the robot go straight? This one curves to the right now! © Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems Speed and Direction • 12 ROBOTC Movement Speed and Direction Manual Straightening (cont.) 2.. We seem to have overcorrected. Our robot now curves in the opposite direction. So we will adjust our guess and go with something in between the original motor power and our last guess. 1 2 3 4 5 6 7 8 9 10 11 12 task main() { wait1Msec(2000); bMotorReflected[port2] = 1; motor[port3] = 63; motor[port2] = 58; wait1Msec(2000); 2a. Modify this code 63 was too high and 53 too low. Choose a value in between, like 58. motor[motorC] = -63; motor[motorB] = 63; wait1Msec(400); 2b. Compile and Download Select Robot > Compile and Download Program. } 2c. Run the Program 2d. Observe the behavior of your robot Did the robot go straight this time? It looks a lot better now. End of Section This method of manual straightening works, but the program values don’t work on every robot. In the example, we had to change our motor power to 58. You probably had to do something quite different with yours. Worse yet, there are obstacles out there that can’t be accounted for by programming your robot hours — or even weeks — in advance. Manual adjustment to robot power levels is good enough for now, but keep an eye open for better solutions! © Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems Speed and Direction • 13