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