Hello, we are a new team, and we have no clue how to program autonomous. So could any of you give a sample program template for us ( We know of the competition template but have no clue what to place in the Autonomous context). Also, we have a competition on the 14th. Would we be able to finish the code and test the robot before that?
What programming language are you using?
Not sure which language you’re using, but I’ll take a guess that you’re using RobotC as it’s the most popular. The first thing you need to do is make sure you are using the competition template, this will allow your robot to run driver control, auton, and be disabled at the right times when connected to the competition field control. If you don’t have it yet, create a new program with the template and paste your code into the appropriate areas. This page explains how to find it: http://help.robotc.net/WebHelpCortex/index.htm#page=functions_vex/comp_control/Competition%20Control.htm
Programming a basic autonomous is pretty simple, instead of setting motors based on joystick values they are set based on preprogrammed commands using sensors or time.
For example, here’s a simple program that uses time (but won’t be very accurate or consistent):
motor[Drive] = 127;
wait(1); //waits 1 second
motor[Drive] = -15; //Applies a brief backwards power to the motor so it brakes instead of coasts
wait(0.1);
motor[Drive] = 0;
Or you could also use an encoder if you have one installed.
motor[Drive] = 127;
while(SensorValue[Encoder] < 600) // Waits until the encoder is greater than 600 ticks
{}
motor[Drive] = -15; //Applies a brief backwards power to the motor so it brakes instead of coasts
wait(0.1);
motor[Drive] = 0;
How exactly you do your autonomous depends on your robot is set up and exactly what you want to do. Hopefully you’ll be able to work out how to do what you are aiming for (and it will take a good bit of testing and adjustment), if not just ask. The most important tip I would give you is to keep it simple and consistent. You can have a super fancy autonomous that works once or twice, and then get to the competition field and it doesn’t work anymore, so make sure you test lots and the routine is as close to 100% consistent as possible.
Sorry I am using RobotC. Thank you.
Thank You, but I still am wondering: which is more reliable and easier to use - time controlled or encoder controlled? Also, how can I switch Autonomous codes in the code itself ( I know I use jumpers but I can’t figure out how to code that into the code).
Reliable, well definitely encoders (although for really reliable stuff you are looking into PID loops and stuff with your encoders). Anyway, to switch autonomous routines you could use jumpers.
With jumpers you just need to remember that when the jumper is plugged in the port it is plugged into will return 1 or true, if it is not plugged in the port will return 0 or false. A simple way of doing a autonomous routine depending on what jumper is plugged in would be to do:
// If the jumper switch is in port JumperSwitch1
if( jumperSwitch1 == 1 )
{
// Put your first autonomous routine here
}
// If the jumper switch is in port JumperSwitch2
else if( jumperSwitch2 == 1 )
{
// Put your first autonomous routine here
}
// in all other cases
else
{
// Put your default autonomous routine here
}
Now with this you will have to define JumperSwitch1&2 in the motor sensors setup menu. I don’t have a copy of robotC on hand, so im not entirely sure how to go about doing that, but if all else fails you could just set the port the jumper is plugged into as as a touch sensor.