Go to Post Please try to apply GP to situations where it makes some sense, as otherwise you're just diluting the meaning. - Kevin Sevcik [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 02-08-2012, 14:08
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
How do I program a joystick deadband?

I'm using an Xbox controller, which are notorious for not returning to center properly. I want to use a threshold of +- .1 (on a scale of -1 to 1).

I assume it would be something like:

Code:
if ((joystick < .1) && (joystick > -.1)) {
return 0;
}
but I'm new to Java and have no idea where I would put the statement.


Also: I'm planning on using one thumbstick to turn, and the right trigger as throttle, but I'm not sure how you would accomplish that and most tutorials are either for tank drive or in languages other than Java.

Thanks!
Reply With Quote
  #2   Spotlight this post!  
Unread 04-08-2012, 13:58
Djur's Avatar
Djur Djur is offline
WPILib
AKA: Sam Carlberg
no team
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2009
Location: Massachusetts
Posts: 182
Djur will become famous soon enough
Re: How do I program a joystick deadband?

About your first question:

Code:
public double getJoystickValue(Joystick joystick) {
    if(Math.abs(joystick.getValue() < 0.1) return 0;
    else return joystick.getValue();
}
This checks the value of the given joystick and returns a double based on your threshold. You'll have to create the Joystick objects yourself; I am unfamiliar with Xbox controllers.

As for your second question about using two joysticks, the RobotDrive classes have an arcadeDrive method that has two arguments: the speed you go forward (the value of the throttle joystick) and the speed you turn at (the value of the turning joystick).
__________________
WPILib dev (RobotBuilder, SmartDashboard, GRIP)
Reply With Quote
  #3   Spotlight this post!  
Unread 05-08-2012, 11:30
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
Re: How do I program a joystick deadband?

Does this appear to be correct?

Reply With Quote
  #4   Spotlight this post!  
Unread 06-08-2012, 10:16
Djur's Avatar
Djur Djur is offline
WPILib
AKA: Sam Carlberg
no team
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2009
Location: Massachusetts
Posts: 182
Djur will become famous soon enough
Re: How do I program a joystick deadband?

I'd just suggest changing the name of your "turn" method to something less confusing, such as "getCompensatedValue" or "getBetterValue" (or anything better you can think of). If you call "turn(Xbox)", then you may be confused why the robot's not turning Other than that, you should be good. Good luck!
__________________
WPILib dev (RobotBuilder, SmartDashboard, GRIP)
Reply With Quote
  #5   Spotlight this post!  
Unread 06-08-2012, 18:18
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,590
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: How do I program a joystick deadband?

Quote:
Originally Posted by F22Rapture View Post
Does this appear to be correct?

You've created a new function, but haven't called it. In order to do the equivalent of the commented out code, you would need to add another line similar to the following
Code:
double turn = turn(Xbox);
(I'm not very experienced with java, so it might not even compile with having variable named the same as a function). Notice how this isn't exactly clear, which is why Djur recommended renaming turn to something more generic. Doesn't this sound better?
Code:
double turn = applyDeadband(Xbox);
There's probably a better way to write the deadband function so that you could apply it to the throttle also easily without creating a second function. Can you think of another way to do it?
Reply With Quote
  #6   Spotlight this post!  
Unread 08-10-2012, 01:24
techkid86's Avatar
techkid86 techkid86 is offline
Magic Programer
FRC #3044 (0xBE4)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2010
Location: ballston spa
Posts: 58
techkid86 is an unknown quantity at this point
Re: How do I program a joystick deadband?

Allow me to show you a piece of code my team has used the last three years....


public double deadband(double JoystickValue, double DeadbandCutOff) {
if (JoystickValue<DeadbandCutOff&&JoystickValue>(Dead bandCutOff*(-1))) {
deadbandreturn=0;
}
else {
deadbandreturn=(JoystickValue-(Math.abs(JoystickValue)/JoystickValue*DeadbandCutOff))/(1-DeadbandCutOff);
}

return deadbandreturn;
}

this not only cuts it off at a point, but prevents jumping up to 0.1 after you get past it. it basically smooths the dead band curve. How ever, i would recommend making a algorithm you understand. ((i am still working on understanding this one. lol))
__________________
"you can build a perfect machine out of imperfect parts" -Urza

Last edited by techkid86 : 08-10-2012 at 01:31.
Reply With Quote
  #7   Spotlight this post!  
Unread 08-10-2012, 11:07
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: How do I program a joystick deadband?

Quote:
Originally Posted by techkid86 View Post
public double deadband(double JoystickValue, double DeadbandCutOff) {
if (JoystickValue<DeadbandCutOff&&JoystickValue>(Dead bandCutOff*(-1))) {
deadbandreturn=0;
}
else {
deadbandreturn=(JoystickValue-(Math.abs(JoystickValue)/JoystickValue*DeadbandCutOff))/(1-DeadbandCutOff);
}

return deadbandreturn;
}
That's actually some pretty clever code... I'd like to put that on our robot this year, if you're okay with that.

To anyone confused:
The first if() checks if the joystick value is in the (-deadband,deadband) range (this could more succinctly be done with Math.abs(JoystickValue) < deadband), and if so, puts the output to 0. Otherwise, it scales the joystick value to [0,1] or [-1,0] depending on the sign by modifying the ranges this way:
[deadband,1] -> [0,1-deadband] -> [0,1]
[-1,-deadband] -> [-1+deadband,0] -> [-1,0]

Code:
deadbandreturn=(JoystickValue- // initially in one of two ranges: [DeadbandCutOff,1] or [-1,-DeadBandCutOff]
                (Math.abs(JoystickValue)/JoystickValue // 1 if JoystickValue > 0, -1 if JoystickValue < 0 (abs(x)/x); could use Math.signum(JoystickValue) instead
                 *DeadbandCutOff // multiply by the sign so that for >0, it comes out to - (DeadBandCutOff), and for <0 it comes to - (-DeadBandCutOff)
                )
               ) // now in either [0,1-DeadBandCutOff] or [-1+DeadBandCutOff,0]
               /(1-DeadbandCutOff); // scale to [0,1] or [-1,0]

Last edited by Ginto8 : 08-10-2012 at 12:13.
Reply With Quote
  #8   Spotlight this post!  
Unread 08-10-2012, 12:41
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: How do I program a joystick deadband?

Quote:
Originally Posted by Ginto8 View Post
Otherwise, it scales the joystick value to [0,1] or [-1,0]
There's deadband in the motor controller too.


Reply With Quote
  #9   Spotlight this post!  
Unread 17-10-2012, 16:27
CodeYeti's Avatar
CodeYeti CodeYeti is offline
FRC Addict
AKA: Matt Coffin
FRC #0662 (Rocky Mountain Robotics)
Team Role: Mentor
 
Join Date: Feb 2011
Rookie Year: 2010
Location: Colorado
Posts: 81
CodeYeti is an unknown quantity at this point
Re: How do I program a joystick deadband?

Personally, the best way I can think of to go about this would be to extend the Joystick class, making a DeadbandJoystick class. I'll write up an example of what I'm talking about when I get home tonight.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


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

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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