I’m trying to get my program to be able to switch the controls of the lift during competition. For example, I have the left lift and right lift controlled on the same analog (channel 3) but if there is a problem during competition, I want to be able to hit a button so that the left lift and right lift are controlled on two different analogs.
Then, my intake must be switched to a button instead of an analog(Channel 2), where one button would control the intake, but have a separate button control releasing the intake. For example, buttons 6U and 6D.
Here’s what I had for switching the controls of the lift.
if(vexRT[Btn7D] == 0)
{
motor[rightlift] = vexRT[Ch3Xmtr2];//lift
motor[leftlift] = vexRT[Ch3Xmtr2];//lift
motor[rightlift2] = vexRT[Ch3Xmtr2];//lift
motor[leftlift2] = vexRT[Ch3Xmtr2];//lift
}
if(vexRT[Btn7D] == 1)
{
motor[rightlift] = vexRT[Ch3Xmtr2];
motor[rightlift2] = vexRT[Ch3Xmtr2];
motor[leftlift2] = vexRT[Ch2Xmtr2];
motor[leftlift] = vexRT[Ch2Xmtr2];
}
So, is my program for switching the controls of the lift wrong, if so, what can I do to fix it?
and,
How would I go about programming my intake to two buttons?
Thank You!
This seems like it will work as long as the inverts are all correct in the motor and Sensor Setup window.
Have you tested this?
Adding the intake controls to each of the if statements will allow that to work as well.
Keep in mind that you have to be continuously holding the the button to get control set up 2.
intake=127*(VexRT[Btn6U]-VexRT[Btn6D]); This is simplest way to code it
I am assuming you have a motor powered intake but the word “release” in your post implies that this could be incorrect.
Like tabor said, you would have to hold the button down and manipulate the joystick at the same time.
Having a variable toggle the state of ch2/ch3 usage would seem like what you want. The trouble is, you can loop through the button detection pretty quick so not only detecting button down but the next button up event is needed for preventing this.
There are more elegant ways of doing this but this gets the button state management across. You could also use the buttons to give more or less power to the other lift motors to adjust for wonkiness.
Yes you can use booleans if you want too but once you get to multiple buttons for state it is nicer to have an enumerated list.
int use_second_stick = 0;
int btn7_released_yet = 1;
// put this inside the while loop
// see if the button is pressed and we are not already using the second stick
// press again to release
if(vexRT[Btn7D] == 1 && btn7_released_yet == 1)
{
use_second_stick = 1;
btn7_released_yet = 0;
}
else if(vexRT[Btn7D] == 1 && btn7_released_yet == 1)
{
use_second_stick = 0;
btn7_released_yet = 0;
}
else if(vexRT[Btn7D] == 0 && btn7_released_yet == 0)
{
btn7_released_yet = 1;
}
motor[rightlift] = vexRT[Ch3Xmtr2];
motor[rightlift2] = vexRT[Ch3Xmtr2];
if( use_second_stick == 1)
{
motor[leftlift2] = vexRT[Ch2Xmtr2];
motor[leftlift] = vexRT[Ch2Xmtr2];
}
else
{
motor[rightlift2] = vexRT[Ch3Xmtr2];//lift
motor[leftlift2] = vexRT[Ch3Xmtr2];//lift
}
wait1Msec(20); // don't forget to wait a little....