We have a backlift on our robot. In the Squared Away game it is useful to carry two cubes. The backlift really only needs to be in two states either up enough to carry the cube or down enough to put it down.
We would like to use the same button press it once and it goes up to a set position. Press it again and it goes down to a set position.
I had this sort of working in Robotc with a simple If-Then statement, but it was with two buttons instead of one AND if I pressed down twice for example … my code would get stuck and the robot was immobilized (because it was trying to get the backLift motor to a specific position it couldn’t reach because it was already all the way down).
Does anyone have a simple example of something like that?
U could make it so that every time u press the button, it adds one to a variable. That variable can either be even or odd. Divide the variable by two. If it’s even the remainder will be zero but if it’s odd the remainder will be one. U can correlate lift states to the remainder
You can create a variable to keep track of the button press, and then use a simple if then/else check to see what that variable value is and then move to an encoder value accordingly.
int backLiftUp = 1; //declared as a global variable
....
....
if (vexRT[BtnLDown] == 1)
{
if (backLiftUp == 0)
{
setMotorTarget(backLift, 0, 100);
backLiftUp = 1;
}
else
{
setMotorTarget(backLift, 100, 100);
backLiftUp = 0;
}
}
you could use a boolean instead of the int as well.