Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Properly calling a Logitech Attack 3 Joystick Class (http://www.chiefdelphi.com/forums/showthread.php?t=135060)

Travis Hoffman 02-23-2015 11:44 AM

Setting up a Joystick class for Logitech Attack 3?
 
It seems the default definition for a Joystick class includes a twist axis, since the default joystick provided to rookies has such an axis. The first axis is X, the second Y, the third twist, and the fourth throttle.

Well, when we try to use our trusty Logitech Attack 3's, these do not possess a twist axis, so a formerly-functional GetThrottle() call returns nothing, since the default for throttle in the class is the 4th axis.

I was wondering why we were seeing "WARNING: Joystick Axis missing, check if all controllers are plugged in" showing up on the console, and now I think I understand why. I'd like to get rid of this warning.

I understand I can get the throttle value by calling GetZ() instead, but I wanted to know, short of writing a custom class, is there a way to instantiate a joystick class that correctly defines the axes and buttons for a Logitech Attack 3 such that GetThrottle will work?

Alan Anderson 02-23-2015 12:34 PM

Re: Properly calling a Logitech Attack 3 Joystick Class
 
I don't understand why you suggest that writing a custom class is not the appropriate answer. If you want to support the Attack 3 in particular, I think the best way to do it is to extend the Joystick class as an Attack_3 class.

Since the named functions don't give you what you want, the second-best way to do it is probably to avoid them and instead use things like getRawAxis().

We did basically the custom class solution in LabVIEW for several different brands of game controllers this year. It lets us provide the axes and buttons as named components of a cluster, which helps keep the programmer and the driver speaking the same language. Instead of having to remember which array element's number is the left stick's Y axis, we just unbundle LeftX. Similarly, we can refer to the A, X, Start, etc. buttons by name.

Travis Hoffman 02-23-2015 01:03 PM

Re: Properly calling a Logitech Attack 3 Joystick Class
 
Quote:

Originally Posted by Alan Anderson (Post 1448715)
I don't understand why you suggest that writing a custom class is not the appropriate answer. If you want to support the Attack 3 in particular, I think the best way to do it is to extend the Joystick class as an Attack_3 class.

Since the named functions don't give you what you want, the second-best way to do it is probably to avoid them and instead use things like getRawAxis().

We did basically the custom class solution in LabVIEW for several different brands of game controllers this year. It lets us provide the axes and buttons as named components of a cluster, which helps keep the programmer and the driver speaking the same language. Instead of having to remember which array element's number is the left stick's Y axis, we just unbundle LeftX. Similarly, we can refer to the A, X, Start, etc. buttons by name.

I don't enjoy diverging from the well-beaten path, so if there was a way to instantiate a standard joystick class to fit an Attack 3 without making a custom class, I'd be all for it, which is why I asked.

As for the custom class, it doesn't help matters much when the WPILib C++ source code location isn't a heavily advertised thing...I found it...but it doesn't seem to be something that is as readily available as it was in the past.

We read all joystick and gamepad values into more functionally-descriptive variables, and this code is well-commented to provide a cross reference between actual controller axis/button and function, so using "GetZ" or "GetRawAxis" won't be an issue.

Alan Anderson 02-23-2015 01:40 PM

Re: Properly calling a Logitech Attack 3 Joystick Class
 
Quote:

Originally Posted by Travis Hoffman (Post 1448731)
I don't enjoy diverging from the well-beaten path, so if there was a way to instantiate a standard joystick class to fit an Attack 3 without making a custom class, I'd be all for it, which is why I asked.

There does seem to be a way in the basic Joystick class to remap axes to the X/Y/Z/Throttle functions, but I don't use C++ enough to have tried it.

Quote:

As for the custom class, it doesn't help matters much when the WPILib C++ source code location isn't a heavily advertised thing...I found it...but it doesn't seem to be something that is as readily available as it was in the past.
What do you need the source code for? All you'd be doing is inheriting from and extending an existing class. You wouldn't be reimplementing any of the lower-level code.

Quote:

We read all joystick and gamepad values into more functionally-descriptive variables, and this code is well-commented to provide a cross reference between actual controller axis/button and function, so using "GetZ" or "GetRawAxis" won't be an issue.
Such cross-referencing would seem to be a natural fit for a brand-specific joystick class, and perhaps even a higher-level "driver controls" class as well. Maybe you're thinking of something more complicated than extending the base class, but I don't believe that much work is called for here.

Travis Hoffman 02-23-2015 01:55 PM

Re: Properly calling a Logitech Attack 3 Joystick Class
 
Quote:

Originally Posted by Alan Anderson (Post 1448745)
There does seem to be a way in the basic Joystick class to remap axes to the X/Y/Z/Throttle functions, but I don't use C++ enough to have tried it.

I don't believe you can re-map the default value of the throttle, which is set to axis 3 (0-based values). You can define the number of axes and buttons, but not which axis is which.

Quote:

What do you need the source code for? All you'd be doing is inheriting from and extending an existing class. You wouldn't be reimplementing any of the lower-level code.
Last I "wrote" a custom class, I took gyro.cpp/.h source, renamed the files gyro48.cpp/.h, and changed the code to permit adjustment of the sensitivity parameter, which was previously not exposed to the end user. Seemed easier and more likely to work to adapt existing code than figure out all the BS of inheritance and writing my own classes and worrying about missing some inane piece of required syntax that would break the code or worse, compile it and cause unintended results I am not equipped to debug. If this somehow violates some code of appropriateness seasoned programmers adhere to, well, I'm not a seasoned programmer, nor do I aspire to be, so I guess it doesn't matter. :)

