Go to Post I am a mentor now and I would be more proud of a National Chairmans Award which acknowledges my many years of service to the team and the community rather than a National Championship which acknowledges one great robot I helped build. - The Lucas [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 30-01-2009, 11:47
Mike Soukup's Avatar
Mike Soukup Mike Soukup is offline
Software guy
FRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1996
Location: Schaumburg, IL
Posts: 797
Mike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond repute
New class for Logitech Dual Action Gamepad

Wildstang is using the Logitech Dual Action Gamepad for our manipulator this year so I "borrowed" the gamepad class that 1114 released as part of the beta project (thanks guys ) for some early testing. I quickly realized that it didn't give access to the D-pad and the left analog stick at the same time since the joystick class they derived from only gives access to four controller axes at once. You have to press the "Mode" button to swap between the D-pad and the left analog stick. Since we want to use both at the same time, I wrote my own class that interfaces directly with the DriverStation class, just like the provided Joystick class does. I didn't bother to add GetLeftTrigger() or similar methods because we won't be using those, but they should be simple for you to add if you need them.

I figured that since most of the code in the new class was pieced together from code in the WPILib Joystick class and the Simbot's LogitechGamepad class, the fair thing to do is release it to everyone. I wouldn't have been able to create this class as quickly and easily without using both of those classes as references.

The code is fairly well tested and it should work fine since it's very simple stuff, but if you find any bugs or make improvements, please post them here.
Attached Files
File Type: zip Gamepad.zip (1.6 KB, 292 views)
Reply With Quote
  #2   Spotlight this post!  
Unread 30-01-2009, 12:21
Pat Fairbank's Avatar
Pat Fairbank Pat Fairbank is offline
Circuit Breaker
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2001
Location: San Jose, CA
Posts: 2,132
Pat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond repute
Send a message via MSN to Pat Fairbank
Re: New class for Logitech Dual Action Gamepad

Thanks!

For some reason I was under the impression that it wasn't physically possible to access both the D-pad and the left stick at the same time when I wrote that class, so thanks for clearing that up.
__________________
Patrick Fairbank
Team 254 | Mentor (2012-)
Team 1503 | Mentor (2007-2011)
Team 296 | Alumnus (2001-2004) | Mentor (2005-2006)

patfairbank.com
Reply With Quote
  #3   Spotlight this post!  
Unread 30-01-2009, 14:15
Mr. Lim Mr. Lim is offline
Registered User
AKA: Mr. Lim
no team
Team Role: Leadership
 
Join Date: Jan 2004
Rookie Year: 1998
Location: Toronto, Ontario
Posts: 1,125
Mr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond repute
Re: New class for Logitech Dual Action Gamepad

Thanks from us here as well!

We're using these exact gamepads for both driver and operator. We haven't gotten around to using the D-Pad portion of it, but we know will need to soon enough.
__________________
In life, what you give, you keep. What you fail to give, you lose forever...
Reply With Quote
  #4   Spotlight this post!  
Unread 08-02-2009, 18:54
Phazonmutant's Avatar
Phazonmutant Phazonmutant is offline
Winrar
AKA: Greg Mitchell
FRC #2556 (RadioActive Roaches)
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Niceville, FL
Posts: 17
Phazonmutant is on a distinguished road
Re: New class for Logitech Dual Action Gamepad

We're planning on using the Logitech gamepad to control our arm, and just for the sake of time I've been using the FRC Joystick class. It actually provides all the functionality you need (axes, buttons, etc), but this should make the code more user-friendly, thanks!

Regarding the actual class:
The D-pad is made from a standard x and a y axis (as you know), but each only return either 1 or -1. The if statements (ex: x < -0.5) would more simply be written like if(x = -1).
EDIT: this is not good practice, see below.

I hope you don't mind, attached is a modification of your Gamepad class that adds an enum for button type (top, bottom-left-trigger, etc) and a Get function that uses the new enum. Hopefully that should make the code more user-friendly.

EDIT: Updated attachment to use the original d-pad code (which, as pointed out below, is more portable and better follows convention).
Also, this particular class assumes the Logitech Dual-Action gamepad with its button enumeration. This should be easy enough to reorder for other gamepads.
Attached Files
File Type: zip Gamepad.zip (1.7 KB, 117 views)

Last edited by Phazonmutant : 08-02-2009 at 20:55.
Reply With Quote
  #5   Spotlight this post!  
Unread 08-02-2009, 19:01
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: New class for Logitech Dual Action Gamepad

Quote:
Originally Posted by Phazonmutant View Post
Regarding the actual class:
The D-pad is made from a standard x and a y axis (as you know), but each only return either 1 or -1. The if statements (ex: x < -0.5) would more simply be written like if(x = -1).
I think Mike did that intentionally because the values that are being used are floats. Because of this, you shouldn't perform equality checks on them, but rather check a range. This page provides a good explanation on why this is the case. While the equality works most of the time, using .5 as the comparison point works all the time.
Reply With Quote
  #6   Spotlight this post!  
Unread 08-02-2009, 19:20
Phazonmutant's Avatar
Phazonmutant Phazonmutant is offline
Winrar
AKA: Greg Mitchell
FRC #2556 (RadioActive Roaches)
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Niceville, FL
Posts: 17
Phazonmutant is on a distinguished road
Re: New class for Logitech Dual Action Gamepad

Quote:
I think Mike did that intentionally because the values that are being used are floats. Because of this, you shouldn't perform equality checks on them, but rather check a range.
In general, you're absolutely right. But in this case, I've done pretty extensive testing (outputting the raw axis value to the console), and the gamepad will always output -1 or 1.

Edit 1: You'll notice the article is talking about testing floats when doing floating point math. Since we're doing no math, only testing a returned value, it's safe.
Edit 2: Furthermore, it talks about how the binary representation is not 100% precise for some numbers. The binary representation of floating points is implementation-specific, but lets assume the first bit is for the sign, the next 24 bits are for the significant figures, and the last 7 bits are for the base (IEEE 754 defines 24 bits as standard for 32-bit - single precision - floating point numbers). OK, a d1 (a 1 in decimal) looks like:
Code:
11000000000000000000000000000000
or, a 1 for the sign, a "100000000000000000000000" (a 1 followed by 23 0s) for the significant figures, and 7 0s (base = 0).
This is precisely 1.

Last edited by Phazonmutant : 08-02-2009 at 19:30.
Reply With Quote
  #7   Spotlight this post!  
Unread 08-02-2009, 19:40
Dave Flowerday Dave Flowerday is offline
Software Engineer
VRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: Feb 2002
Rookie Year: 1995
Location: North Barrington, IL
Posts: 1,366
Dave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond repute
Re: New class for Logitech Dual Action Gamepad

Quote:
Originally Posted by Phazonmutant View Post
In general, you're absolutely right. But in this case, I've done pretty extensive testing (outputting the raw axis value to the console), and the gamepad will always output -1 or 1.

Edit 1: You'll notice the article is talking about testing floats when doing floating point math. Since we're doing no math, only testing a returned value, it's safe.
Edit 2: Furthermore, it talks about how the binary representation is not 100% precise for some numbers. The binary representation of floating points is implementation-specific, but lets assume the first bit is for the sign, the next 24 bits are for the significant figures, and the last 7 bits are for the base (IEEE 754 defines 24 bits as standard for 32-bit - single precision - floating point numbers). OK, a d1 (a 1 in decimal) looks like:
Code:
11000000000000000000000000000000
or, a 1 for the sign, a "100000000000000000000000" (a 1 followed by 23 0s) for the significant figures, and 7 0s (base = 0).
This is precisely 1.
We're using a Logitech gamepad that outputs analog values on the D-Pad. The buttons under the dpad on that stick are pressure sensitive and CAN output a value less than 1 if you press them lightly. And, most people follow the "don't test an exact value of a float" as a rule-of-thumb (so as not to get into trouble) rather than considering the exact implementation and whether it's safe for a particular case. We tend to write code with portability in mind, even if we're not likely to port it, just as a good habit to have.
Reply With Quote
  #8   Spotlight this post!  
Unread 08-02-2009, 20:56
Phazonmutant's Avatar
Phazonmutant Phazonmutant is offline
Winrar
AKA: Greg Mitchell
FRC #2556 (RadioActive Roaches)
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Niceville, FL
Posts: 17
Phazonmutant is on a distinguished road
Re: New class for Logitech Dual Action Gamepad

Quote:
The buttons under the dpad on that stick are pressure sensitive and CAN output a value less than 1 if you press them lightly.
Ah, I hadn't considered that. I'd only seen 1 or -1.

You're absolutely right on all counts. I got a bit too into the argument xD

I updated the code I posted above to the original d-pad code.
Not a huge improvement over the original code, but worthwhile, I think.
Reply With Quote
  #9   Spotlight this post!  
Unread 11-02-2009, 20:08
Ken Streeter's Avatar
Ken Streeter Ken Streeter is offline
Let the MAYHEM begin!
FRC #1519 (Mechanical Mayhem)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 2005
Location: Team: Milford, NH; Me: Bedford, NH
Posts: 469
Ken Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond reputeKen Streeter has a reputation beyond repute
Re: New class for Logitech Dual Action Gamepad

Quote:
Originally Posted by Mike Soukup View Post
Wildstang is using the Logitech Dual Action Gamepad for our manipulator this year so I "borrowed" the gamepad class that 1114 released as part of the beta project (thanks guys ) for some early testing. ...

I figured that since most of the code in the new class was pieced together from code in the WPILib Joystick class and the Simbot's LogitechGamepad class, the fair thing to do is release it to everyone. I wouldn't have been able to create this class as quickly and easily without using both of those classes as references. ...
Thanks to all of those that have worked on this and released it to everybody! I'm really looking forward to the forthcoming "open source project" for the WPILib robot code, where hopefully lots of teams will be able to work together to publish generically useful capabilities like this!

Thanks again!
__________________
Ken Streeter - Team 1519 - Mechanical Mayhem (Milford Area Youth Homeschoolers Enriching Minds)
2015 NE District Winners with 195 & 2067, 125 & 1786, 230 & 4908, and 95 & 1307
2013 World Finalists & Archimedes Division Winners with 33 & 469
2013 & 2012 North Carolina Regional Winners with teams 435 & 4828 and 1311 & 2642
2011, 2010, 2006 Granite State Regional Winners with teams 175 & 176, 1073 & 1058, and 1276 & 133
Team 1519 Video Gallery - including Chairman's Video, and the infamous "Speed Racer!"
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
define a new class(C++) nadavsen2 C/C++ 15 02-11-2010 13:21
pic: 716 Dual Motor/Dual Speed CD47-Bot Robot Showcase 18 23-04-2004 01:51
White Paper Discuss: Dual-motor, dual-speed gearbox CD47-Bot Extra Discussion 8 05-04-2004 19:24
White Paper Discuss: Dual-motor, dual-speed drive transmission design CD47-Bot Extra Discussion 9 03-09-2003 10:40
Gamepad Controller Mike375 Technical Discussion 13 05-03-2002 21:20


All times are GMT -5. The time now is 14:09.

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