Speed and Direction Motor Power Levels - ROBOTCcdn.robotc.net/pdfs/vex/curriculum/Movement - Speed...

13
ROBOTC Speed and Direction 1 © Carnegie Mellon Robotics Academy / For use with VEX ® Robotics Systems task main() { wait1Msec(2000); bMotorReflected[port2] = 1; motor[port3] = 63; motor[port2] = 63; wait1Msec(1000); } 1 2 3 4 5 6 7 8 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. 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. 1. Change the power levels in your motor commands to move at half power. 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

Transcript of Speed and Direction Motor Power Levels - ROBOTCcdn.robotc.net/pdfs/vex/curriculum/Movement - Speed...

Page 1: Speed and Direction Motor Power Levels - ROBOTCcdn.robotc.net/pdfs/vex/curriculum/Movement - Speed and Direction.pdf · Speed and Direction Motor Power Levels ... 1b. Compile and

ROBOTC

Speed and Direction • 1© Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems

task main() { wait1Msec(2000); bMotorReflected[port2] = 1; motor[port3] = 63; motor[port2] = 63; wait1Msec(1000); }

12345678

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. Modify this codeThe 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.

1. Change the power levels in your motor commands to move at half power.

2. Compile, download and run your program. Note that downloading automatically saves your program.

2a. Compile and DownloadChoose Robot > Compile and Download Program.

2b. Run the Program

Page 2: Speed and Direction Motor Power Levels - ROBOTCcdn.robotc.net/pdfs/vex/curriculum/Movement - Speed and Direction.pdf · Speed and Direction Motor Power Levels ... 1b. Compile and

ROBOTC

Speed and Direction • 2© Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems

Movement

3. Since the power has been halved, try doubling the time.

task main() { bMotorReflected[port2] = 1; motor[port3] = 63; motor[port2] = 63; wait1Msec(2000); }

1234567

3. Modify this codeSince 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 robotChoose Robot > Compile and Download Program.

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 changedTraveling for the same amount of time but at a slower speed causes the robot to stop short of its destination.

4b. Run the Program

Page 3: Speed and Direction Motor Power Levels - ROBOTCcdn.robotc.net/pdfs/vex/curriculum/Movement - Speed and Direction.pdf · Speed and Direction Motor Power Levels ... 1b. Compile and

ROBOTC

Speed and Direction • 3© Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems

Movement

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.

Speed and Direction Motor Power Levels (cont.)

Page 4: Speed and Direction Motor Power Levels - ROBOTCcdn.robotc.net/pdfs/vex/curriculum/Movement - Speed and Direction.pdf · Speed and Direction Motor Power Levels ... 1b. Compile and

ROBOTC

Movement

Speed and Direction • 4© Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems

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?

1a. Modify this codeChange the motor power values from 63 to –127 to make the motors spin in reverse at full power.

1. Negative power numbers make the motor spin in reverse.

task main(){ wait1Msec(2000); bMotorReflected[port2] = 1; motor[port3] = -127; motor[port2] = -127; wait1Msec(2000);}

12345678

1b. Compile and DownloadChoose Robot > Compile and Download Program to send your program to the robot.

Speed and Direction Turn and Reverse

1d. Move in reverseWhen you run the program, the robot now moves in reverse!

1c. Run the Program

Page 5: Speed and Direction Motor Power Levels - ROBOTCcdn.robotc.net/pdfs/vex/curriculum/Movement - Speed and Direction.pdf · Speed and Direction Motor Power Levels ... 1b. Compile and

ROBOTC

Movement

Speed and Direction • 5© Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems

2a. Modify this codeChange the motor power levels to 0 for both motors.

2. A motor power of 0 (zero) provides no power to the motors, so they do not turn.

task main(){ wait1Msec(2000); bMotorReflected[port2] = 1; motor[port3] = 0; motor[port2] = 0; wait1Msec(2000);}

12345678

2d. Robot does not moveThe robot appears to be doing nothing! Setting the motor power levels to 0 causes the motors to not turn.

Speed and Direction Turn and Reverse (cont.)

2b. Compile and DownloadChoose Robot > Compile and Download Program to send your program to the robot.

2c. Run the Program

Page 6: Speed and Direction Motor Power Levels - ROBOTCcdn.robotc.net/pdfs/vex/curriculum/Movement - Speed and Direction.pdf · Speed and Direction Motor Power Levels ... 1b. Compile and

ROBOTC

Movement

Speed and Direction • 6© Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems

3a. Modify this codeChange the motor power levels to –127 for motor port 3 and 127 for port 2.

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.

task main(){ bMotorReflected[port2] = 1; motor[port3] = -127; motor[port2] = 127; wait1Msec(2000);}

1234567

Speed and Direction Turn and Reverse (cont.)

3d. Robot does a left point turnMaking the motor on port 3 go backward while the motor on port 2 goes forward causes a point turn in place to the left.

