Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ArActionJoydrive.cpp

00001 /*
00002 ActivMedia Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004,2005 ActivMedia Robotics, LLC
00004 
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 ActivMedia Robotics for information about a commercial version of ARIA at 
00022 robots@activmedia.com or 
00023 ActivMedia Robotics, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
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     // get the readings from the joystick
00156     myJoyHandler->getDoubles(&rot, &trans);
00157     rot *= myTurnAmountMax;
00158     // if we're not using the throttle just mult simply, or if we
00159     // don't know if we have a throttle
00160     if (!myUseThrottle || !myJoyHandler->haveZAxis()) 
00161     {
00162       trans *= myTransVelMax;
00163     }
00164     // if we are using the throttle, interpolate its position between
00165     // low and high throttle values
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     // set what we want to do
00175     myDesired.setVel(trans);
00176     myDesired.setDeltaHeading(-rot);
00177     // return the actionDesired
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 }

Generated on Wed Oct 19 12:56:34 2005 for Aria by  doxygen 1.4.0