Log in

View Full Version : Joystick axis values in new controller


koreabell
16-12-2008, 13:50
Are the values of joystick axis(x,y,and z) in new controller 0 to 255 like last controller? or do they have float value of -1.0 to +1.0?

i can't find what value it returns although my guess is float value of -1.0 to +1.0 since doxgen says function type is float.

just making sure

billbo911
16-12-2008, 14:02
READ the Programming Guide (http://decibel.ni.com/content/docs/DOC-2631), your question will be answered.

koreabell
16-12-2008, 14:47
well I'm programming in c++ and there is no examples or something like that on C/C++ Users Guide (http://first.wpi.edu/Images/CMS/First/C_Programming_Guide_for_FRC.pdf) for joystick axis value(there's nothing except for big "DRAFT" across the page when you go to joystick page)

there is GetRawAxis() function under joystick class which i assume it will return values between 0 to 255, but that is also float type function while GetRaw() function under PWM class is int type(actually UINT8 type) function.

i know float can handle more wide range than int, thus GetRawAxis() might return values between 0 and 255, but still i'm not sure and i won't know until new controller comes

anyway, i wrote a function that will return values between 0 and 255 even if GetY() or GetAxis() function returns values between -1.0 and +1.0

slavik262
16-12-2008, 17:05
Refer to the C/C++ Programmer Reference Guide (http://first.wpi.edu/Images/CMS/First/CProgrammingReference.chm).

You can either use Joystick::GetRawAxis(UINT32 axis), where axis is a value between 1 and 6 specifying the axis, or you can simply use Joystick::GetX() and Joystick::GetY(). All of these functions return a floating point value between -1.0f and 1.0f. Returning values between 0 and 255 will lower your precision, as a floating point variable can hold much more data than an unsigned character.

Joe Ross
16-12-2008, 17:23
In most cases, the WPI Robotics Library is equivalent between LabVIEW and C++, although the documentation isn't always as good for one or the other. 99% of the time, you should be able to look at the LabVIEW documentation if the C++ documentation isn't clear (and vice versa). Don't get caught up in the name of the document.

Returning values between 0 and 255 will lower your precision, as a floating point variable can hold much more data than an unsigned character. I don't believe that is true in this case. I'm pretty sure that DS sends the values to the cRIO as a single byte integer. In this case, they should be equivilent.

If you are trying to directly copy an algorithm from the IFI controller, it may be easier if you use the raw joystick values and the PWM class, but for implementing new things, you'll probably find it easier to work with the floating point values.

slavik262
16-12-2008, 22:19
I'm pretty sure that DS sends the values to the cRIO as a single byte integer. In this case, they should be equivilent.

I may be wrong, but in doing basic tests it seemed that the joystick had greater precision than that. What you're saying does make sense though. I'll have to take a deeper look at it.

Mike Soukup
17-12-2008, 10:38
Refer to the C/C++ Programmer Reference Guide (http://first.wpi.edu/Images/CMS/First/CProgrammingReference.chm).
I've downloaded that document on two computers and when I open it on both I get "The address is not valid" in the right pane. Is it a problem with the user or the document?

Mark McLeod
17-12-2008, 11:39
Is it due to Microsoft's problem with .chm format?

http://forums.usfirst.org/showthread.php?t=10708