View Full Version : [FTC]: Deadbands (axis/motor power restrictions)
JohnFogarty
03-11-2010, 21:30
Hello fellow programmers!
I am currently working on finding a solution to a probable bug which in being a programmer for the last 2 years never occurred. The base joystick to motor control has a bug in it.
4wd
motor[motorD]=joystick.joy1_y1;
motor[motorE]=joystick.joy1_y2;
motor[motorF]=joystick.joy1_y2;
motor[motorG]=joystick.joy1_y1;
It preforms the funtion, but one wheel always continues to spin even when the joystick may only be giving a output of 1 or 2. How do you implement dead bands on your analog sticks to control the motor power output.
Here is the code we've used to create deadbands:
if((joystick.joy1_y1 < 5) && (joystick.joy1_y1 > -5)) joystick.joy1_y1 = 0;
motor[motorD]=joystick.joy1_y1;
I dont have it right here, but ours is something like:
// since joysticks return -127 to 127 values, and since motors react in a
// rance of -100 to 100, this function adds a midpoint deadband and
// adjusts the speed to be within the expected range.
int deadband(int invalue)
{
// if the value is between -27 and 27 then use
// that as the deadband and return 0
if (abs(invalue) < 27) return 0;
// if the value is negative, add 27 to bring the (-27 to -127) to (0 to -100)
if (invalue < 0) return invalue + 27;
// if the value is not > 27 then it already exited, so - 27 and return
return invalue - 27;
}
task main()
{
motor[motorA] = deadband(joystick.joy1_y1);
motor[motorB] = deadband(joystick.joy1_x1);
motor[motorC] = deadband(joystick.joy1_y2);
motor[motorD] = deadband(joystick.joy1_x2);
}
JohnFogarty
04-11-2010, 17:23
Here is the code we've used to create deadbands:
if((joystick.joy1_y1 < 5) && (joystick.joy1_y1 > -5)) joystick.joy1_y1 = 0;
motor[motorD]=joystick.joy1_y1;
haha that looks exactly like what I am trying today thanks:D
I'll just see what works best I may end up going with the other idea too but thank you for your help.
John Fogarty
GForce 3864
Another way to do it is
int threshold = 12;
motor[motorD] = (abs(joystick.joy1_y1) >= threshold) * joystick.joy1_y1;
...
This basically just zeroes any joystick value that is within a threshold of 0.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.