In the case of the joystick class, I'd simply change the default throttle axis from 3 to 2. Bing bang zoom. But with GetZ or GetRawAxis in the default class, I don't need to do that, so I won't even bother.

Alan Anderson 02-23-2015 02:34 PM

Re: Properly calling a Logitech Attack 3 Joystick Class
 
Quote:

Originally Posted by Travis Hoffman (Post 1448751)
I don't believe you can re-map the default value of the throttle, which is set to axis 3 (0-based values). You can define the number of axes and buttons, but not which axis is which.

The documentation for the Joystick::SetAxisChannel() method suggests otherwise.

Quote:

Last I "wrote" a custom class, I took gyro.cpp/.h source, renamed the files gyro48.cpp/.h, and changed the code to permit adjustment of the sensitivity parameter, which was previously not exposed to the end user.
If you were adding an interface to a private attribute of the class, then the way you did it was probably necessary. But was there ever a version of the Gyro class that didn't have the SetSensitivity() method?

Quote:

Seemed easier and more likely to work to adapt existing code than figure out all the BS of inheritance and writing my own classes and worrying about missing some inane piece of required syntax that would break the code or worse, compile it and cause unintended results I am not equipped to debug. If this somehow violates some code of appropriateness seasoned programmers adhere to, well, I'm not a seasoned programmer, nor do I aspire to be, so I guess it doesn't matter. :)
Since you seem to think subclassing by way of inheritance is complicated, I suspect you don't know what it means. It is not complicated. It should be as easy as
Code:

public class Axis_3 extends Joystick {
  float Axis_3::GetThrottle()
  {
        return GetRawAxis(2);
  }
}

That's kind of crude, but it should be effective. Note that I don't use C++ enough to be confident that I've done it correctly. Perhaps someone else with more experience and expertise can chime in and either confirm or correct my code.

Quote:

In the case of the joystick class, I'd simply change the default throttle axis from 3 to 2. Bing bang zoom. But with GetZ or GetRawAxis in the default class, I don't need to do that, so I won't even bother.
With the existence of SetAxisChannel(), I think you can indeed change the throttle axis of any Joystick object from 3 to 2 without even creating a new class.

bob.wolff68 02-23-2015 03:47 PM

Re: Properly calling a Logitech Attack 3 Joystick Class
 
I concur with Alan. Making a specific derivative of Joystick is the way to go. I think there's a mis-understanding with what this means. The following links will show an example of deriving jankyXBoxJoystick from Joystick - cpp and header folllow...

https://github.com/FRCTeam1967/FRCTe...oxJoystick.cpp

https://github.com/FRCTeam1967/FRCTe...XboxJoystick.h


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

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