RUNNING MOTORS
It is not fun programming solely for an emulator. We joined Robotics to see parts move and metal come to life! As the programmer this is our responsibility. It’s time to run motors!!! The way motors operate in RobotC is very simple. To run a motor, write “motor[ port# ] = value;” The # is replaced with the number of the port for that motor and the value should be replaced with the speed of the motor. Motor ports on the Vex Cortex are numerically labeled as follows:
(Insert Vex Cortex Picture)
The first (port 1) and last (port 10) ports only accept wires with 2 prongs whereas all of the other ports only accept wires with three prongs. If your motor only has two prongs on its end and you wish to plug it into a port other than 1 or 10, you must use a transformer which is shown below. Your builder friends should know what this means so don’t be afraid to ask them for one.
(Insert Transformer Picture)
There will be small notches on the ends of each motor wire showing how to plug the motor wire into the cortex.
(Insert motor wire picture here as well as another one showing the notch on the Cortex)
In Vex, motors run in a range of integers between and including -127 to 127. Negative being the backwards and 127 being forwards. It’s not always clear once wiring is done which way motors will run so it is beneficial to test each motor to see what value (-127 or 127) is clockwise and what value is counterclockwise and taking note of that.
Since we are done with the explanations of how to program a motor, let’s actually do it! Plug a motor into ports 1 and 2 of the Vex Cortex (remember to use a transformer if you need to for port 2). Create a new file Control N and copy the following text:
task main()
{
motor[ port1 ] = 127;
motor[ port2 ] = 127;
wait1Msec( 1000 );
motor[ port1 ] = -127;
motor[ port2 ] = -127;
wait1Msec( 1000 );
motor[ port1 ] = 0;
motor[ port 2 ] = 0;
}
This text looks quite similar to one of the codes we used in the first tutorial. The program first runs the motors plugged into ports one and two at full speed forward “motor[ port1 ] = 127;” and “motor[ port2 ] = 127;” However, after one second, “wait1Msec( 1000 );”, it reverses the direction of the motors, setting both of them to backwards, “motor[ port1 ] = -127’” and “motor[ port2 ] = -127;” Lastly, after waiting another second, “wait1Msec( 1000 );”, the program stops both motors by setting their speed to zero, “motor[ port1 ] = 0;” and “motor[ port2 ] = 0;” Since we understand how the program works, we can run it! Since we want to run the program on an actual robot, we need to change Compiler Target. Go to Robot -> Compiler Target - > Physical Robot. Press F7 to compile the program and check for errors. Now plug the A to A cable into the robot and computer (check the lights on the robot turn on when you do this). Then press F5 to upload the program to the robot. When the window pops up with the Start button, press away and watch as the program executes exactly what we told it to do.
Cheers!
(Insert Vex Cortex Picture)
The first (port 1) and last (port 10) ports only accept wires with 2 prongs whereas all of the other ports only accept wires with three prongs. If your motor only has two prongs on its end and you wish to plug it into a port other than 1 or 10, you must use a transformer which is shown below. Your builder friends should know what this means so don’t be afraid to ask them for one.
(Insert Transformer Picture)
There will be small notches on the ends of each motor wire showing how to plug the motor wire into the cortex.
(Insert motor wire picture here as well as another one showing the notch on the Cortex)
In Vex, motors run in a range of integers between and including -127 to 127. Negative being the backwards and 127 being forwards. It’s not always clear once wiring is done which way motors will run so it is beneficial to test each motor to see what value (-127 or 127) is clockwise and what value is counterclockwise and taking note of that.
Since we are done with the explanations of how to program a motor, let’s actually do it! Plug a motor into ports 1 and 2 of the Vex Cortex (remember to use a transformer if you need to for port 2). Create a new file Control N and copy the following text:
task main()
{
motor[ port1 ] = 127;
motor[ port2 ] = 127;
wait1Msec( 1000 );
motor[ port1 ] = -127;
motor[ port2 ] = -127;
wait1Msec( 1000 );
motor[ port1 ] = 0;
motor[ port 2 ] = 0;
}
This text looks quite similar to one of the codes we used in the first tutorial. The program first runs the motors plugged into ports one and two at full speed forward “motor[ port1 ] = 127;” and “motor[ port2 ] = 127;” However, after one second, “wait1Msec( 1000 );”, it reverses the direction of the motors, setting both of them to backwards, “motor[ port1 ] = -127’” and “motor[ port2 ] = -127;” Lastly, after waiting another second, “wait1Msec( 1000 );”, the program stops both motors by setting their speed to zero, “motor[ port1 ] = 0;” and “motor[ port2 ] = 0;” Since we understand how the program works, we can run it! Since we want to run the program on an actual robot, we need to change Compiler Target. Go to Robot -> Compiler Target - > Physical Robot. Press F7 to compile the program and check for errors. Now plug the A to A cable into the robot and computer (check the lights on the robot turn on when you do this). Then press F5 to upload the program to the robot. When the window pops up with the Start button, press away and watch as the program executes exactly what we told it to do.
Cheers!