need program help

I have a code for a lift bot with a claw. the claw arms are not physically connected but I want them to move together at the same time on command and get stopped by a potentiometer on each one. the arm is only controlled by one potentiometer. the segments of my code work fine alone but the way I have them put together I have to move the arm up down then the right claw then the left, I want to run which ever one when ever I need to here is my code. please help

#pragma config(Sensor, in1, pot1, sensorPotentiometer)
#pragma config(Sensor, in2, pot2, sensorPotentiometer)
#pragma config(Sensor, in3, pot3, sensorPotentiometer)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

task main()
{
while (true)
{
repeat(forever)
{
motor[port2] = vexRT[Ch3];
motor[port3] = vexRT[Ch2];

//Arm control
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//6U

waitUntil(vexRT[Btn6U] == 1);
	{
	motor(port4) = 0;
	motor(port5) = 0;
	motor(port6) = 0;
	motor(port7) = 0;
	repeatUntil(vexRT[Btn6D] == 1)
{
if(SensorValue(pot1) >= 2530)
	{
	motor(port4) = 20;
	motor(port5) = 20;
	motor(port6) = 20;
	motor(port7) = 20;
	}
	else if(SensorValue(pot1) <= 2529)
{
	motor(port4) = 127;
	motor(port5) = 127;
	motor(port6) = 127;
	motor(port7) = 127;
	}
	else
	{
	motor(port4) = 0;
	motor(port5) = 0;
	motor(port6) = 0;
	motor(port7) = 0;
}
}
}

//5D/////////////////////////////////////////////////////////////////////////////


waitUntil(vexRT[Btn6D] == 1);
	{
	motor(port4) = 0;
	motor(port5) = 0;
	motor(port6) = 0;
	motor(port7) = 0;
	repeatUntil(vexRT[Btn6U] == 1)
{

if(SensorValue(pot1) >=1200)
{
motor(port4) = -127;
motor(port5) = -127;
motor(port6) = -127;
motor(port7) = -127;
}
else
{
motor(port4) = 0;
motor(port5) = 0;
motor(port6) = 0;
motor(port7) = 0;
}
}
}

//claw control

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//right claw
//5U

    waitUntil(vexRT[Btn5U] == 1);
	{
	motor(port8) = 0;
	repeatUntil(vexRT[Btn5D] == 1)
{
if(SensorValue(pot2) <= 415)
	{
	motor(port8) = 20;
	}
	else if(SensorValue(pot2) >= 415)
{
	motor(port8) = 127;
	}
	else
	{
	motor(port8) = 0;
}
}
}

//5D////////////////////////////////////////////////////////////////////////////////////////////////

waitUntil(vexRT[Btn5D] == 1);
	{
	motor(port8) = 0;
	repeatUntil(vexRT[Btn5U] == 1)
{
if(SensorValue(pot2) <= 1800)
{
	motor(port8) = -127;
	}
	else
	{
	motor(port8) = 0;
}
}
}

//left claw
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//5D
  waitUntil(vexRT[Btn5U] == 1);
	{
	motor(port9) = 0;

	repeatUntil(vexRT[Btn5D] == 1)
{
if(SensorValue(pot3) >= 1820)
	{
	motor(port9) = 20;

	}
	else if(SensorValue(pot3) <= 1820)
{
	motor(port9) = 127;
	}
	else
	{
	motor(port9) = 0;
}
}
}

//5D////////////////////////////////////////////////////////////////////////////////////////////////

waitUntil(vexRT[Btn5D] == 1);
	{
	motor(port9) = 0;
	repeatUntil(vexRT[Btn5U] == 1)
{
if(SensorValue(pot3) >= 340)
{
	motor(port9) = -127;
	}
	else
	{
	motor(port9) = 0;
}
}
}

}
}
}

Please tab indent this code and use the “code” tool on this forum:

