Main Page   Class Hierarchy   Compound List   Compound Members  

ArJoyHandler Class Reference

Interfaces to a joystick. More...

#include <ArJoyHandler.h>

List of all members.

Public Methods

 ArJoyHandler (bool useOSCal=true)
 Constructor. More...

 ~ArJoyHandler (void)
 Destructor.

bool init (void)
 Intializes the joystick, returns true if successful.

void setUseOSCal (bool useOSCal)
 Sets whether to just use OS calibration or not. More...

bool getUseOSCal (void)
 Gets whether to just use OS calibration or not. More...

bool haveJoystick (void)
 Returns if the joystick was successfully initialized or not.

void setSpeeds (int x, int y)
 Sets the max that X or Y will return.

void getAdjusted (int *x, int *y)
 Gets the adjusted reading, as integers, based on the setSpeed. More...

void getDoubles (double *x, double *y)
 Gets the adjusted reading, as floats, between -1.0 and 1.0. More...

bool getButton (int button)
 Checkes whether the given button is pressed or not. More...

void startCal (void)
 Starts the calibration process. More...

void endCal (void)
 Ends the calibration process. More...

void getUnfiltered (int *x, int *y)
 Gets the unfilitered reading, mostly for internal use, maybe useful for Calibration. More...

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 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 getSpeeds (int *x, int *y)
 Gets the speeds that X and Y are set to.


Detailed Description

Interfaces to a joystick.

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.


Constructor & Destructor Documentation

ArJoyHandler::ArJoyHandler bool    useOSCal = true
 

Constructor.

Parameters:
useOSCal  if this is set then the joystick will just rely on the OS to calibrate, otherwise it will keep track of center min and max and use those values for calibration


Member Function Documentation

void ArJoyHandler::endCal void   
 

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

See also:
startCal

void ArJoyHandler::getAdjusted int *    x,
int *    y
 

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.

Parameters:
x  pointer to an integer in which to store the x value, which is between - x given in set speeds and x given in set speeds
y  pointer to an integer in which to store the y value, which is between - y given in set speeds and y given in set speeds

bool ArJoyHandler::getButton int    button
 

Checkes whether the given button is pressed or not.

Parameters:
button  button to test for pressed, buttons are 1 through 4
Returns:
true if the button is pressed, false otherwise

void ArJoyHandler::getDoubles double *    x,
double *    y
 

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.

Parameters:
x  pointer to a double in which to store the x value, this value is a value between -1.0 and 1.0, for where the stick is on that axis
y  pointer to a double in which to store the y value, this value is a value between -1.0 and 1.0, for where the stick is on that axis

void ArJoyHandler::getUnfiltered int *    x,
int *    y
 

Gets the unfilitered reading, mostly for internal use, maybe useful for Calibration.

This returns the raw value from the joystick... with X and Y varying between -128 and poseitive 128... this shouldn't be used except in calibration since it'll give very strange readings. For example its not uncommon for a joystick to move 10 to the right but 50 or 100 to the left, so if you aren't adjusting for this you get a robot (or whatever) that goes left really fast, but will hardly go right, hence you should use getAdjusted exclusively except for display in calibration.

Parameters:
x  pointer to an integer in which to store x value
y  pointer to an integer in which to store y value

bool ArJoyHandler::getUseOSCal void   
 

Gets whether to just use OS calibration or not.

Returns:
if useOSCal is set then the joystick will just rely on the OS to calibrate, otherwise it will keep track of center min and max and use those values for calibration

void ArJoyHandler::setUseOSCal bool    useOSCal
 

Sets whether to just use OS calibration or not.

Parameters:
useOSCal  if this is set then the joystick will just rely on the OS to calibrate, otherwise it will keep track of center min and max and use those values for calibration

void ArJoyHandler::startCal void   
 

Starts the calibration process.

Starts the calibration, which resets all the min and max variables as well as the center variables.

See also:
endCal


The documentation for this class was generated from the following files:
Generated on Tue Nov 12 17:43:57 2002 for Aria by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001