ADBLib  0.5
A simple library for rapid robot code development
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Pages
ADBLib::Controller Class Reference

A wrapper class for the WPILib Joystick class, adding some stuff to take the headache out of working with raw inputs. More...

#include <Controller.h>

Collaboration diagram for ADBLib::Controller:

Public Member Functions

 ~Controller ()
 
bool getButtonRaw (int ID)
 Gets the raw button setting as true or false, disregarding any active cooldowns. More...
 
double getJoystickRaw (int ID)
 Gets the raw axis value. More...
 
void setJoystick (Joystick *newJoystick)
 Sets the joystick to get data from. More...
 
void setRumble (Joystick::RumbleType side, float intensity=1.f)
 Make the controller rumble using built-in rumbler thingies. More...
 
void parseConfig (string filename)
 Loads control settings from a config file, because hard-coded controls are awful. More...
 
void switchProfile (string profileName)
 Switches out the current control profile for another profile, specified by name. More...
 
double operator[] (const string &name)
 Get the value of a set control, referenced by name. More...
 

Protected Attributes

unordered_map< string,
unordered_map< string, ctrlCfg > > 
profiles
 
string currentProfile
 
Joystick * joystick
 

Detailed Description

A wrapper class for the WPILib Joystick class, adding some stuff to take the headache out of working with raw inputs.

Constructor & Destructor Documentation

ADBLib::Controller::~Controller ( )

Member Function Documentation

bool ADBLib::Controller::getButtonRaw ( int  ID)

Gets the raw button setting as true or false, disregarding any active cooldowns.

Parameters
IDThe ID of the button. ID changes depending on controller mode (X-Mode or D-Mode)
double ADBLib::Controller::getJoystickRaw ( int  ID)

Gets the raw axis value.

Parameters
IDThe ID of the joystick. ID changes depending on controller mode (X-Mode or D-Mode)
double ADBLib::Controller::operator[] ( const string &  name)

Get the value of a set control, referenced by name.

Parameters
nameThe name of the control. Referenced in the XML configuration file.
Returns
If the control is a button, nonzero for true and zero for false (duh). Else, a double.
Note
If you get inexplicable crashes originating from this class, check to make sure you gave it a joystick.

Here is the call graph for this function:

void ADBLib::Controller::parseConfig ( string  filename)

Loads control settings from a config file, because hard-coded controls are awful.

Config files should be structured as follows:

  • The root node should be called "ControlConfig".
  • The children underneath the root node should be called "profile" with an attribute "name". This name is the name for a specific control profile. There should also be an attribute "active", which should be either true or false. This sets which control profile is active.
  • Nodes underneath a profile node should be named "control". They should have an attribute "type" (either button or joystick), an attribute "name", which is how you will refer to the control in the code, and an "id" attribute, for the control ID.
  • A control node's children should vary depending on control type.
    • All children will name the type of parameter, whereas an XML attribute ("value") specifies the value.
    • Button controls need only have "toggle" (boolean) and "cooldown" (double) parameters..
    • Joystick controls have four parameters: maxInput, minInput, deadzone, and equation (how the resulting value is modified; negative-blind).
    • Both button and joystick controls can accept an "inverse" (boolean) parameter, to invert output.

An example (tiny) XML config file follows (you might need to check the source code, doxygen screws up the tabs!):

<ControlConfig> <profile name="Sourec" active="false"> <control type="button" id="0" name="raiseForks"> <toggle value="false"> <cooldown value="0.250"> </control> <control type="joystick" name="intakeWheels" id="5"> <maxInput value="1.0"> <minInput value="-1.0"> <deadzone value="0.1"> <equation value="x"> </control> </profile> </ControlConfig>

Parameters
cfgFileThe path/filename to the config file.
Note
RoboRIOs are UNIX-y! This means that your directory (even if it's just the root directory!) should start out with a '/' !
Not setting a control parameter in the file will cause default values to be used! If you suspect error, check the log!

Here is the call graph for this function:

void ADBLib::Controller::setJoystick ( Joystick *  newJoystick)

Sets the joystick to get data from.

Parameters
newJoystickA shared pointer to the joystick to use.
void ADBLib::Controller::setRumble ( Joystick::RumbleType  side,
float  intensity = 1.f 
)

Make the controller rumble using built-in rumbler thingies.

Parameters
sideThe side on which the joystick will rumble. Definedby WPILib.
intensityThe intensity of vibration on a scale from 0 to 1.
void ADBLib::Controller::switchProfile ( string  profileName)

Switches out the current control profile for another profile, specified by name.

Parameters
profileNameThe name of the profile to switch to as a string.

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

string ADBLib::Controller::currentProfile
protected
Joystick* ADBLib::Controller::joystick
protected
unordered_map<string, unordered_map<string, ctrlCfg> > ADBLib::Controller::profiles
protected

The documentation for this class was generated from the following files: