View unanswered posts | View active topics It is currently Wed Jul 23, 2014 7:56 am






Reply to topic  [ 3 posts ] 
Joystick problems!! 
Author Message
Novice

Joined: Tue Jan 13, 2009 5:22 pm
Posts: 72
Location: USA, Pennsylvania
Post Joystick problems!!
Our team have a problem with the joysticks, they are not centered correctly. We have used Windows program to calibrate it but it still not calibrated good enough.
We wondered if there is a code that stops the robots motors/servos if the x or y value is between 0-15.

_________________
We need a Linux Version!


Wed Feb 04, 2009 9:11 am
Profile WWW
Novice

Joined: Fri Oct 24, 2008 8:58 am
Posts: 87
Post Re: Joystick problems!!
1) I don't recommend using the windows program to recalibrate the joysticks. This calibration is only stored on the computer it was performed on. I mentioned that calibration in an earlier post, but it was to make sure it hadn't been done...I should have been more clear on that.

2) Analog joysticks can be quite bad at both noise (value changing with out touching the sticks) and centering (not returning to exactly the same spot).

This really needs to be corrected by your code, not relying on the joystick to be more accurate than it is. Here's one method:
Code:
#include "JoystickDriver.c"

int handleAxis(int val, int dbMin, int dbMax)
{

  // 1. Remove the Deadband and shift everything back to zero
   if (val <= dbMin)
      val = (val - dbMin);
   else if (val >= dbMax)
      val = (val - dbMax);
   else
      val = 0;

   // 2. Now realign the axis so that the output is 0-100 between dbMax and +127
   //    and -100 to 0 between -128 and dbMin.

   if (val > 0)
   {
    val *= 100;
    val /=  (127 - dbMax);          // dbMax should be >= 0
   }
   else
   {
    val *= 100;
    val /= (128 + dbMin);             // dbMin should be <= 0
   }


   return val;
}

void handleJoystick()
{
   joystick.joy1_x1 = handleAxis(joystick.joy1_x1, -10, 10);
   joystick.joy1_y1 = handleAxis(joystick.joy1_y1, -10, 10);
   joystick.joy1_x2 = handleAxis(joystick.joy1_x2, -10, 10);
   joystick.joy1_y2 = handleAxis(joystick.joy1_y2, -10, 10);

   joystick.joy2_x1 = handleAxis(joystick.joy2_x1, -10, 10);
   joystick.joy2_y1 = handleAxis(joystick.joy2_y1, -10, 10);
   joystick.joy2_x2 = handleAxis(joystick.joy2_x2, -10, 10);
   joystick.joy2_y2 = handleAxis(joystick.joy2_y2, -10, 10);
}

task main()
{
  getJoystickSettings(joystick);
  handleJoystick();
}


This function ignores any values between dbMin and dbMax ie (-10, +10) and also makes the output smooth and continuous between -100 and +100.

Hope it helps.


Wed Feb 04, 2009 11:16 am
Profile
Novice

Joined: Tue Jan 13, 2009 5:22 pm
Posts: 72
Location: USA, Pennsylvania
Post Re: Joystick problems!!
Thank you its working really good!!
Much smoother also!!

_________________
We need a Linux Version!


Thu Feb 05, 2009 5:20 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.