How to Program a VEX Robotics Clawbot
Get the programming environment., Create a new bit of code., Set up the motors., Code the while loop., Code the wheels., Code the lift., Add the claw code., Test and adapt your new code., Feel free to play around with the code and find what works...
Step-by-Step Guide
-
Step 1: Get the programming environment.
You can download RobotC for free here: http://www.robotc.net/download/vexrobotics/ , Go to File/New/New File.
You could also use a 'Competition Template' if you are planning on using this code in a competition.
But if you are just testing your robot, 'New file' works., Go to the motors and sensors set-up page (robot/motors and sensors).
When the box pops up enter in your motor name (anything you want but stick with things like front right and lift) into the corresponding port number.
Use the drop down on the right to select the type of motor you are using and check whether you need it reversed or not.
You can use trial and error to find out if it needs to be reversed or not., You will want to make sure that all of the code to control your motors is inside some type of infinite while loop.
This will make your program run smoothly as is is constantly checking to see if the controller is requesting a motor to move. task main(){ while(1==1){ } } , If you have four motors for your wheels you can set up your motors two on each side.
The code looks like this: motor= vexRT; motor= vexRT; motor= vexRT; motor= vexRT; This is taking a specific motor and assigning it to a channel; in this case, either 3 or
2.
These are the y axis on the joysticks.
The code automatically takes the position of the joystick and gives the wheels appropriate rpm (rotations per minute)., This will raise and lower the arm that your claw is on. if(vexRT==1){ motor=127; }else if(vexRT==1){ motor=-127; }else{ motor=0; } It is saying:
If Btn5U is being held down lift motor rotate forwards (clockwise) at the speed of 127 rpm.
Then- If that isn't happening is Btn5D being pressed, if that is true then rotate the motor backwards (anti-clockwise).
If none of that is happening, don't turn the motor at all., if(vexRT==1){ motor=127; }else if(vexRT==1){ motor=-127; }else{ motor=0; } This code looks a lot like the lift code but, instead of Btn5U and Btn5D it uses Btn6U and Btn6D.
This means that you use a different set of buttons on your controller for the lift and claw.
The other difference is that this bit of code activates the motor 'claw' rather than the motor 'lift'., After you have your code completed compile and download it onto your clawbot (Windows
- F5).
You can change the buttons that activate the motors and change the rpm of the motors.
The fastest the standard 393 motors can go is 127rpm. , There are other ways to make the same thing happen using robotC but the above is the easiest to create edit and understand. -
Step 2: Create a new bit of code.
-
Step 3: Set up the motors.
-
Step 4: Code the while loop.
-
Step 5: Code the wheels.
-
Step 6: Code the lift.
-
Step 7: Add the claw code.
-
Step 8: Test and adapt your new code.
-
Step 9: Feel free to play around with the code and find what works for you.
Detailed Guide
You can download RobotC for free here: http://www.robotc.net/download/vexrobotics/ , Go to File/New/New File.
You could also use a 'Competition Template' if you are planning on using this code in a competition.
But if you are just testing your robot, 'New file' works., Go to the motors and sensors set-up page (robot/motors and sensors).
When the box pops up enter in your motor name (anything you want but stick with things like front right and lift) into the corresponding port number.
Use the drop down on the right to select the type of motor you are using and check whether you need it reversed or not.
You can use trial and error to find out if it needs to be reversed or not., You will want to make sure that all of the code to control your motors is inside some type of infinite while loop.
This will make your program run smoothly as is is constantly checking to see if the controller is requesting a motor to move. task main(){ while(1==1){ } } , If you have four motors for your wheels you can set up your motors two on each side.
The code looks like this: motor= vexRT; motor= vexRT; motor= vexRT; motor= vexRT; This is taking a specific motor and assigning it to a channel; in this case, either 3 or
2.
These are the y axis on the joysticks.
The code automatically takes the position of the joystick and gives the wheels appropriate rpm (rotations per minute)., This will raise and lower the arm that your claw is on. if(vexRT==1){ motor=127; }else if(vexRT==1){ motor=-127; }else{ motor=0; } It is saying:
If Btn5U is being held down lift motor rotate forwards (clockwise) at the speed of 127 rpm.
Then- If that isn't happening is Btn5D being pressed, if that is true then rotate the motor backwards (anti-clockwise).
If none of that is happening, don't turn the motor at all., if(vexRT==1){ motor=127; }else if(vexRT==1){ motor=-127; }else{ motor=0; } This code looks a lot like the lift code but, instead of Btn5U and Btn5D it uses Btn6U and Btn6D.
This means that you use a different set of buttons on your controller for the lift and claw.
The other difference is that this bit of code activates the motor 'claw' rather than the motor 'lift'., After you have your code completed compile and download it onto your clawbot (Windows
- F5).
You can change the buttons that activate the motors and change the rpm of the motors.
The fastest the standard 393 motors can go is 127rpm. , There are other ways to make the same thing happen using robotC but the above is the easiest to create edit and understand.
About the Author
Janice Richardson
A passionate writer with expertise in creative arts topics. Loves sharing practical knowledge.
Rate This Guide
How helpful was this guide? Click to rate: