Claw Code help

We are trying to make our claw move to two predetermined positions using two different buttons on the remote. This should be simple, but for some reason, I’m not getting it to work. If i take the code for one of the positions out, it seems to work, but add the other code, which is identical, it won’t work. also if I remove the UserControlCodePlaceholderForTesting(); out of the code, the program won’t work at all. What am I doing wrong?

#pragma config(Sensor, in1, claw_S, sensorPotentiometer)
#pragma config(Motor, port1, LeftFBaseM, tmotorVex393_HBridge, openLoop, driveLeft)
#pragma config(Motor, port2, RightBBaseM, tmotorVex393_MC29, openLoop, driveRight)
#pragma config(Motor, port3, RightFBaseM, tmotorVex393_MC29, openLoop, driveRight)
#pragma config(Motor, port4, LeftTowerM, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port5, LeftTowerM, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port6, RightTowerM, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, RightTowerM, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port8, , tmotorVex393_MC29, openLoop)
#pragma config(Motor, port9, , tmotorVex393_MC29, openLoop)
#pragma config(Motor, port10, LeftBBaseM, tmotorVex393_HBridge, openLoop, driveLeft)

// This code is for the VEX cortex platform
#pragma platform(VEX2)

// Select Download method as “competition”
#pragma competitionControl(Competition)

//Main competition background code…do not modify!
#include “Vex_Competition_Includes.c”

void pre_auton()
{
bStopTasksBetweenModes = true;

}

task autonomous()
{

AutonomousCodePlaceholderForTesting();

}

task usercontrol()
{
while (true)
{

	motor[port2] = - vexRT[Ch2] + vexRT[Ch1];			//moveing
	motor[port3] = - vexRT[Ch2] + vexRT[Ch1];			//moveing

	motor[port4] = - vexRT[Ch3]; 									//arms
	motor[port5] = - vexRT[Ch3]; 									//arms
	motor[port6] = - vexRT[Ch3]; 									//arms
	motor[port7] = - vexRT[Ch3]; 									//arms

	motor[port8] = + vexRT[Ch2] + vexRT[Ch1];			//moveing
	motor[port9] = + vexRT[Ch2] + vexRT[Ch1];			//moveing


	if(vexRT[Btn6U] == 1)		//													 baseich funcshin of the claw
	{
		motor[port1] = 127; motor[port10] = 127;
	}
	else if(vexRT[Btn6D] == 1)
	{
		motor[port1] = -127;	motor[port10] = -127;
	}
	else
	{
		if(SensorValue[in1] > 2400)
		{
			motor[port1] = 40; motor[port10] = 40;
		}
		else
		{
			motor[port1] = 0;	motor[port10] = 0;
		}
	}

	if(vexRT[Btn5U] == 1)			//																					grab poistin
	{
		if(SensorValue[in1] > 2300)   //gos back when it went to far
		{
			motor[port1] = -50;	motor[port10] = -50;
		}
		else if(SensorValue[in1] < 2500)  //gos to the postin
		{
			motor[port1] = 90;  motor[port10] = 90;
		}
		else(SensorValue[in1] == 2100);   // just stops went it gets there
		{
			motor[port1] = 0; 	motor[port10] = 0;
		}
	}


	if (vexRT[Btn7D] == 1)			//																					levels out
	{
		if(SensorValue[in1] > 1900)   //gos back when it went to far
		{
			motor[port1] = -50;	motor[port10] = -50;
		}
		else if(SensorValue[in1] < 1700)  //gos to the postin
		{
			motor[port1] = 90;  motor[port10] = 90;
		}
		else if(SensorValue[in1] == 1800)   // just stops went it gets there
		{
			motor[port1] = 0; 	motor[port10] = 0;
		}

UserControlCodePlaceholderForTesting();

	}

}

}

The fundamental problem is that you have multiple if-then-else statements that send control values to the same motors. The first condition looks like this.

if(vexRT[Btn6U] == 1) //  basic function of the claw
{
  motor[port1] = 127; motor[port10] = 127;
}
else if(vexRT[Btn6D] == 1)
{
  motor[port1] = -127;  motor[port10] = -127;
}
else
{
  if(SensorValue[in1] > 2400)
  {
    motor[port1] = 40; motor[port10] = 40;
  }
  else
  {
    motor[port1] = 0; motor[port10] = 0;
  }
}

So this says
If I press button 6U then run the motors CW else if I press button 6D run the motors CCW else if a sensor is greater then 2400 run the motors CW slowly else stop them.

That looks good, now lets look at the next conditional statement.

if(vexRT[Btn5U] == 1) //  grab position
{
  if(SensorValue[in1] > 2300) //gos back when it went to far
  {
    motor[port1] = -50; motor[port10] = -50;
  }
  else if(SensorValue[in1] < 2500) //gos to the postin
  {
    motor[port1] = 90; motor[port10] = 90;
  }
  else(SensorValue[in1] == 2100); // just stops went it gets there
  {
    motor[port1] = 0; motor[port10] = 0;
  }
}

pressing button 5U tries to run another conditional loop controlling the same motors, but your first loop is still running and sending values to the motors, so things don’t work properly.

Have a look at this post, it talks about the same situation.
https://vexforum.com/index.php/conversation/post/123070

you also ask why removing the “UserControlCodePlaceholderForTesting” call stops the code working altogether. Lets have a look at what that function does (from RobotC V4.55)

/*---------------------------------------------------------------------------*/
/*  Placeholder function that is called from the competition template if     */
/*  the user has not modified the usercontrol task                           */
/*---------------------------------------------------------------------------*/
void UserControlCodePlaceholderForTesting()
{
  // Following code is simply for initial debuggging.
  //
  // It can be safely removed in a real program and removing it will slightly
  // improve the real-time performance of your robot.
  //
  displayStatusAndTime();
  wait1Msec(100);
}

Notice that it has a 100mS delay, this slows down your while loop and allows at least some stable value to be sent to the motors, removing that call makes you while loop run very fast and the motor control values are indeterminate.

It’s good practice to have a small delay at the end of a while loop, perhaps 20mS, but fix the issue of multiple motor control values and everything should work ok. My suggestion is to replace the “motor]” assignments with an assignment to a variable and then send that once to the motor at the end of the while loop.