potentiometer hold for chain arm???

We tried to add a motor hold to our chain arm so when its on either side. At the end of the code in comments is what we tried but we do not know where to put it if it will even work. Any Suggestions???

#pragma config(Sensor, in1,    GyroBoi,        sensorGyro)
#pragma config(Sensor, in2,    SmokePot,       sensorPotentiometer)
#pragma config(Sensor, dgtl1,  sensorleft,     sensorQuadEncoder)
#pragma config(Sensor, dgtl3,  sensorright,    sensorQuadEncoder)
#pragma config(Sensor, dgtl5,  solenoid,       sensorDigitalOut)
#pragma config(Sensor, dgtl6,  SWERVEBOT,      sensorLEDtoVCC)
#pragma config(Motor,  port2,           FrontRight,    tmotorVex393HighSpeed_MC29, openLoop, reversed, encoderPort, dgtl3)
#pragma config(Motor,  port3,           FrontLeft,     tmotorVex393HighSpeed_MC29, openLoop, encoderPort, dgtl1)
#pragma config(Motor,  port4,           Lifty,         tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port5,           wyattsucks,    tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port6,           claw,          tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor,  port7,           Mobilee,       tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port8,           BackRight,     tmotorVex393HighSpeed_MC29, openLoop, reversed, encoderPort, dgtl3)
#pragma config(Motor,  port10,          BackLeft,      tmotorVex393_HBridge, openLoop, encoderPort, dgtl1)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

// 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 Drive(int distance, int power)

{
	{
		SensorValue[sensorleft] = 0;
		SensorValue[sensorright] = 0;

		while((distance > 0 && SensorValue[sensorleft] < distance)||( distance < 0 && SensorValue[sensorleft] > distance))

		{
			if(SensorValue[sensorright] > SensorValue[sensorleft])
			{
				motor[FrontLeft] = power;
				motor[BackLeft] = power;
				motor[FrontRight] = power * (8.0/10);
				motor[BackRight] = power * (8.0/10);
			}
			else if(SensorValue[sensorright] < SensorValue[sensorleft])
			{
				motor[FrontLeft] = power * (9.0/10);
				motor[BackLeft] = power * (9.0/10);
				motor[FrontRight] = power;
				motor[BackRight] = power;
			}
			else if (SensorValue[sensorright] == SensorValue[sensorleft])
			{
				motor[FrontLeft] = power;
				motor[BackLeft] = power;
				motor[FrontRight] = power;
				motor[BackRight] = power;
			}
		}
		motor[FrontLeft] = 0;
		motor[BackLeft] = 0;
		motor[FrontRight] = 0;
		motor[BackRight] = 0;
	}
}
void turnLeft (int angle, int power)
{
	SensorValue[sensorright] = 0;
	SensorValue[sensorleft] = 0;

	while((angle > 0 && (SensorValue[sensorright] > -angle || SensorValue[sensorleft] > -angle))
		|| ((angle < 0) && (SensorValue[sensorright] < -angle || SensorValue[sensorleft] < -angle)))
	{
		motor[BackLeft] = -power;
		motor[FrontLeft] = -power;
		motor[BackRight] = power;
		motor[FrontRight] = power;
	}
	motor[BackLeft] = 0;
	motor[FrontLeft] = 0;
	motor[BackRight] = 0;
	motor[FrontRight] = 0;
}
void mobile (int time, int power)
{
	motor[Mobilee] = power*1;
	wait1Msec(time);
	motor[Mobilee] = 0;
}



void pre_auton()
{

  bStopTasksBetweenModes = true;

	
}


task autonomous()
{

  AutonomousCodePlaceholderForTesting();
}


task usercontrol()
{


  while (true)
  {


  	motor[FrontLeft] = vexRT[Ch3];
		motor[BackLeft] = vexRT[Ch3];
		motor[FrontRight] = vexRT[Ch2];
		motor[BackRight] = vexRT[Ch2];



	if (vexRT(Btn7U)==1)
	{
		motor[Lifty] = -120;

	}
	else if (vexRT(Btn7D)==1)
	{
		motor[Lifty] = 120;

	}
	else
	{
		motor[Lifty] = -20;
}
  if (vexRT(Btn5U)==1)
		{
			motor[Mobilee] = 120;

		}
		else if (vexRT(Btn5D)==1)
		{
			motor[Mobilee] = -100;

		}
		else
		{
			motor[Mobilee] = 10;

		}
		if(vexRT(Btn6U) == 1)
		{
			SensorValue[solenoid] = 1;
		}
		else
		{
			SensorValue[solenoid] = 0;

		}
		if (vexRT(Btn8U)==1)
		{
			motor[claw] = 120;
		}
		else if (vexRT(Btn8D)==1)
		{
			motor[claw] = -120;
		}
		else
		{
			motor[claw] = 5;
	}
}
}

/*

	while(SensorValue[SmokePot] > position)
  	{
  			motor[FrontLeft] = 20;
				motor[BackLeft] = 20;
				motor[FrontRight] = 20;
				motor[BackRight] = 20;
	}
	  	while(SensorValue[SmokePot] < position)
  	{
  			motor[FrontLeft] = -20;
				motor[BackLeft] = -20;
				motor[FrontRight] = -20;
				motor[BackRight] = -20;
	}

	*/

Not the answer to your question, but one observation is that you can make your while() conditions much simpler if you use absolute value, something along the lines of:


if abs(SensorVelue[mySensor]) < abs(distance)

Basically saying, “has the robot gone enough clicks?” (without caring about direction, because I assume you’ve got that covered in the power level you hand the function). This is instead of having to explicitly code + and - scenarios.

Thank you biglesliep. We also figured out our issue. We are gonna be using some variables and buttons to switch between motor holds.

You would put the hold within your lift drive control:


	if (vexRT(Btn7U)==1)
	{
		motor[Lifty] = -120;

	}
	else if (vexRT(Btn7D)==1)
	{
		motor[Lifty] = 120;

	}
	else if (vexRT(Btn7U)==0 && vexRT(Btn7D)==0) // if neither 7U or 7D are pressed
	{
		motor[Lifty] =  sgn(position - SensorValue[SmokePot] ) * 20; // run the lift motor at 20 against gravity
        }

This assumes “position” is the potentiometer reading when the arm is vertical.