I’ve been thinking about how to do this and I’m not quite sure how to go about it. What I’m wanting to do is make a sort of function that can automatically shut off our autonomous program if certain shaft encoders have not changed in a set amount of time. I would start out with code like this:
void forward(int speed, int rotations)
{
sensorValue[shaftR] = 0;
sensorValue[shaftL] = 0;
while(sensorValue[shaftR] < rotations)
{
motor[drive1] = speed;
motor[drive2] = speed;
motor[drive3] = speed;
motor[drive4] = speed;
}
motor[drive1] = 0;
motor[drive2] = 0;
motor[drive3] = 0;
motor[drive4] = 0;
}
This isn’t my actual code but I needed something for reference. I’m wanting some function that I can put in the while loop so that the “hard stop” function will only be working while I’m running an autonomous routine. So, could I maybe do something like:
sensorValue[shaftEncoder] = 0;
if(sensorValue[shaftEncoder] < rotations && timer[T1] > however long my function is)
{
motorStop();
}
Looking at this I should be able to just integrate this into each function. What’s everyone’s thought on this? Any suggestions? The reason I’m wanting to make this is in case we or our partner run the wrong autonomous routine and we catch on one another then the autonomous routine wouldn’t burn out our motors for the rest of the match.