#pragma config(Sensor, in1, pot1, sensorPotentiometer)
#pragma config(Sensor, in2, pot2, sensorPotentiometer)
#pragma config(Sensor, in3, pot3, sensorPotentiometer)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
	while (true)
	{
		repeat(forever)
		{
			motor[port2] = vexRT[Ch3];
			motor[port3] = vexRT[Ch2];

//Arm control
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//6U

			waitUntil(vexRT[Btn6U] == 1);
			{
				motor(port4) = 0;
				motor(port5) = 0;
				motor(port6) = 0;
				motor(port7) = 0;
				repeatUntil(vexRT[Btn6D] == 1)
				{
					if(SensorValue(pot1) >= 2530)
					{
						motor(port4) = 20;
						motor(port5) = 20;
						motor(port6) = 20;
						motor(port7) = 20;
					}
					else if(SensorValue(pot1) <= 2529)
					{
						motor(port4) = 127;
						motor(port5) = 127;
						motor(port6) = 127;
						motor(port7) = 127;
					}
					else
					{
						motor(port4) = 0;
						motor(port5) = 0;
						motor(port6) = 0;
						motor(port7) = 0;
					}
				}
			}

//5D/////////////////////////////////////////////////////////////////////////////


			waitUntil(vexRT[Btn6D] == 1);
			{
				motor(port4) = 0;
				motor(port5) = 0;
				motor(port6) = 0;
				motor(port7) = 0;
				repeatUntil(vexRT[Btn6U] == 1)
				{
					if(SensorValue(pot1) >=1200)
					{
						motor(port4) = -127;
						motor(port5) = -127;
						motor(port6) = -127;
						motor(port7) = -127;
					}
					else
					{
						motor(port4) = 0;
						motor(port5) = 0;
						motor(port6) = 0;
						motor(port7) = 0;
					}
				}
			}

//claw control
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//right claw
//5U

			waitUntil(vexRT[Btn5U] == 1);
			{
				motor(port8) = 0;
				repeatUntil(vexRT[Btn5D] == 1)
				{
					if(SensorValue(pot2) <= 415)
					{
						motor(port8) = 20;
					}
					else if(SensorValue(pot2) >= 415)
					{
						motor(port8) = 127;
					}
					else
					{
						motor(port8) = 0;
					}
				}
			}

//5D////////////////////////////////////////////////////////////////////////////////////////////////

			waitUntil(vexRT[Btn5D] == 1);
			{
				motor(port8) = 0;
				repeatUntil(vexRT[Btn5U] == 1)
				{
					if(SensorValue(pot2) <= 1800)
					{
						motor(port8) = -127;
					}
					else
					{
						motor(port8) = 0;
					}
				}
			}

//left claw
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//5D
			waitUntil(vexRT[Btn5U] == 1);
			{
				motor(port9) = 0;

				repeatUntil(vexRT[Btn5D] == 1)
				{
					if(SensorValue(pot3) >= 1820)
					{
						motor(port9) = 20;

					}
					else if(SensorValue(pot3) <= 1820)
					{
						motor(port9) = 127;
					}
					else
					{
						motor(port9) = 0;
					}
				}
			}

//5D////////////////////////////////////////////////////////////////////////////////////////////////

			waitUntil(vexRT[Btn5D] == 1);
			{
				motor(port9) = 0;
				repeatUntil(vexRT[Btn5U] == 1)
				{
					if(SensorValue(pot3) >= 340)
					{
						motor(port9) = -127;
					}
					else
					{
						motor(port9) = 0;
					}
				}
			}

		}
	}
}

Video coming…

#pragma config(Sensor, in1, pot1, sensorPotentiometer)
#pragma config(Sensor, in2, pot2, sensorPotentiometer)
#pragma config(Sensor, in3, pot3, sensorPotentiometer)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#define ARM_UP_POS 2530
#define ARM_DOWN_POS 1200

task main() {

	bool armMoveUp = false;
	bool armMoveDown = false;

	while(true) {

		// I assume this is drive code or something?!?
		motor[port2] = vexRT[Ch3];

		motor[port3] = vexRT[Ch2];

		// Pressing 6U starts arm move up code
		if(vexRT[Btn6U]) {

			setMultipleMotor(0, port4, port5, port6, port7);

			armMoveUp = true;

			armMoveDown = false;

		}

		// Pressing 6D stops arm move up code
		if(vexRT[Btn6D]) {

			setMultipleMotor(0, port4, port5, port6, port7);

			armMoveUp = false;

			armMoveDown = true;

		}

		if(armMoveUp) {

			if(SensorValue(pot1) >= ARM_UP_POS) {

				// Hold arm @ position
				setMultipleMotor(20, port4, port5, port6, port7);

			} else if(SensorValue(pot1) < ARM_UP_POS) {

				// Move arm up?
				setMultipleMotor(127, port4, port5, port6, port7);

			}

		} 

		if(armMoveDown) {

			if(SensorValue(pot1) >= ARM_DOWN_POS) {

				setMultipleMotor(-127, port4, port5, port6, port7);

			} else {

				setMultipleMotor(0, port4, port5, port6, port7);

				armMoveDown = false;

			}

		}

		// The rest is up to you.....




		

		// claw control
		// right claw
		// 5U

		waitUntil(vexRT[Btn5U]);

		motor(port8) = 0;

		repeatUntil(vexRT[Btn5D]) {

			if(SensorValue(pot2) <= 415) {
				motor(port8) = 20;
			} else if(SensorValue(pot2) >= 415) {
				motor(port8) = 127;
			} else {
				motor(port8) = 0;
			}

		}

		// 5D

		waitUntil(vexRT[Btn5D]);

		motor(port8) = 0;

		repeatUntil(vexRT[Btn5U]) {

			if(SensorValue(pot2) <= 1800) {
				motor(port8) = -127;
			} else {
				motor(port8) = 0;
			}

		}

		// left claw
		// 5D

		waitUntil(vexRT[Btn5U]);

		motor(port9) = 0;

		repeatUntil(vexRT[Btn5D])
		{
			if(SensorValue(pot3) >= 1820) {
				motor(port9) = 20;
			} else if(SensorValue(pot3) <= 1820) {
				motor(port9) = 127;
			} else {
				motor(port9) = 0;
			}
		}

		// 5D

		waitUntil(vexRT[Btn5D]);

		motor(port9) = 0;

		repeatUntil(vexRT[Btn5U]) {

			if(SensorValue(pot3) >= 340) {
				motor(port9) = -127;
			} else {
				motor(port9) = 0;
			}

		}

	}

}

