Go to Post But should we "discriminate" based on how long your team has been around? If you think about it, FIRST's goal is to inspire students, right? ...But students on rookie and second-year teams, if anything, are in greater need of being inspired. - LauraN [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 02-08-2009, 06:54 PM
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, 115 views)

Last edited by Phazonmutant : 02-08-2009 at 08:55 PM.
Reply With Quote
  #2   Spotlight this post!  
Unread 02-08-2009, 07:01 PM
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
  #3   Spotlight this post!  
Unread 02-08-2009, 07:20 PM
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 : 02-08-2009 at 07:30 PM.
Reply With Quote
  #4   Spotlight this post!  
Unread 02-08-2009, 07:40 PM
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
  #5   Spotlight this post!  
Unread 02-08-2009, 08:56 PM
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
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 11-02-2010 01:21 PM
pic: 716 Dual Motor/Dual Speed CD47-Bot Robot Showcase 18 04-23-2004 01:51 AM
White Paper Discuss: Dual-motor, dual-speed gearbox CD47-Bot Extra Discussion 8 04-05-2004 07:24 PM
White Paper Discuss: Dual-motor, dual-speed drive transmission design CD47-Bot Extra Discussion 9 09-03-2003 10:40 AM
Gamepad Controller Mike375 Technical Discussion 13 03-05-2002 09:20 PM


All times are GMT -5. The time now is 10:54 AM.

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