3b. Compile and DownloadChoose Robot > Compile and Download Program to send your program to the robot.

3c. Run the Program

Page 7: Speed and Direction Motor Power Levels - ROBOTCcdn.robotc.net/pdfs/vex/curriculum/Movement - Speed and Direction.pdf · Speed and Direction Motor Power Levels ... 1b. Compile and

ROBOTC

Movement

Speed and Direction • 7© Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems

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.

Speed and Direction Turn and Reverse (cont.)

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.

4b. Compile and DownloadChoose Robot > Compile and Download Program to send your program to the robot.

4a. Modify this codeChange the motor power levels to 0 for motor port 3 and –127 for port 2.

task main(){ bMotorReflected[port2] = 1; motor[port3] = 0; motor[port2] = 127; wait1Msec(2000);}

1234567

4c. Run the Program

Page 8: Speed and Direction Motor Power Levels - ROBOTCcdn.robotc.net/pdfs/vex/curriculum/Movement - Speed and Direction.pdf · Speed and Direction Motor Power Levels ... 1b. Compile and

ROBOTC

Speed and Direction • 8© Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems

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;

Page 9: Speed and Direction Motor Power Levels - ROBOTCcdn.robotc.net/pdfs/vex/curriculum/Movement - Speed and Direction.pdf · Speed and Direction Motor Power Levels ... 1b. Compile and

ROBOTC

Movement

Speed and Direction • 9© Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems

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.

task main(){ wait1Msec(2000); bMotorReflected[port2] = 1; motor[port3] = 63; motor[port2] = 63; wait1Msec(2000);

motor[port3] = -63; motor[port2] = 63; wait1Msec(400);}

123456789101112

5b. Add this codeAdd a left point turn behavior after the forward behavior. Have the robot turn left for 400 milliseconds (0.4 seconds).

8. Compile and download the program, then run it.

Speed and Direction Turn and Reverse (cont.)

5c. Compile and DownloadChoose Robot > Compile and Download Program to send your program to the robot.

5e. Robot does a left point turnThe robot travels forward for two seconds, then executes a left point turn.

5d. Run the Program

5a. Modify this codeChange the motor power levels back to having it go approximately half power, or 63.

Page 10: Speed and Direction Motor Power Levels - ROBOTCcdn.robotc.net/pdfs/vex/curriculum/Movement - Speed and Direction.pdf · Speed and Direction Motor Power Levels ... 1b. Compile and

ROBOTC

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.

Off courseThis robot has drifted noticeably to the left while running.

Movement

Speed and Direction Turn and Reverse (cont.)

Speed and Direction • 10© Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems

Page 11: Speed and Direction Motor Power Levels - ROBOTCcdn.robotc.net/pdfs/vex/curriculum/Movement - Speed and Direction.pdf · Speed and Direction Motor Power Levels ... 1b. Compile and

ROBOTC

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.

123456789

10111213

task main(){ wait1Msec(2000); bMotorReflected[port2] = 1; motor[port3] = 63; motor[port2] = 63; wait1Msec(2000);

motor[port3] = -63; motor[port2] = 63; wait1Msec(400);

}

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?

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.

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 noteThe 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.

Speed and Direction • 11© Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems

Page 12: Speed and Direction Motor Power Levels - ROBOTCcdn.robotc.net/pdfs/vex/curriculum/Movement - Speed and Direction.pdf · Speed and Direction Motor Power Levels ... 1b. Compile and

ROBOTC

task main(){ wait1Msec(2000); bMotorReflected[port2] = 1; motor[port3] = 63; motor[port2] = 53; wait1Msec(2000);

motor[motorC] = -63; motor[motorB] = 63; wait1Msec(400);

}

123456789

101112

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.

1a. Modify this codeReduce the power of the faster motor in the Moving Forward behavior.

1b. Compile and DownloadSelect Robot > Compile and Download Program.

1d. Observe the behavior of your robotDid the robot go straight? This one curves to the right now!

Movement

1c. Run the Program

Speed and Direction • 12© Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems

Page 13: Speed and Direction Motor Power Levels - ROBOTCcdn.robotc.net/pdfs/vex/curriculum/Movement - Speed and Direction.pdf · Speed and Direction Motor Power Levels ... 1b. Compile and

ROBOTC

Speed and Direction Manual Straightening (cont.)

Movement

task main(){ wait1Msec(2000); bMotorReflected[port2] = 1; motor[port3] = 63; motor[port2] = 58; wait1Msec(2000);

motor[motorC] = -63; motor[motorB] = 63; wait1Msec(400);

}

123456789

101112

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.

2a. Modify this code63 was too high and 53 too low. Choose a value in between, like 58.

2b. Compile and DownloadSelect Robot > Compile and Download Program.

2d. Observe the behavior of your robotDid 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!

2c. Run the Program

Speed and Direction • 13© Carnegie Mellon Robotics Academy / For use with VEX® Robotics Systems