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 #include "ArExport.h"
00028 #include "ariaOSDef.h"
00029 #include "ArActionJoydrive.h"
00030 #include "ArRobot.h"
00031 #include "ariaInternal.h"
00032
00059 ArActionJoydrive::ArActionJoydrive(const char *name,
00060 double transVelMax,
00061 double turnAmountMax,
00062 bool stopIfNoButtonPressed,
00063 bool useOSCalForJoystick) :
00064 ArAction(name, "This action reads the joystick and sets the translational and rotational velocities based on this.")
00065 {
00066 if ((myJoyHandler = Aria::getJoyHandler()) == NULL)
00067 {
00068 myJoyHandler = new ArJoyHandler;
00069 myJoyHandler->init();
00070 Aria::setJoyHandler(myJoyHandler);
00071 }
00072
00073 setSpeeds(transVelMax, turnAmountMax);
00074
00075 setNextArgument(ArArg("trans vel max", &myTransVelMax, "The full speed to go when the joystick is maxed forwards/backwards (mm/sec)"));
00076
00077 setNextArgument(ArArg("turn amount max", &myTurnAmountMax, "The full amount to turn if the joystick is pushed all the way right/left (deg)"));
00078
00079 setNextArgument(ArArg("stop if no button pressed", &myStopIfNoButtonPressed, "If this is true, then joydrive will stop the robot if there is no button pressed, otherwise it will just let whatever lower priority things go."));
00080 myStopIfNoButtonPressed = stopIfNoButtonPressed;
00081
00082 setNextArgument(ArArg("use os calibration for joystick", &myUseOSCal, "If this is true then the os calibration for the joystick will be used, otherwise autocalibration will be used."));
00083 myUseOSCal = useOSCalForJoystick;
00084 myPreviousUseOSCal = myUseOSCal;
00085
00086 myUseThrottle = false;
00087 }
00088
00089 ArActionJoydrive::~ArActionJoydrive()
00090 {
00091
00092 }
00093
00094 void ArActionJoydrive::setStopIfNoButtonPressed(
00095 bool stopIfNoButtonPressed)
00096 {
00097 myStopIfNoButtonPressed = stopIfNoButtonPressed;
00098 }
00099
00100 bool ArActionJoydrive::getStopIfNoButtonPressed(void)
00101 {
00102 return myStopIfNoButtonPressed;
00103 }
00104
00105 bool ArActionJoydrive::joystickInited(void)
00106 {
00107 return myJoyHandler->haveJoystick();
00108 }
00109
00113 void ArActionJoydrive::setUseOSCal(bool useOSCal)
00114 {
00115 myUseOSCal = useOSCal;
00116 myPreviousUseOSCal = useOSCal;
00117 myJoyHandler->setUseOSCal(useOSCal);
00118 }
00119
00123 bool ArActionJoydrive::getUseOSCal(void)
00124 {
00125 return myUseOSCal;
00126 }
00127
00128 void ArActionJoydrive::setSpeeds(double transVelMax,
00129 double turnAmountMax)
00130 {
00131 myTransVelMax = transVelMax;
00132 myTurnAmountMax = turnAmountMax;
00133 }
00134
00135 void ArActionJoydrive::setThrottleParams(double lowSpeed, double highSpeed)
00136 {
00137 myUseThrottle = true;
00138 myLowThrottle = lowSpeed;
00139 myHighThrottle = highSpeed;
00140 }
00141
00142 ArActionDesired *ArActionJoydrive::fire(ArActionDesired currentDesired)
00143 {
00144 double rot, trans, throttle;
00145
00146 myDesired.reset();
00147 if (myPreviousUseOSCal != myUseOSCal)
00148 {
00149 myJoyHandler->setUseOSCal(myUseOSCal);
00150 myPreviousUseOSCal = myUseOSCal;
00151 }
00152
00153 if (myJoyHandler->haveJoystick() && myJoyHandler->getButton(1))
00154 {
00155
00156 myJoyHandler->getDoubles(&rot, &trans);
00157 rot *= myTurnAmountMax;
00158
00159
00160 if (!myUseThrottle || !myJoyHandler->haveZAxis())
00161 {
00162 trans *= myTransVelMax;
00163 }
00164
00165
00166 else
00167 {
00168 throttle = myJoyHandler->getAxis(3);
00169 throttle += 1.0;
00170 throttle /= 2.0;
00171 trans = trans * (myLowThrottle +
00172 (throttle * (myHighThrottle - myLowThrottle)));
00173 }
00174
00175 myDesired.setVel(trans);
00176 myDesired.setDeltaHeading(-rot);
00177
00178 return &myDesired;
00179 }
00180 else if (myJoyHandler->haveJoystick() && myStopIfNoButtonPressed)
00181 {
00182 myDesired.setVel(0);
00183 myDesired.setDeltaHeading(0);
00184 return &myDesired;
00185 }
00186
00187 return NULL;
00188 }