Joystick.h
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
00029
00030
00034
00035
00036
00037
00038
00039
00040 #ifndef __JOYSTICK_H_
00041 #define __JOYSTICK_H_
00042
00043 #include <Task.h>
00044 #include <MobileRob.h>
00045 #include <MobileRob3D.h>
00046
00047 #include <Keyboard.h>
00048 #ifndef MIP_PLATFORM_ARM
00049 #include <DraWin.h>
00050 #include <RemoteDevice.h>
00051 #endif
00052 #include <string.h>
00053 #include <CommonOptions.h>
00054 #include <SharedMem.h>
00055 #include <FirFilter.h>
00056
00057
00058 #define JVERBOSE 0
00059
00060
00061 #define JOYSTICK_LINVEL_STEP 0.005
00062
00063 #define JOYSTICK_ANGVEL_STEP 0.05
00064
00065 using namespace MipResources;
00066
00067 namespace MipTasks{
00068
00070
00071
00075 class JoystickOptions : public Options {
00076 public:
00077 IntOption *cmdType;
00078 DecimalOption *speedFilterLag;
00079 PositionOption *boundBoxCenter;
00080 DecimalOption *boundBoxRadius;
00081
00082 JoystickOptions();
00083
00084 OptionGroupsType getGroup();
00085 string getObjectName() const {
00086 return "JoystickOptions";
00087 }
00088 };
00089
00090
00094 class JoystickSharedMem : public SharedMem{
00095 public:
00097 void initSharedMem(){
00098 }
00099
00101 void togglePrintPose(){
00102 _printPose = !_printPose;
00103 }
00105 void togglePrintScan(){
00106 _printScan = !_printScan;
00107 }
00109 void togglePrintFeat(){
00110 _printFeat = !_printFeat;
00111 }
00113 void togglePrintFormation(){
00114 _printFormation = !_printFormation;
00115 }
00117 void togglePrintFormationDetails(){
00118 _printFormationDetails = !_printFormationDetails;
00119 }
00121 void togglePrintTarget(){
00122 _printTarget = !_printTarget;
00123 }
00125 void toggleDoMloc(){
00126 _doMloc = !_doMloc;
00127 }
00129 void toggleDoAutoNavigation(){
00130 _doAutoNavigation = !_doAutoNavigation;
00131 }
00132
00133
00134
00135 bool printPose(){
00136 return _printPose;
00137 }
00138 bool printScan(){
00139 return _printScan;
00140 }
00141 bool doMloc(){
00142 return _doMloc;
00143 }
00144 bool doAutoNavigation(){
00145 return _doAutoNavigation;
00146 }
00147
00148 };
00149
00150
00154 class Joystick : public Task{
00155
00156 private:
00157 static const TaskPlate _plate = JOY_TASK;
00158 static const long int _maxDurSec = 0, _maxDurUsec = 150000;
00159 static const long int _maxSamplPeriodSec = 0, _maxSamplPeriodUsec = 500000;
00160 static const long int _minSamplPeriodSec = 0, _minSamplPeriodUsec = 50000;
00161
00162 Keyboard* _keyboard;
00163 MobileRob* _mobileRob;
00164 MobileRob3D* _mobileRob3D;
00165 MotionModule* _motionModule;
00166 JoystickSharedMem* _sharedMem;
00167 #ifndef MIP_PLATFORM_ARM
00168 RemoteDevice* _remoteInputDevice;
00169 #endif
00170 JoystickOptions _options;
00171
00172
00173 bool useMobileRob;
00174 bool useMotionModule;
00175 bool useMobileRob3D;
00176 bool useRemoteInputDevice;
00177
00178 Decimal _linRangeMax;
00179
00180
00181
00182 fstream _saveTState;
00183 fstream _saveTStateTime;
00184
00185 #ifndef MIP_PLATFORM_ARM
00186 DraWin* _draWin;
00187 unsigned int _drawList;
00188 bool dwOn;
00189 #endif
00190
00191 bool rangeSensOn;
00192 bool rangeSensPrint;
00193
00194 Scan scan;
00195 Ray ray;
00196
00197 bool _useSpeedFilter;
00198 Decimal _speedFilterLag;
00199 FirFilter* _linVelFilter;
00200 FirFilter* _angVelFilter;
00201
00202 Decimal _drive,_turnrate;
00203
00204 Decimal _bbRadius;
00205 Position _bbCenter;
00206
00208 bool _driveUnicycle(char command,Decimal& drive,Decimal& turnrate);
00210 void _driveRangeSensor(char command,MobileRob *mobileRob);
00212 void _driveFuntionalities(char command);
00213
00214 public:
00216 Joystick(ResourcePointers resources,int argc, const char* argv[]);
00217
00219 ~Joystick(){
00220 cout << "destr JoystickTask" << endl;
00221 }
00222
00224 TaskPlate getPlate() const {
00225 return _plate;
00226 }
00228 Time getMaxDuration(){
00229 return Time(_maxDurSec,_maxDurUsec);
00230 }
00232 Time getMaxSamplPeriod(){
00233 return Time(_maxSamplPeriodSec,_maxSamplPeriodUsec);
00234 }
00236 Time getMinSamplPeriod(){
00237 return Time(_minSamplPeriodSec,_minSamplPeriodUsec);
00238 }
00239
00240 void draw();
00241
00242 void writeSharedMem();
00243
00245 TaskOutputs run();
00246 };
00247
00248
00249
00250 };
00251
00252 #endif
00253
00254
00255
00256
00257