Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   FIRST Tech Challenge (http://www.chiefdelphi.com/forums/forumdisplay.php?f=146)
-   -   [FTC]: Deadbands (axis/motor power restrictions) (http://www.chiefdelphi.com/forums/showthread.php?t=87385)

JohnFogarty 03-11-2010 21:30

[FTC]: Deadbands (axis/motor power restrictions)
 
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
Code:

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.

RCXRM 04-11-2010 12:56

Re: [FTC]: Deadbands (axis/motor power restrictions)
 
Here is the code we've used to create deadbands:

Code:

if((joystick.joy1_y1 < 5) && (joystick.joy1_y1 > -5)) joystick.joy1_y1 = 0;
motor[motorD]=joystick.joy1_y1;


NalaTI 04-11-2010 13:40

Re: [FTC]: Deadbands (axis/motor power restrictions)
 
I dont have it right here, but ours is something like:

Code:

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

Re: [FTC]: Deadbands (axis/motor power restrictions)
 
Quote:

Originally Posted by RCXRM (Post 979608)
Here is the code we've used to create deadbands:

Code:

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

coollog 04-11-2010 19:03

Re: [FTC]: Deadbands (axis/motor power restrictions)
 
Another way to do it is

Code:

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.


All times are GMT -5. The time now is 18:37.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi