Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include "jaus/extras/controllers/joystick.h"
00041 #include <cmath>
00042 #include <tinyxml/tinyxml.h>
00043
00044 using namespace JAUS;
00045
00046
00052 Joystick::Joystick()
00053 {
00054 mID = CxUtils::Joystick::AnyJoystick;
00055 mFrequency = 25;
00056 mCalibrationFile = "/home/developer/logitech_extreme_3d";
00057 mEnableJoystickFlag = true;
00058 }
00059
00060
00066 Joystick::~Joystick()
00067 {
00068
00069 }
00070
00071
00081 bool Joystick::LoadSettings(const std::string& filename)
00082 {
00083 if(ControlDevice::LoadSettings(filename))
00084 {
00085 TiXmlDocument xml;
00086
00087 if(xml.LoadFile(filename.c_str()) == false)
00088 {
00089 return false;
00090 }
00091 TiXmlHandle doc(&xml);
00092 TiXmlNode* node;
00093
00094 node = doc.FirstChild("JAUS").FirstChild("ControlDevice").FirstChild("Joystick").FirstChild("ID").ToNode();
00095 if(node && node->FirstChild())
00096 {
00097 int id = atoi(node->FirstChild()->Value());
00098 if(id < 0)
00099 {
00100 mID = CxUtils::Joystick::AnyJoystick;
00101 }
00102 else
00103 {
00104 mID = (unsigned int)id;
00105 }
00106
00107 }
00108 node = doc.FirstChild("JAUS").FirstChild("ControlDevice").FirstChild("Joystick").FirstChild("Frequency").ToNode();
00109 if(node && node->FirstChild())
00110 {
00111 mFrequency = (unsigned int)atoi(node->FirstChild()->Value());
00112 }
00113 node = doc.FirstChild("JAUS").FirstChild("ControlDevice").FirstChild("Joystick").FirstChild("CalibrationFile").ToNode();
00114 if(node && node->FirstChild())
00115 {
00116 mCalibrationFile = node->FirstChild()->Value();
00117 }
00118
00119 if(mJoystick.GetID() != mID)
00120 {
00121 mJoystick.Shutdown();
00122 }
00123
00124 return true;
00125 }
00126 return false;
00127 }
00128
00129
00135 void Joystick::ProcessJoystickEvent(const CxUtils::Joystick& jstick)
00136 {
00137
00138
00139 ClearWrenchEffort();
00140
00141
00142 for(int i = 0; i < CxUtils::Joystick::MaxAxis; i++)
00143 {
00144 UpdateWrench(i, jstick.GetAxisPercentage((short)i, 0));
00145 UpdateAnalogOut(i, jstick.GetAxisPercentage((short)i, 0));
00146 }
00147 if(mEnableJoystickFlag == false)
00148 {
00149 return;
00150 }
00151
00152 SendWrenchEffort();
00153
00154 SendMicrocontrollerState();
00155 }
00156
00157
00163 void Joystick::ProcessButtonEvent(const unsigned int buttonNumber, const CxUtils::Joystick::Event type)
00164 {
00165 if(mEnableJoystickFlag == false)
00166 {
00167 return;
00168 }
00169 if(type == CxUtils::Joystick::ButtonDown)
00170 {
00171 SignalButtonPress(buttonNumber);
00172 }
00173 else if(type == CxUtils::Joystick::ButtonUp)
00174 {
00175 SignalButtonRelease(buttonNumber);
00176 }
00177 }
00178
00179
00187 void Joystick::CheckServiceStatus(const unsigned int timeSinceLastCheckMs)
00188 {
00189 ControlDevice::CheckServiceStatus(timeSinceLastCheckMs);
00190 if(mEnableJoystickFlag && mJoystick.IsConnected() == false)
00191 {
00192 mJoystick.RegisterCallback(this);
00193 mJoystick.Initialize(mID, mFrequency, mCalibrationFile);
00194 }
00195 }
00196
00197
00198