Controller Dead Zone

Need some help:confused::confused:
I have a 4 motor drive with omni wheel’s, we are using the right joystick to control it (1&2 axis). The joystick has seen some better days and does not return to (0,0) and will continue to move the robot. Does anyone have any code that will use dead zone values to stop this???

A deadzone on a typical setup is just used to stop the horrid high pitched squealing that emanates from he motors below about 15 power. For you it sounds like the joystick is quite seriously off :slight_smile: So you will have to set the threshold reasonably high. Anyway the way I recommend of creating a deadzone is to create a function/subroutine that you call before changing the motor values.
First you need to define the variables used:


int Channel1;
int Channel2;
int threshold;

Then you can create a subroutine that only applies the readings given by Ch2 & Ch3 (if your using tank drive) if they are above your threshold, or below your negative threshold:


void deadZoneCheck()
{

	if(abs(vexRT[Ch2]) > threshold)
		Channel2 = vexRT[Ch2];
	else
		Channel2 = 0;

	if(abs(vexRT[Ch3]) > threshold)
		Channel3 = vexRT[Ch3];
	else
		Channel3 = 0;
}

Finally you call the function and set your motors to the value of Channel2 & Channel3:


while(true)
{
	deadZoneCheck();
	motor[left] = Channel2;
	motor[right] = Channel3;
	
	wait1Msec(20);
}

to find the threshold you will have to do some trial and error, it will probably be around 20.

Good Luck!

Just out of curiosity, what’s the point of the second part of each if statement? Correct me if I’m wrong, but it seems to me that this code:


if(abs(vexRT[Ch2]) < -threshold) {
}
else {
}

would use the else block unless the threshold is negative, as the absolute value of a number is always positive, and you are comparing an absolute value to the additive inverse (negative version) of a number.

Your correct, the second half of the if statement does absolutely nothing :smiley: It may be because I copied and pasted the result of mine and someone else’s work into said code. Anyway, I have made alterations above :slight_smile:

Thanks EvolvingJon. I should have explained myself a little better. We are not using the tank drive but 4 different wheels. I am hoping i can just use your code and just change the:
"
deadZoneCheck();
motor[left] = Channel2;
motor[right] = Channel3;
"
to something like???
"
deadZoneCheck();
motor[FrontL] = vexRT[Ch2] + vexRT[Ch1];
motor[BackL] = vexRT[Ch2] + vexRT[Ch1];
motor[FrontR] = vexRT[Ch2] - vexRT[Ch1];
motor[BackR] = vexRT[Ch2] - vexRT[Ch1];
"
would this work. (sorry not very good a programming)

If you wanted to maintain the deadzone you would have to define Channel 1 and Channel 2 within deadzone check.


int Channel1;
int Channel2;
int Channel3;
int threshold;

void deadZoneCheck()
{
 
    if(abs(vexRT[Ch2]) > threshold)
        Channel2 = vexRT[Ch2];
    else
        Channel2 = 0;
    if(abs(vexRT[Ch1]) > threshold)
        Channel1 = vexRT[Ch1];
    else
        Channel1 = 0;
}

Then change your drive code to use the channel variables instead of the vexRT values:


deadZoneCheck();
motor[FrontL] = Channel2 + Channel1;
motor[BackL] = Channel2 + Channel1;
motor[FrontR] = Channel2 - Channel1;
motor[BackR] = Channel2 - Channel1;

Thanks that really helps me and my team:)

Glad I could help you out :slight_smile: