Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

WheeledWalkMC.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_WheeledWalkMC_h_
00003 #define INCLUDED_WheeledWalkMC_h_
00004 
00005 #include "Motion/MotionCommand.h"
00006 #include "Motion/MotionManager.h"
00007 #include "Shared/get_time.h"
00008 #include "Shared/Measures.h"
00009 #include "Shared/RobotInfo.h"
00010 #include "Shared/plist.h"
00011 
00012 //! Provides a 'WalkMC' implementation for wheeled robots (diff-drive or theoretically holonomic configurations as well)
00013 /*! Uses kinematic description to determine location and orientation of wheels
00014  *  and computes appropriate wheel velocities to produce a target motion.
00015  *  Can handle skid-steer (diff drive) type motion, including holonomic wheels,
00016  *  but does not handle ackerman style (steered) configurations.
00017  *  
00018  *  Also does not handle 'slanted' wheels optimally: Assumes wheels are perpendicular
00019  *  to the ground, that the base frame Z axis is perpendicular to the ground frame.
00020  *  This could be added with a bit more math when computing wheel positions.
00021  *
00022  *  This motion command also assumes that wheels are commanded by mm/sec ground
00023  *  speed, not rad/sec rotational speed.
00024  *
00025  *  For simulation in Mirage, make sure all wheels are marked by adding a Velocity=true
00026  *  entry in the ControllerInfo of the corresponding kinematics configuration, and that
00027  *  the x and y dimensions of the collision model are set for the wheel radius.
00028  *
00029  *  TODO: Test on a holonomic platform, should handle it, but originally only
00030  *  tested on diff-drive like Create.  Also, perhaps add config settings to override #rotationCenter and
00031  *  a flag to have updateWheelConfig called before each updateOutputs. */
00032 class WheeledWalkMC : public MotionCommand, public virtual plist::Dictionary {
00033 public:
00034   //! constructor
00035   WheeledWalkMC() :
00036     plist::Dictionary(), MotionCommand(),
00037 #if defined(TGT_IS_KOBUKI) || defined(TGT_IS_CREATE2)
00038     lastTickLeft(state->sensors[LeftEncoderOffset]),
00039     lastTickRight(state->sensors[RightEncoderOffset]),
00040     lastDistTraveled(0), lastAngTraveled(0),
00041 #endif
00042     preferredXVel(), preferredYVel(), preferredAngVel(), 
00043     targetVel(), targetAngVel(0), targetDur(0), targetDist(0), targetAngDist(0),
00044     maxVel(), maxAngVel(0), rotationCenter(), displacementMode(false),
00045     travelStartTime(0), travelStartDist(0), travelStartAngle(0),
00046     dirty(false)
00047   {
00048     addEntry("PreferredXVel",preferredXVel,"optimal X velocity for unspecified displacements (mm/s)");
00049     addEntry("PreferredYVel",preferredYVel,"optimal Y velocity for unspecified displacements (mm/s)");
00050     addEntry("PreferredAngVel",preferredAngVel,"optimal angular velocity for unspecified displacements (rad/s)");
00051     setLoadSavePolicy(FIXED,SYNC);
00052     resetConfig();
00053   }
00054   
00055   void resetConfig(); //!< reset and reload configuration settings, implies call to updateWheelConfig()
00056 
00057   void setDirty() { dirty = true; }
00058 
00059   virtual int updateOutputs();
00060   virtual int isDirty() { return dirty; }
00061   virtual int isAlive();
00062   virtual void start();
00063   virtual void stop();
00064   
00065   //!  Posts a LocomotionEvent and sets velocities to zero. Also forces an output frame setting wheel velocities to zero; needed because if we remove a motion command there may be nothing left to zero the velocities.
00066   virtual void zeroVelocities();
00067   
00068   float getMaxXVel() const { return maxVel[0]; }
00069   float getMaxYVel() const { return maxVel[1]; }
00070   float getMaxAVel() const { return maxAngVel; }
00071   
00072   unsigned int getTravelTime() { return get_time()-travelStartTime; } //!< the amount of time (ms) we have been travelling the current vector
00073   
00074   //! Returns the current x and y velocities in mm/sec
00075   const fmat::Column<2>& getTargetVelocity() const { return targetVel; };
00076   
00077   //! Returns the current angular velocity in radians/sec
00078   float getTargetAngVelocity() const { return targetAngVel; }
00079   
00080   //! Specify the desired body velocity in x and y (millimeters per second) and angular velocity (radians per second)
00081   virtual void getTargetVelocity(float &xvel, float &yvel, float &avel) {
00082     xvel = targetVel[0];
00083     yvel = targetVel[1];
00084     avel = targetAngVel;
00085   }
00086   
00087   //! Specify the desired body velocity in x and y (millimeters per second) and angular velocity (radians per second); does not stop automatically
00088   virtual void setTargetVelocity(float xvel, float yvel, float avel);
00089   
00090   //! Specify the desired body velocity in x and y (millimeters per second) and angular velocity (radians per second), and amount of time before stopping
00091   virtual void setTargetVelocity(float xvel, float yvel, float avel, float time);
00092   
00093   //! Specify the desired body displacement in x and y (millimeters) and a (radians)
00094   /*! Corresponding velocity will be limited to max velocity, so setting time=0 implies max speed */
00095   virtual void setTargetDisplacement(float xdisp, float ydisp, float adisp, float time=0);
00096   
00097   //! Specify body displacement and speed
00098   void setTargetDisplacement(float xdisp, float ydisp, float adisp, float xvel, float yvel, float avel);
00099 
00100   //! Recomputes wheel positions and orientations.  Automatically called by constructor, but may need to recall if wheel positions are actuated.
00101   /*! Includes a call to updateWheelVels() in case wheel positions change. */
00102   virtual void updateWheelConfig();
00103 #if defined(TGT_IS_KOBUKI) || defined(TGT_IS_CREATE2)
00104   unsigned short lastTickLeft;
00105   unsigned short lastTickRight;
00106   float lastDistTraveled;
00107   float lastAngTraveled;
00108 #endif
00109   plist::Primitive<float> preferredXVel; //!< optimal X velocity for unspecified displacements
00110   plist::Primitive<float> preferredYVel; //!< optimal Y velocity for unspecified displacements
00111   plist::Primitive<float> preferredAngVel; //!< optimal angular velocity for unspecified displacements
00112   
00113 protected:
00114   void updateWheelVels(); //!< updates WheelInfo::targetVel values based on #targetVel and #targetAngVel
00115   
00116   fmat::Column<2> targetVel; //!< the requested xy velocity of the body (ignoring parameterized body motion, like sway or surge), millimeters per second
00117   float targetAngVel; //!< the requested angular velocity of the body, radians per second
00118   unsigned int targetDur; //!< duration in msecs for the current displacement
00119   float targetDist; //!< forward distance we want to travel
00120   float targetAngDist; //!< angular distance we want to travel
00121   fmat::Column<2> maxVel; //!< maximum velocity in x,y
00122   float maxAngVel; //!< maximum angular velocity
00123   
00124   fmat::Column<2> rotationCenter; //!< point to use as center of rotations, defaults to center of wheels
00125   bool displacementMode; //!< If true, velocity will be set to 0 when desired displacement is achieved
00126   unsigned int travelStartTime; //!< the time of the last call to setTargetVelocity - handy to check the time we've been traveling current vector
00127   float travelStartDist; //!< The forward odometry reading in millimeters at the time of the last call to setTargetVelocity
00128   float travelStartAngle; //!< The angular odometry reading in radians at the time of the last call to setTargetVelocity
00129   bool dirty; //!< set to true by updateWheelVels(), cleared up updateOutputs()
00130   
00131   static constexpr float EPSILON = 1e-4f;
00132 
00133   //! stores information about the configuration and current target state of each wheel
00134   struct WheelInfo {
00135     WheelInfo() : valid(false), position(), direction(), targetVel(0) {}
00136     bool valid; //!< set to false if the wheel axle is vertical
00137     fmat::Column<2> position; //!< the center of the wheel's contact
00138     fmat::Column<2> direction; //!< the direction of forward motion produced by this wheel
00139     float targetVel; //!< the current wheel velocity to supply to motman via updateOutputs, is calculated by setTargetVelocity()
00140   };
00141   WheelInfo wheels[NumWheels];
00142 };
00143 
00144 /*! @file
00145  * @brief Defines WheeledWalkMC, which provides a 'WalkMC' implementation for wheeled robots (diff-drive or theoretically holonomic configurations as well)
00146  * @author Ethan Tira-Thompson (ejt) (Creator)
00147  */
00148 
00149 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:52 2016 by Doxygen 1.6.3