programming a deadzone and potentiometer?

hello vexforum, our team has experienced some problems while programming the robot and would like to get some help…\

deadzone: is programming a dead zone even necessary? since when the joystick returns to rest, it may or may not return 0, so in a simple code like “motor motor1 = vexRT[ch1];” would have the motor running at very low speed/force, so, would that be an issue?
if so, what is a good way to program it?

pot: how do we set up the potentiometer in code? and is there a way to convert the pot output to angle in degrees, and use it as a variable? all I could find online is something like " waituntilpotiometer();" which is insufficient.

Deadzone: yes this is a common issue with the joysticks. Usually, it results in a high pitched buzzing sound.
Very basic code that I wrote, and that my team currently uses:


while(true)
	{
		if (vexRT[Ch2] > 15)
		{
			motor[rightBack] = vexRT[Ch2];
			motor[rightFront] = vexRT[Ch2];
		}
		if (vexRT[Ch2] < -15)
		{
			motor[rightBack] = vexRT[Ch2];
			motor[rightFront] = vexRT[Ch2];

		}

		wait1Msec(5); 
		motor[rightBack] = 0;
		motor[rightFront] = 0;
	}//end of while true


This code is for a basic tank drive where channel 2 is on the right side of the drive. The same will work for the right side if the joystick channel and motor assignments are changed.

Basically, if the joystick is like a slider, think of the slider on your phone to adjust the brightness, so it has a different value at a different position. Sometimes the joysticks don’t return back to its true center, so it doesn’t return a value of 0. With the code, you posted above,


motor1 = vexRT[ch1]

it basically says set the motor to the value of the joystick at all times. So it may try to return a value of 7 to the motors, which is not enough to make them move, this is basically stalling your motor and causes the high pitched buzzing sound. I don’t think this is bad for the motors, nor does it drain the battery much, so it is not absolutely necessary. But the code is not too complicated, and it works well so it doesn’t hurt to use.

Looking back at:


while(true)
	{
		if (vexRT[Ch2] > 15) // postivie deadzone constant: 15
		{
			motor[rightBack] = vexRT[Ch2];
			motor[rightFront] = vexRT[Ch2];
		}
		if (vexRT[Ch2] < -15) // negative deadzone constant: -15
		{
			motor[rightBack] = vexRT[Ch2];
			motor[rightFront] = vexRT[Ch2];

		}

		wait1Msec(5); 
		motor[rightBack] = 0;
		motor[rightFront] = 0;
	}//end of while true


All the program says is if the joystick is OUTSIDE the deadzone (-15 to 15) then, set the motor power equal to the joystick value. I’m pretty sure the joysticks max out at a value of -127 to 127 so you don’t have to worry about them feeding values too high for the motors.

The code doesn’t have any else statements, but it is implied that if none of the if statements are true, then they will not be executed, so the motor values are set to a default of 0. The default value of 0 is very important because otherwise, the motors will not stop. :slight_smile:

There is no specific calculation to receive the deadzone constant. Think of it like choosing what values of the joystick you want to be included in the deadzone, and remember that the joystick can produce negative and positive values. I think 15 works great, so I would not recommend changing it, but you can try anything between 10-20. Don’t go too high or else you will not be able to make fine driving movements.

Good Luck!!

This is a thread is a thread I created back in august where I asked about a deadzone if you want to look at other solutions to creating a deadzone.

Setup Pot:

  1. pot is an analog sensor, so choose an analog port in the cortex to plug it into. it will not work in a digital sensor port, and make sure your write down what analog port you plugged the pot into.
  2. open RobotC and open the code you ar working on
  3. find the motor and sensor setup button at the top of the screen, and press it
  4. go to the analog sensors tab and go to the port that you plugged the pot into
  5. name the pot sensor (for this example I’ll name the potentiometer potSensor), and select the sensor type drop down menu and select potentiometer.
  6. press apply changes and the motor and sensors setup screen should disappear
  7. create a variable that you want to store the value of the pot, don’t set it equal to anything yet

float potVal;

  1. in while (true), set the variable equal to SensorValue[thisIsTheNameOfThePotSensorFromStep5]. Make sure the name of the sensor is correctly spelled. You should have the variable equal to the value of the sensor in an infinite loop, or the value of the variable will not update as the value of the sensor changes.

while(true){

potVal = SensorValue[potSensor]

}


I’m, not sure how to convert the value of the potentiometer to degrees, but you can open the debugger, and look at the value of the pot in real time in relation to its position.

According to Vex’s Website “the potentiometer does not travel more than 260º (the potentiometer can only move approximately 265º ±5º and can only electrically measure 250º ±20º)”. A potentiometer reads from 0-4000 Potentiometer Units or PU’s (I totally just made PU’s up). Therefor we can approximate the value of a degree to be approximately 4,000/250 which is 16 PU’s per degree. I’d honestly just open the debugger on RobotC to read the actual PU for the location of whatever subsystem you are using like @Colossus recommends. Hope that helps!