Potentiometer problem?

hey guys i had a question

so i have a potentiometer on my Mobile goal intake and when i do my autonomous the intake sometimes goes fully down and up a little bit preventing it from picking up the mobile goal.

is this a problem with my potentiometer or the code

sorry if i didnt explain things probably, ask for clarification if you didnt understand

thanks

Depending on your code (you better post it), it could be a problem with the potetiometer.
If you use potentiometer for an angle feedback and stop the motors once you achieve particular angle (read value from the potentiometer port), it could happen that your motor stops too early due to noise.
Potentiometer is a noisy device and can randomly read very out-of-place values. Specifically for this problem, my students have applied simple averaging filter that uses 3 values sampled 3ms apart, though for this failure mode, a median filter would likely be better.

I assume that you stop powering the mobile goal lift once your it’s below the target. If you have rubber bands these will probably be pulling the lift up a tiny bit. If you aren’t using rubber bands, the lift may be ‘bouncing’ a bit when it hits the bottom. You could probably solve both these problems by setting the motors to provide a small amount of downwards force (~10 power)

do you guys want the whole code


#pragma config(Sensor, in1,    pontmojo,       sensorPotentiometer)
#pragma config(Sensor, dgtl3,  motorencoder,   sensorQuadEncoder)
#pragma config(Sensor, dgtl8,  armencoder,     sensorQuadEncoder)
#pragma config(Motor,  port2,           bothrightmotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port3,           bothleftmotor, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port4,           mojo1,         tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port5,           mojo2,         tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port6,           lift1,         tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor,  port7,           lift2,         tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port8,           chain1,        tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port9,           chain2,        tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port10,          claw,          tmotorVex393_HBridge, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/*---------------------------------------------------------------------------*/
/*                                                                           */
/*        Description: Competition template for VEX EDR                      */
/*                                                                           */
/*---------------------------------------------------------------------------*/

// 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"

/*---------------------------------------------------------------------------*/
/*                          Pre-Autonomous Functions                         */
/*                                                                           */
/*  You may want to perform some actions before the competition starts.      */
/*  Do them in the following function.  You must return from this function   */
/*  or the autonomous and usercontrol tasks will not be started.  This       */
/*  function is only called once after the cortex has been powered on and    */
/*  not every time that the robot is disabled.                               */
/*---------------------------------------------------------------------------*/

//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
//void for drive
void drive(int distance, int speed)
{
    SensorValue[motorencoder] = 0;
    motor[bothrightmotor] = speed;
      motor[bothleftmotor] = speed;
    while(abs(SensorValue[motorencoder]) < distance) {
        //...wait...and wait...
        wait1Msec(15);
    }
   motor[bothrightmotor] = 0;
      motor[bothleftmotor] = 0;
}
//void for turn drive

void turndrive(int distance, int speed)
{
    SensorValue[motorencoder] = 0;
    motor[bothrightmotor] = speed;
      motor[bothleftmotor] = -speed;
    while(abs(SensorValue[motorencoder]) < distance) {
        //...wait...and wait...
        wait1Msec(15);
    }
    motor[bothrightmotor] = 0;
      motor[bothleftmotor] = 0;
}
//void for mojo
void mojo(int angle, int speed)
{

	while(SensorValue[pontmojo] < angle)
		{
	motor[mojo1] = -127;
	motor[mojo2] = -127;
}
while(SensorValue[pontmojo] > angle)
		{
	motor[mojo1] = 127;
	motor[mojo2] = 127;
}

motor[mojo1] = 0;
motor[mojo2] = 0;
}

//void for armP

int target;
task armP
{
const float kp = 2.2;
float error;
int speed;

while(true)
{
	error = (target - SensorValue [armencoder]);
	speed = kp*error;
	motor[chain1] = -speed;
motor[chain2] = -speed;

wait1Msec(15);

}
}


//VOID FOR DRIVEPD

void drivePD(int target)
{
const float Kp = .6; //must test for this value, I am just making it up
const float Kd = .9;//must test for this value, I am just making it up
int error;
int derivative;
int previousError;
int motorSpeed;

bool bContinue = true;

while(bContinue) //this is what you need in order to keep checking the sensor
{
error = target - SensorValue[motorencoder];
derivative = error - previousError;
previousError = error;
motorSpeed = (error*Kp) + (derivative*Kd);

motor[bothrightmotor] = motorSpeed;
motor[bothleftmotor] = motorSpeed;
if(fabs(error)> 5){
		}
		else
		{
			bContinue = false;
		}


wait1Msec(20);
}
}


//VOID FOR TURNDRIVEPD

void turndrivePD(int target)
{
	SensorValue[motorencoder] = 0;
const float Kp = .6; //must test for this value, I am just making it up
const float Kd = .9;//must test for this value, I am just making it up
int error;
int derivative;
int previousError;
int motorSpeed;

bool bContinue = true;

while(bContinue) //this is what you need in order to keep checking the sensor
{
error = target - SensorValue[motorencoder];
derivative = error - previousError;
previousError = error;
motorSpeed = (error*Kp) + (derivative*Kd);

motor[bothrightmotor] = -motorSpeed;
motor[bothleftmotor] = motorSpeed;
if(fabs(error)> 5){
		}
		else
		{
			bContinue = false;
		}


wait1Msec(20);
}
}
void pre_auton()
{
SensorValue[motorencoder] = 0;
SensorValue[armencoder] = 0;
}


