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

ArActionGroups.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 "ArActionGroup.h"
00030 #include "ArActionGroups.h"
00031 #include "ArActionLimiterTableSensor.h"
00032 #include "ArActionLimiterForwards.h"
00033 #include "ArActionLimiterBackwards.h"
00034 #include "ArActionInput.h"
00035 #include "ArActionStop.h"
00036 #include "ArActionStallRecover.h"
00037 #include "ArActionBumpers.h"
00038 #include "ArActionAvoidFront.h"
00039 #include "ArActionConstantVelocity.h"
00040 #include "ArActionJoydrive.h"
00041 #include "ArActionKeydrive.h"
00042 #include "ArActionDeceleratingLimiter.h"
00043 #include "ArActionRatioInput.h"
00044 #include "ArRatioInputKeydrive.h"
00045 #include "ArRatioInputJoydrive.h"
00046 #include "ArRatioInputRobotJoydrive.h"
00047 
00048 ArActionGroupInput::ArActionGroupInput(ArRobot *robot)
00049   : ArActionGroup(robot)
00050 {
00051   addAction(new ArActionLimiterTableSensor, 100);
00052   addAction(new ArActionLimiterForwards("Speed Limiter Near", 
00053                                                       300, 600, 250),
00054                           90);
00055   addAction(new ArActionLimiterForwards("Speed Limiter Far",
00056                                                       300, 1100, 400),
00057                           89);
00058   addAction(new ArActionLimiterBackwards, 80);
00059   myInput = new ArActionInput;
00060   addAction(myInput, 70);
00061 }
00062 
00063 ArActionGroupInput::~ArActionGroupInput()
00064 {
00065   std::list<ArAction *>::iterator it;
00066   removeActions();
00067   for (it = myActions.begin(); it != myActions.end(); ++it)
00068   {
00069     delete (*it);
00070   }
00071 }
00072 
00073 void ArActionGroupInput::setVel(double vel)
00074 {
00075   myInput->setVel(vel);
00076 }
00077 
00078 void ArActionGroupInput::setRotVel(double rotVel)
00079 {
00080   myInput->setRotVel(rotVel);
00081 }
00082 
00083 void ArActionGroupInput::deltaHeadingFromCurrent(double delta)
00084 {
00085   myInput->deltaHeadingFromCurrent(delta);
00086 }
00087 
00088 void ArActionGroupInput::setHeading(double heading)
00089 {
00090   myInput->setHeading(heading);
00091 }
00092 
00093 void ArActionGroupInput::clear(void)
00094 {
00095   myInput->clear();
00096 }
00097 
00098 ArActionInput *ArActionGroupInput::getActionInput(void)
00099 {
00100   return myInput;
00101 }
00102 
00103 ArActionGroupStop::ArActionGroupStop(ArRobot *robot)
00104   : ArActionGroup(robot)
00105 {
00106   addAction(new ArActionStop, 100);
00107 }
00108 
00109 ArActionGroupStop::~ArActionGroupStop()
00110 {
00111   std::list<ArAction *>::iterator it;
00112   removeActions();
00113   for (it = myActions.begin(); it != myActions.end(); ++it)
00114   {
00115     delete (*it);
00116   }
00117 }
00118 
00119 
00120 ArActionGroupTeleop::ArActionGroupTeleop(ArRobot *robot)
00121   : ArActionGroup(robot)
00122 {
00123   addAction(new ArActionLimiterTableSensor, 100);
00124   addAction(new ArActionLimiterForwards("Speed Limiter Near", 
00125                                                       300, 600, 250),
00126                           90);
00127   addAction(new ArActionLimiterForwards("Speed Limiter Far",
00128                                                       300, 1100, 400),
00129                           89);
00130   addAction(new ArActionLimiterBackwards, 80);
00131   myJoydrive = new ArActionJoydrive;
00132   myJoydrive->setStopIfNoButtonPressed(false);
00133   addAction(myJoydrive, 70);
00134   addAction(new ArActionKeydrive, 69);
00135 }
00136 
00137 ArActionGroupTeleop::~ArActionGroupTeleop()
00138 {
00139   std::list<ArAction *>::iterator it;
00140   removeActions();
00141   for (it = myActions.begin(); it != myActions.end(); ++it)
00142   {
00143     delete (*it);
00144   }
00145 }
00146 
00147 void ArActionGroupTeleop::setThrottleParams(int lowSpeed, 
00148                                                      int highSpeed)
00149 {
00150   myJoydrive->setThrottleParams(lowSpeed, highSpeed);
00151 }
00152 
00153 ArActionGroupUnguardedTeleop::ArActionGroupUnguardedTeleop(ArRobot *robot)
00154   : ArActionGroup(robot)
00155 {
00156   myJoydrive = new ArActionJoydrive;
00157   myJoydrive->setStopIfNoButtonPressed(false);
00158   addAction(myJoydrive, 70);
00159   addAction(new ArActionKeydrive, 69);
00160 }
00161 
00162 ArActionGroupUnguardedTeleop::~ArActionGroupUnguardedTeleop()
00163 {
00164   std::list<ArAction *>::iterator it;
00165   removeActions();
00166   for (it = myActions.begin(); it != myActions.end(); ++it)
00167   {
00168     delete (*it);
00169   }
00170 }
00171 
00172 void ArActionGroupUnguardedTeleop::setThrottleParams(int lowSpeed, 
00173                                                          int highSpeed)
00174 {
00175   myJoydrive->setThrottleParams(lowSpeed, highSpeed);
00176 }
00177 
00178 ArActionGroupWander::ArActionGroupWander(ArRobot *robot, int forwardVel, int avoidFrontDist, int avoidVel, int avoidTurnAmt)
00179   : ArActionGroup(robot)
00180 {
00181   addAction(new ArActionBumpers, 100);
00182   addAction(new ArActionStallRecover, 90);
00183   //addAction(new ArActionAvoidFront("Avoid Front Near", 250, 0), 80);
00184   addAction(new ArActionAvoidFront("Avoid Front", avoidFrontDist, avoidVel, avoidTurnAmt), 79);
00185   addAction(new ArActionConstantVelocity("Constant Velocity",
00186                                          forwardVel),
00187                                          50);
00188 
00189 }
00190 
00191 ArActionGroupWander::~ArActionGroupWander()
00192 {
00193   std::list<ArAction *>::iterator it;
00194   removeActions();
00195   for (it = myActions.begin(); it != myActions.end(); ++it)
00196   {
00197     delete (*it);
00198   }
00199 }
00200 
00201 // The color follow action group
00202 ArActionGroupColorFollow::ArActionGroupColorFollow(ArRobot *robot, ArACTS_1_2 *acts, ArPTZ *camera)
00203   : ArActionGroup(robot)
00204 {
00205   // Add the limiters so the robot is less likely to run into things
00206   addAction(new ArActionLimiterTableSensor, 100);
00207   addAction(new ArActionLimiterForwards("Speed Limiter Near", 
00208                                                       300, 600, 250),
00209                           90);
00210   addAction(new ArActionLimiterForwards("Speed Limiter Far",
00211                                                       300, 1100, 400),
00212                           89);
00213   addAction(new ArActionLimiterBackwards, 80);
00214 
00215   // Construct the color follower and add it
00216   myColorFollow = new ArActionColorFollow("Follow a color.", acts, camera);
00217   addAction(myColorFollow, 70);
00218 }
00219 
00220 // Destructor
00221 ArActionGroupColorFollow::~ArActionGroupColorFollow()
00222 {
00223   std::list<ArAction *>::iterator it;
00224   removeActions();
00225   for (it = myActions.begin(); it != myActions.end(); ++it)
00226   {
00227     delete (*it);
00228   }
00229 }
00230 
00231 // Set the channel to get blob info from
00232 void ArActionGroupColorFollow::setChannel(int channel)
00233 {
00234   myColorFollow->setChannel(channel);
00235 }
00236 
00237 // Set the camera to control
00238 void ArActionGroupColorFollow::setCamera(ArPTZ *camera)
00239 {
00240   myColorFollow->setCamera(camera);
00241 }
00242 
00243 // Allow the robot to move
00244 void ArActionGroupColorFollow::startMovement()
00245 {
00246   myColorFollow->startMovement();
00247 }
00248 
00249 // Keep the robot from moving
00250 void ArActionGroupColorFollow::stopMovement()
00251 {
00252   myColorFollow->stopMovement();
00253 }
00254 
00255 // Toggle whether or not the robot will try to actively
00256 // acquire a color blob
00257 void ArActionGroupColorFollow::setAcquire(bool acquire)
00258 {
00259   myColorFollow->setAcquire(acquire);
00260 }
00261 
00262 // Return the channel that the robot is looking on
00263 int ArActionGroupColorFollow::getChannel()
00264 {
00265   return myColorFollow->getChannel();
00266 }
00267 
00268 // Return whether the robot is allowed to actively
00269 // acquire a color blob
00270 bool ArActionGroupColorFollow::getAcquire()
00271 {
00272   return myColorFollow->getAcquire();
00273 }
00274 
00275 // Return whether the robot is allowed to move
00276 bool ArActionGroupColorFollow::getMovement()
00277 {
00278   return myColorFollow->getMovement();
00279 }
00280 
00281 // Return if the robot is targeting a color blob
00282 bool ArActionGroupColorFollow::getBlob()
00283 {
00284   return myColorFollow->getBlob();
00285 }
00286 
00287 ArActionGroupRatioDrive::ArActionGroupRatioDrive(ArRobot *robot)
00288   : ArActionGroup(robot)
00289 {
00290   // add the actions, put the ratio input on top, then have the
00291   // limiters since the ratio doesn't touch decel except lightly
00292   // whereas the limiter will touch it strongly
00293 
00294   myInput = new ArActionRatioInput;
00295   addAction(myInput, 50); 
00296 
00297   myKeydrive = new ArRatioInputKeydrive(robot, myInput);
00298   myJoydrive = new ArRatioInputJoydrive(robot, myInput);
00299   myRobotJoydrive = new ArRatioInputRobotJoydrive(robot, myInput);
00300 
00301   myDeceleratingLimiterForward = new ArActionDeceleratingLimiter(
00302           "DeceleratingLimiterForward", true);
00303   addAction(myDeceleratingLimiterForward, 40);
00304 
00305   myDeceleratingLimiterBackward = new ArActionDeceleratingLimiter(
00306           "DeceleratingLimiterBackward", false);
00307   addAction(myDeceleratingLimiterBackward, 39);
00308 
00309 
00310 }
00311 
00312 ArActionGroupRatioDrive::~ArActionGroupRatioDrive()
00313 {
00314   std::list<ArAction *>::iterator it;
00315   removeActions();
00316   for (it = myActions.begin(); it != myActions.end(); ++it)
00317   {
00318     delete (*it);
00319   }
00320 }
00321 
00322 
00323 ArActionRatioInput *ArActionGroupRatioDrive::getActionRatioInput(void)
00324 {
00325   return myInput;
00326 }
00327 
00328 void ArActionGroupRatioDrive::addToConfig(ArConfig *config, 
00329                                                  const char *section)
00330 {
00331   myInput->addToConfig(config, section);
00332   myDeceleratingLimiterForward->addToConfig(config, section, "Forward");
00333   myDeceleratingLimiterBackward->addToConfig(config, section, "Backward");
00334 }
00335 
00336 ArActionGroupRatioDriveUnsafe::ArActionGroupRatioDriveUnsafe(ArRobot *robot)
00337   : ArActionGroup(robot)
00338 {
00339   // add the actions, put the ratio input on top, then have the
00340   // limiters since the ratio doesn't touch decel except lightly
00341   // whereas the limiter will touch it strongly
00342 
00343   myInput = new ArActionRatioInput;
00344   addAction(myInput, 50); 
00345 
00346   myKeydrive = new ArRatioInputKeydrive(robot, myInput);
00347   myJoydrive = new ArRatioInputJoydrive(robot, myInput);
00348   myRobotJoydrive = new ArRatioInputRobotJoydrive(robot, myInput);
00349 }
00350 
00351 ArActionGroupRatioDriveUnsafe::~ArActionGroupRatioDriveUnsafe()
00352 {
00353   std::list<ArAction *>::iterator it;
00354   removeActions();
00355   for (it = myActions.begin(); it != myActions.end(); ++it)
00356   {
00357     delete (*it);
00358   }
00359 }
00360 
00361 
00362 ArActionRatioInput *ArActionGroupRatioDriveUnsafe::getActionRatioInput(void)
00363 {
00364   return myInput;
00365 }
00366 
00367 void ArActionGroupRatioDriveUnsafe::addToConfig(ArConfig *config, 
00368                                                  const char *section)
00369 {
00370   myInput->addToConfig(config, section);
00371 }

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