#include <ArJoyHandler.h>
Public Member Functions | |
ArJoyHandler (bool useOSCal=true, bool useOldJoystick=false) | |
Constructor. | |
void | endCal (void) |
Ends the calibration process. | |
void | getAdjusted (int *x, int *y, int *z=NULL) |
Gets the adjusted reading, as integers, based on the setSpeed. | |
double | getAxis (unsigned int axis) |
Gets the floating (-1 to 1) location of the given joystick axis. | |
bool | getButton (unsigned int button) |
Gets the button. | |
void | getDoubles (double *x, double *y, double *z=NULL) |
Gets the adjusted reading, as floats, between -1.0 and 1.0. | |
unsigned int | getNumAxes (void) |
Gets the number of axes the joystick has. | |
unsigned int | getNumButtons (void) |
Gets the number of buttons the joystick has. | |
void | getSpeeds (int *x, int *y, int *z) |
Gets the speeds that X and Y are set to. | |
void | getStats (int *maxX, int *minX, int *maxY, int *minY, int *cenX, int *cenY) |
Gets the stats for the joystick, useful after calibrating to save values. | |
void | getUnfiltered (int *x, int *y, int *z=NULL) |
bool | getUseOSCal (void) |
Gets whether to just use OS calibration or not. | |
bool | haveJoystick (void) |
Returns if the joystick was successfully initialized or not. | |
bool | haveZAxis (void) |
Returns true if we definitely have a Z axis (we don't know in windows unless it moves). | |
bool | init (void) |
Intializes the joystick, returns true if successful. | |
void | setSpeeds (int x, int y, int z=0) |
Sets the max that X or Y will return. | |
void | setStats (int maxX, int minX, int maxY, int minY, int cenX, int cenY) |
Sets the stats for the joystick, useful for restoring calibrated settings. | |
void | setUseOSCal (bool useOSCal) |
Sets whether to just use OS calibration or not. | |
void | startCal (void) |
Starts the calibration process. | |
~ArJoyHandler () | |
Destructor. | |
Protected Member Functions | |
void | getData (void) |
void | getNewData (void) |
Handles the reading of the data into the bins. | |
void | getOldData (void) |
Protected Attributes | |
std::map< unsigned int, int > | myAxes |
std::map< unsigned int, bool > | myButtons |
int | myCenX |
int | myCenY |
bool | myFirstData |
bool | myHaveZ |
bool | myInitialized |
int | myJoyData |
int | myJoyDesc |
char | myJoyNameTemp [512] |
int | myJoyNumber |
ArTime | myLastDataGathered |
ArTime | myLastOpenTry |
int | myMaxX |
int | myMaxY |
int | myMinX |
int | myMinY |
FILE * | myOldJoyDesc |
int | myPhysMax |
int | myTopX |
int | myTopY |
int | myTopZ |
bool | myUseOld |
bool | myUseOSCal |
The joystick handler keeps track of the minimum and maximums for both axes, updating them to constantly be better calibrated. The speeds set influence what is returned by getAdjusted...
The joystick is not opened until init is called. What should basically be done to use this class is to 'init' a joystick, do a 'setSpeed' so you can use 'getAdusted', then at some point do a 'getButton' to see if a button is pressed, and then do a 'getAdjusted' to get the values to act on.
Also note that x is usually rotational velocity (since it right/left), whereas Y is translational (since it is up/down).
You can also use this to do multiple uses with the joystick, for example to have button 1 drive the robot while to have button 2 move the camera, you can get the different values you want (don't want to move the camera as quickly or as far as the robot) by using setSpeed before doing getAdjusted since setSpeed is fast and won't take any time.
Definition at line 69 of file ArJoyHandler.h.
|
Constructor.
Definition at line 40 of file ArJoyHandler.cpp. |
|
Ends the calibration process. Ends the calibration, which also sets the center to where the joystick is when the function is called... the center is never reset except in this function, whereas the min and maxes are constantly checked
Definition at line 99 of file ArJoyHandler.cpp. References getUnfiltered(). Referenced by init(). |
|
Gets the adjusted reading, as integers, based on the setSpeed. if useOSCal is true then this returns the readings as calibrated from the OS. If useOSCal is false this finds the percentage of the distance between center and max (or min) then takes this percentage and multiplies it by the speeds given the class, and returns the values computed from this.
Definition at line 151 of file ArJoyHandler.cpp. References getUnfiltered(), and ArMath::roundInt(). |
|
Gets the floating (-1 to 1) location of the given joystick axis.
Definition at line 258 of file ArJoyHandler.cpp. Referenced by ArActionJoydrive::fire(). |
|
Gets the button.
Definition at line 278 of file ArJoyHandler.cpp. Referenced by ArActionJoydrive::fire(). |
|
Gets the adjusted reading, as floats, between -1.0 and 1.0. If useOSCal is true then this returns the readings as calibrated from the OS. If useOSCal is false this finds the percentage of the distance between center and max (or min) then takes this percentage and multiplies it by the speeds given the class, and returns the values computed from this.
Definition at line 201 of file ArJoyHandler.cpp. References getUnfiltered(). Referenced by ArActionJoydrive::fire(). |
|
Gets the number of axes the joystick has.
Definition at line 296 of file ArJoyHandler.cpp. |
|
Gets the number of buttons the joystick has.
Definition at line 305 of file ArJoyHandler.cpp. |
|
Gets the unfilitered reading, mostly for internal use, maybe useful for Calibration Definition at line 243 of file ArJoyHandler.cpp. Referenced by endCal(), getAdjusted(), getDoubles(), and startCal(). |
|
Gets whether to just use OS calibration or not.
Definition at line 71 of file ArJoyHandler.cpp. |
|
Sets whether to just use OS calibration or not.
Definition at line 60 of file ArJoyHandler.cpp. Referenced by ArActionJoydrive::fire(), ArRatioInputJoydrive::setUseOSCal(), and ArActionJoydrive::setUseOSCal(). |
|
Starts the calibration process. Starts the calibration, which resets all the min and max variables as well as the center variables.
Definition at line 80 of file ArJoyHandler.cpp. References getUnfiltered(). Referenced by init(). |