Hello,
For this year’s competition, my team and I are writing two different autonomous codes, one for each side of the pit. My question is how would you make it so you can select one of the autonomous codes before the match using push buttons.
Thanks,
DaOctoOw
It is easier to do with a limit switch. Configure a digital port as a limit switch, plug it in, mount it so you can easily reach it. Note that if the switch is closed it will read as a 1. So:
if (SensorValue[autonomousSwitch])
{
// Switch is closed
// run one of the autonomous routines
}
else
{
// Switch is open
// run the other one
}
Use a rubber band to hold the switch closed if you want to run the “Switch is closed” routine. Take the rubber band off to run the other one.
does anyone have sample code for a potentiometer auton selecter?
Here’s a simple one. It has comments that describe shorter ways to write the code.
int autoNumber;
void pre_auton()
{
// choose autonomous based on potentiometer setting
// Potentiometers give values from 0 to 4096, and we divide
// the range up into a number of selections
// stay in this loop while the competition controller has the robot disabled
// The second condtion, autoNumber = 0, makes the loop execute at least once
// to pick up a non-zero value even if the robot is enabled.
while (bIfiRobotDisabled || (autoNumber == 0))
{
// All the if and else if stuff below can be replaced by these lines, where
// you set "choices" to be the number of autonomous choices you want. Here
// it is with 4:
// int choices = 4;
// int rangePerChoice;
// rangePerChoice = 4096/choices;
// autonumber = (SensorValue[selector] + rangePerChoice - 1 )/rangePerChoice;
// or, you can substitute in the values and just put in the one line that does
// all the work.
// for 4 choices, rangePerChoice is 1024, and the line looks like:
// autonumber = (SensorValue[selector] + 1023)/1024;
// for 8 choices, rangerPerChoice is 512, and the line looks like:
// autonumber = (SensorValue[selector] + 511)/512;
// Since all that is a bit more cryptic, I've written out the long way below
if (SensorValue[selector] < 1024)
{
autoNumber = 1;
}
else if (SensorValue[selector] < 2048)
{
autoNumber = 2;
}
else if (SensorValue[selector] < 3072)
{
autoNumber = 3;
}
else
{
autoNumber = 4;
}
// give up the CPU, even though we may have
// nothing else running in pre-autonomous
wait1Msec(10);
}
// eventually, the task will be stopped, and autonumber will have the value last read
}
Here’s how the code would look if you used the shorter representation:
int autoNumber;
void pre_auton()
{
// choose autonomous based on potentiometer setting
// Potentiometers give values from 0 to 4096, and we divide
// the range up into a number of selections
// stay in this loop while the competition controller has the robot disabled
// The second condtion, autoNumber = 0, makes the loop execute at least once
// to pick up a non-zero value even if the robot is enabled.
while (bIfiRobotDisabled || (autoNumber == 0))
{
int choices = 4;
int rangePerChoice;
rangePerChoice = 4096/choices;
autonumber = (SensorValue[selector] + rangePerChoice - 1 )/rangePerChoice;
// give up the CPU, even though we may have
// nothing else running in pre-autonomous
wait1Msec(10);
}
// eventually, the task will be stopped, and autonumber will have the value last read
}
[edited to add declaration of autoNumber and the example of short implementation.]
FWIW
Isn’t this what the jumpers included w/Cortex for. By shorting certain Digital pins runs a specific code.
We found evoking autonomous via a VEX remote button event to be very unreliable - granted it could be our inexperience.
This being said - this gent apparently figured this out: https://www.youtube.com/watch?v=Ub1bC7DGhwA
Use an LCD if you have one. Not only do they make autonomous choosing much easier, they also allow you to do many things in driver control that are very beneficial (we use ours to display battery values, swap and start autonomous, change PID constants without re-downloading code, display sensor/encoder values, move/rotate however we want, display text, and play songs via a speaker).