/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                              Autonomous Task                              */
/*                                                                           */
/*  This task is used to control your robot during the autonomous phase of   */
/*  a VEX Competition.                                                       */
/*                                                                           */
/*  You must modify the code to add your own robot specific commands here.   */
/*---------------------------------------------------------------------------*/
//315  for turndrive for 90 degrees
//167.5 for turndrive for 45 degrees
//29 ticks equalls 1 inch
task autonomous()
{
	time1[T4] = 0;
	    target = 100;
	      startTask(armP);
				wait1Msec (400);
 				 mojo(3050,90);
				drivePD(1300);
				mojo (1230,127);
				target = 52;
			wait1Msec (600);
				motor [claw] = -127;
				wait1Msec (250);
				drivePD(100);
				turndrivePD(635);

				drivePD(700);

//wait1Msec (250); //pause for .025 seconds*//
//mojo(3135, -127); //put down mojo
//wait1Msec(250);
//drive(1300, 127); //drive forward
//wait1Msec(250);
//mojo(1230, 100); //pick up mobile goal
//wait1Msec(250);
//drive(800,-127); //drive backward
//wait1Msec(250);
//turndrive(500, 127); //turn
//wait1Msec(250);
//drive(350, 127); //drive forward
//wait1Msec(250);
//turndrive(125, 127); //turn
//wait1Msec(250);
//drive(450, 127); //drive forward
//wait1Msec(250);
//mojo(3135, -127); //put down mojo
//wait1Msec(250);
//drive(300,-127); //drive backward
//mojo(1075, 100); //pick up mobile goal
//wait1Msec(250);
writeDebugStreamLine("Total auto time: %d", time1[T4]);
}

/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                              User Control Task                            */
/*                                                                           */
/*  This task is used to control your robot during the user control phase of */
/*  a VEX Competition.                                                       */
/*                                                                           */
/*  You must modify the code to add your own robot specific commands here.   */
/*---------------------------------------------------------------------------*/

task usercontrol()
{
  // User control code here, inside the loop

  while (true)
  {

//DRIVE
  	motor[bothrightmotor] = vexRT[Ch3]*.7;
  	motor[bothleftmotor] = vexRT[Ch2]*.7;

    // This is the main execution loop for the user control program.
    // Each time through8 the loop your program should update motor + servo
    // values based on feedback from the joysticks.

    // ........................................................................
    // Insert user code here. This is where you use the joystick values to
    // update your motors, etc.
  // ........................................................................


//MOBILE GOAL

   if (vexRT[Btn6D] == 1)
   {
     motor[mojo1] = -127*.7;
  	 motor[mojo2] = -127*.7;
 	}
   else if  (vexRT[Btn6U] == 1)
 {
     motor[mojo1] = 127;
   motor[mojo2] = 127;
 }

   else
   {
     motor[mojo1] = 0;
   motor[mojo2] = 0;
 }


//lift
 if (vexRT[Btn5UXmtr2] == 1)
   {
     motor[lift1] = 127;
     motor[lift2] = 127;
 	}
   else if  (vexRT[Btn5DXmtr2] == 1)
 {
     motor[lift1] = -127;
     motor[lift2] = -127;
 }

			   else
   {
     motor[lift1] = 0;
     motor[lift2] = 0;
 }

 //Chainbar

 if (vexRT[Btn6UXmtr2] == 1)
   {
     motor[chain1] = 127;
     motor[chain2] = 127;
 	}
   else if  (vexRT[Btn6DXmtr2] == 1)
 {
     motor[chain1] = -127;
     motor[chain2] = -127;
 }

   else
   {
      motor[chain1] = 0;
     motor[chain2] = 0;
   }

   //true
 bool closingClaw = false;
// in the while loop
if(vexRT[Btn7UXmtr2] == 1) {
  motor[claw] = 127; // open the claw
  closingClaw = false;
}
else if(vexRT[Btn7DXmtr2] == 1) {
  motor[claw] = -127; // close the claw
  closingClaw = true;
}
else if(closingClaw) {
  motor[claw] = -20; // hold it closed
}
else {
  motor[claw] = 0; // leave it open
}
 }
}


and i dont have any rubberbands

thanks for the help

@Sgarg14 First off your drivePD loop looks really familiar LOL. Hope it is working well, lemme know if there are issues. However, for your actual issue I would highly recommend doing 2 things first and than a next thing if these don’t work. 1st, have a physical limit: have a standoff or something with some rubber bands wrapped around them(I hate the sound of metal touching), prevent the lift from going down too far. Next, use the PD loop instead of the current code (mojo I am guessing). By having it spring back at full force it will constantly overshoot. If you use the PD loop with well tuned constants it should work perfectly every time. Then if that doesn’t work just switch the potentiometer to an Optical Shaft Encoder because potentiometers have only ever been a struggle for me(other people might get triggered by that) but potentiometers have NEVER worked well for me. (IT COULD BE BECAUSE MINE ARE REALLY OLD)

(yeah the code does look familiar LOL :slight_smile: )

for the first idea you gave me the problem isnt that it goes down too much the problem is that when the autonomous is going only sometimes the mogo goes down and it just springs up and it stays there so then it cant pick up the mobile goal

for the second idea i will try the PD loop and i will let you guys know if it doesnt work

thanks for all the help

my friend who also does programming and its his second year told me not to use PD because the potentiometer never reaches the value(?) so i didnt cause i didnt wanna a brake ANOTHER potentiometer

so is there any other way i can fix this problem

thanks

Create a task in which you are using just a P controller to hold the lift down while some variable is true. Once, in your autonomous routine, you know that the mobile goal has been picked up, you can then set that variable to false and the hold will stop. I’m not sure why your friend said not to use PD because I don’t really see how that could break the potentiometer unless it causes the axle to go past the limit of the pot.