Need help with lift button code.

Hey all, I’m here to ask you all for some help with programming our lift. So the current setup is that we have a conveyor being powered by two motors in tandem. We have a piece of rib sticking out from the chain that contacts a button. When that button is pressed the conveyor is in perfect position to pick up mobile goals. Our problem is the code that is needed to stop the motor movement. Here is the portion of what we currently have working:

#pragma config(Motor,  port1,           intake,        tmotorVex393_HBridge, openLoop)
#pragma config(Motor,  port2,           ldrive1,       tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port3,           ldrive2,       tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port4,           ldrive3,       tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port5,           lift,          tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port6,           carousel,      tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port7,           rdrive3,       tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port8,           rdrive2,       tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port9,           rdrive1,       tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port10,          mglift,        tmotorVex393_HBridge, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
	int leftStickX;
	int leftStickY;

		if (abs(vexRT[Ch3]) > JOYSTICK_TOLERANCE)
			leftStickY = vexRT[Ch3];
			leftStickX = 0;
			leftStickY = 0;
		if (abs(vexRT[Ch1]))
			leftStickX = vexRT[Ch1];

		motor[ldrive1] = leftStickY + leftStickX;
		motor[ldrive2] = leftStickY + leftStickX;
		motor[ldrive3] = leftStickY + leftStickX;
		//left side drive
		motor[rdrive1] = leftStickY - leftStickX;
		motor[rdrive2] = leftStickY - leftStickX;
		motor[rdrive3] = leftStickY - leftStickX;
		if(vexRT[Btn6U] == 1)
		{motor[mglift] = 127;}
		else if(vexRT[Btn6D] == 1)
		{motor[mglift] = -127;
			waitUntil(SensorValue(dgtl5) == 1);
			motor[mglift] = 0;}
		{motor[mglift] = 0;}

The problem with using the waitUntil command is that when it is added to our drive code it ends up freezing all motor values until the lift switch is pressed. So say I am driving forward and click the button to lower the lift you see my drive continue to drive straight. So what I have to ask you is how can I do this in a manner that alleviates our freezing issue?

your else if can take more than one condition. for example:

 else if(vexRT[Btn6D] == 1 && SensorValue(dgtl5) == 0)
{ // mg motors down}

if the button is pressed and the limit switch is not pressed, the motors will run.

You’ll want to put the Btn6U/6D/mgLift stuff into its own task, so that it’s running in pseudo-parallel with the rest of your code and will not take over all functionality when it gets to the waitUntil part. I wrote an introduction to RobotC tasks in this article: RobotC Tasks: The Basics. Hope it helps.

For your code, you could set up the tasks like this:

task mgLift() {
   while(true) {
      btn6U/6D/mgLift stuff here, exactly as you have it now

task main() {
   while(true) {
      everything else in your code, just like you have it now