View Single Post
  #3   Spotlight this post!  
Unread 04-11-2010, 13:40
NalaTI NalaTI is offline
Registered User
AKA: Alan
FTC #2848 (Techno Guards)
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2005
Location: California
Posts: 106
NalaTI is just really niceNalaTI is just really niceNalaTI is just really niceNalaTI is just really nice
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);

}
__________________
Reply With Quote