I tried your 2nd code cody but I got erors for the setMultipleMotor command it is an undefined variable

This…
Capture.PNG

I’m still getting errors for setMultipleMotor in natural language
(thanks for the help cody I’m still somewhat new to programing and this is my first time using potentiometers)

So what’s the “repeat(forever)” supposed to do even though it’s already inside of an infinitely running while loop? Another thing, you are using curved brackets “(” instead of normal brackets “” when it’s about sensors and motors being defined (edited)… Let me see what I can do, but this may be SOME of the errors fixed:


#pragma config(Sensor, in1, pot1, sensorPotentiometer)
#pragma config(Sensor, in2, pot2, sensorPotentiometer)
#pragma config(Sensor, in3, pot3, sensorPotentiometer)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#define ARM_UP_POS 2530
#define ARM_DOWN_POS 1200

task main() {

	bool armMoveUp = false;
	bool armMoveDown = false;

	while(true) {

		// I assume this is drive code or something?!?
		motor[port2] = vexRT[Ch3];

		motor[port3] = vexRT[Ch2];

		// Pressing 6U starts arm move up code
		if(vexRT[Btn6U]) {

			setMultipleMotor(0, port4, port5, port6, port7);

			armMoveUp = true;

			armMoveDown = false;

		}

		// Pressing 6D stops arm move up code
		if(vexRT[Btn6D]) {

			setMultipleMotor(0, port4, port5, port6, port7);

			armMoveUp = false;

			armMoveDown = true;

		}

		if(armMoveUp) {

			if(SensorValue[pot1] >= ARM_UP_POS) {

				// Hold arm @ position
				setMultipleMotor(20, port4, port5, port6, port7);

			} else if(SensorValue[pot1]< ARM_UP_POS) {

				// Move arm up?
				setMultipleMotor(127, port4, port5, port6, port7);

			}

		} 

		if(armMoveDown) {

			if(SensorValue[pot1] >= ARM_DOWN_POS) {

				setMultipleMotor(-127, port4, port5, port6, port7);

			} else {

				setMultipleMotor(0, port4, port5, port6, port7);

				armMoveDown = false;

			}

		}

		// The rest is up to you.....




		

		// claw control
		// right claw
		// 5U

		waitUntil(vexRT[Btn5U]);

		motor[port8)]= 0;

		repeatUntil(vexRT[Btn5D]) {

			if(SensorValue[pot2] <= 415) {
				motor[port8] = 20;
			} else if(SensorValue[pot2] >= 415) {
				motor[port8] = 127;
			} else {
				motor[port8] = 0;
			}

		}

		// 5D

		waitUntil(vexRT[Btn5D]);

		motor[port8] = 0;

		repeatUntil(vexRT[Btn5U]) {

			if(SensorValue[pot2] <= 1800) {
				motor[port8] = -127;
			} else {
				motor[port8] = 0;
			}

		}

		// left claw
		// 5D

		waitUntil(vexRT[Btn5U]);

		motor[port9] = 0;

		repeatUntil(vexRT[Btn5D])
		{
			if(SensorValue[pot3] >= 1820) {
				motor[port9] = 20;
			} else if(SensorValue[pot3] <= 1820) {
				motor[port9] = 127;
			} else {
				motor[port9] = 0;
			}
		}

		// 5D

		waitUntil(vexRT[Btn5D]);

		motor[port9] = 0;

		repeatUntil(vexRT[Btn5U]) {

			if(SensorValue[pot3] >= 340) {
				motor[port9] = -127;
			} else {
				motor[port9] = 0;
			}

		}

	}

}

Hopefully this helps/works :slight_smile:

I did something that prevents the overheating in the claw motors. clawangleleft and clawangleright are the potentiometers on each side of the claw. The code is such that the further away a claw arm is from its desired position, the more power it sends to the motor.


int clawset = 0
if(VexRT[Btn5U] == 1)
{
clawset = (clawset + 2)
}
if(VexRT[Btn5D] ==1)
{
clawset = (clawset - 2)
}
if((VexRT[Btn5U] == 0) && (VexRT[Btn5D] == 0)
{
}
while(true)
{
motor[clawArmReft] = ((0.3)*((clawset) - (sensorValue[clawangleleft])));
motor[clawArmRight] = ((0.3)*((clawset) - (sensorValue[clawangleright])));
}