Autonomous

I am trying to program a sensor-based autonomous. What would be the best way to do so?

I will move this question into the general tech support forum. Let us know what you have tried so far and what issues you are finding, then perhaps we can help.

We use a quad encoder on our drive. We chained our front and back wheels together, and place the encoder on another sprocket between them. We use an IME to measure our arm’s position, a potentiometer to measure our claw’s position, and three sonar sensors so our robot can correct for inconsistencies.

It’s good to have some goals to work toward, some constraints to work within, or at least some interest to explore.

So:

  1. Do you have goals that you want to achieve with your autonomous program which you believe are best done (better, faster, easier, more reliably) using information from sensors? If so, what are they? If not, why do you want to uses sensors? Is it simply to demonstrate their use?
  2. What are your constraints? Do you have multiples of every sensor for VEX EDR, or are you more limited? Which specific sensors are available to you?
  3. Are there particular sensors that you’d like to use, or problems you’d like to try just to learn about a sensor? What are these interests?

We can guess, and we might get there following the “different rock” theory of project management*. But it’s not efficient, and it’s not much fun.

(* The manager says “Bring me a rock,” and the team goes off, combing the beach looking for just the right one. The team members disagree, and negotiate, eventually settling on a nice round one. It’s very smooth, and mostly gray, though a small vein of pink quartz can be seen when you hold it at just the right angle to the sun. The team goes together to meet with the manager. Their most senior member holds the rock in front of him, and presents it to the manager. The manager cocks his head to the side as he takes the rock. He seems to be looking directly into the pink quartz vein. He turns the rock over in his hand, as he straightens his head and looks into the distance. He frowns, and knits his brow. Liftts one corner of his mouth into a kind of a smirk, and lets the rock fall to the ground. “Not that rock” he says. “Bring me a different rock.”

That is the “different rock” theory of project management. Help us do it another way.)

the best sensors to use would just be quad encoders and pots

So the first thing I would do is create all your functions/control loops, for example I have four main functions I use in my code. These are drive forward, turn, lift, and claw. Once you have all these control loops well tuned making an autonomous becomes very easy because you just need to activate the functions in what ever order to make your routine

Here is an example of a code we threw together:

            resetMotorEncoder(clamp1);
	resetMotorEncoder(clamp2);
 SensorValue[rightencoder] = 0;

SensorValue[leftencoder] = 0;
while(1==1)
{
if(SensorValue[potent] > 1200)
{
motor[lift1] = 0;
motor[lift2] = 0;
}
}
if(SensorValue(bump) == 0)
{
motor[motor1] = 127;
motor[motor2] = 127;
motor[motor3] = 127;
motor[motor4] = 127;
motor[lift1] = 127;
motor[lift2] = 127;
motor[clamp1] = 63;
motor[clamp2] = 63;
}
if(getMotorEncoder(clamp1) > -1100 || getMotorEncoder(clamp2) < 1055)
{
motor[clamp1] = 63;
motor[clamp2] = 63;
}
if(getMotorEncoder(clamp1) < -1100 || getMotorEncoder(clamp2) > 1055)
{
motor[clamp1] = 0;
motor[clamp2] = 0;
}
if(SensorValue(bump) == 1)
{
motor[clamp1] = 63;
motor[clamp2] = 63;
motor[motor1] = 0;
motor[motor2] = 0;
motor[motor3] = 0;
motor[motor4] = 0;
}
We were wondering if we could run an autonomous only using if-statements. Would this code work? Why or why not? All answers appreciated.

Yes, this will work but your autonomous will have varying success depending on your battery voltage. If you have time I would recommend that you look into programming control loops for the different parts of your robot so your movements are presice.

This part of your code

while(1==1)
{
if(SensorValue[potent] > 1200)
{
motor[lift1] = 0;
motor[lift2] = 0;
}
}

will never exit, so the rest of your code won’t execute.

Also, if you want the rest of your code to run more than once (to keep checking if the conditions are true) then they should be within a while loop as well.

Though in theory programming by time would seem unreliable because of battery voltage drops, we’ve found it to be much more reliable than programming solely with sensors.