Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

WalkNode.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_WalkNode_h_
00003 #define INCLUDED_WalkNode_h_
00004 
00005 #include <iostream>
00006 
00007 #include "Events/LocomotionEvent.h"
00008 #include "Motion/WalkMC.h"
00009 #include "Behaviors/Nodes/MCNode.h"
00010 #include "Shared/attributes.h"
00011 
00012 extern const char defWalkNodeName[];
00013 extern const char defWalkNodeDesc[];
00014 
00015 //! A request to walk at a specified velocity or for a specific distance, to be used in a SignalTrans
00016 /*! Recommended usage is via the velocity() and displacement() generators */
00017 class WalkRequest {
00018 public:
00019   //! Constructor
00020   WalkRequest() : x(0), y(0), a(0), time(-1), velocityMode(true), storedVelocities(false), filename() {}
00021   
00022   //! Constructor
00023   WalkRequest(const std::string& paramFile) : x(0), y(0), a(0), time(-1), velocityMode(true), storedVelocities(false), filename(paramFile) {}
00024   
00025   //! Constructor: velocities in mm/sec and radians/sec
00026   WalkRequest(float xvel, float  yvel, float avel, const std::string& paramFile="") :
00027   x(xvel), y(yvel), a(avel), time(-1), velocityMode(true), storedVelocities(true), filename(paramFile) {}
00028   
00029   //! Constructor
00030   /*! @param x_ if @a isVelocity, the speed (mm/s) to move forward, else the distance (mm)
00031    *  @param y_ if @a isVelocity, the speed (mm/s) to move to the left, else the distance (mm)
00032    *  @param a_ if @a isVelocity, the speed (radians/s) to rotate to the left, else the distance (radians)
00033    *  @param time_ the duration of the walk (seconds), if isVelocity is false the velocity will still be subject to the walk's calculated limits, so just pass 0 for max speed
00034    *  @param isVelocity controls interpretation of @a x, @a y, and @a a
00035    *  @param paramFile loads a parameter file to control walk gait */
00036   WalkRequest(float x_, float y_, float a_, float time_, bool isVelocity, const std::string& paramFile="") :
00037   x(x_), y(y_), a(a_), time(time_), velocityMode(isVelocity), storedVelocities(true), filename(paramFile) {}
00038   
00039   //! Generator to call the constructor with appropriate arguments, a little more concise/readable than using the constructor directly
00040   /*! @param x the speed (mm/s) to move forward
00041    *  @param y the speed (mm/s) to move to the left
00042    *  @param a the speed (radians/s) to rotate to the left
00043    *  @param time the duration of the walk (seconds)
00044    *  @param paramFile loads a parameter file to control walk gait */
00045   static WalkRequest velocity(float x, float y, float a, float time=-1, const std::string& paramFile="") { return WalkRequest(x, y, a, time, true, paramFile); }
00046   
00047   //! Generator to call the constructor with appropriate arguments, a little more concise/readable than using the constructor directly
00048   /*! @param x the distance (mm) to move forward
00049    *  @param y the distance (mm) to move to the left
00050    *  @param a the distance (radians) to rotate to the left
00051    *  @param time the duration of the walk (seconds), the velocity will still be subject to the walk's calculated limits, so just pass 0 for max speed
00052    *  @param paramFile loads a parameter file to control walk gait */
00053   static WalkRequest displacement(float x, float y, float a, float time=0, const std::string& paramFile="") { return WalkRequest(x, y, a, time, false, paramFile); }
00054   
00055   float x, y, a, time;
00056   bool velocityMode,  storedVelocities;
00057   std::string filename;
00058   
00059 public:
00060   bool operator==(const WalkRequest& other) const;
00061 };
00062 
00063 std::ostream& operator<<(std::ostream &os, const WalkRequest &req);
00064 
00065 //! A StateNode for walking using WalkMC
00066 /*! The WalkNode can handle either velocities or displacements.
00067  *
00068  *  To specify a velocity with no end, use the 3-tuple constructor:
00069  *  @code
00070  *  WalkNode(vx,vy,va)
00071  *  @endcode
00072  *
00073  *  To specify a velocity for a specific amount of time, which will then trigger a completion event:
00074  *  @code
00075  *  WalkNode(vx,vy,va, time, WalkNode::VEL) 
00076  *  @endcode
00077  *  (You could also use the "endless" velocity constructor with a TimeOutTrans)
00078  *
00079  *  To have WalkNode interpret the (x,y,a) as a distance to travel instead of velocity, pass false at the end instead:
00080  *  @code
00081  *  WalkNode(dx,dy,da, time, WalkNode::DISP)
00082  *  @endcode
00083  *  The time will be subject to speed limits of the underlying WalkMC, so it may take more time to complete.
00084  *  In particular, this means you can simply pass time=0 for a displacement and this will be extended to the maximum speed:
00085  *  @code
00086  *  WalkNode(dx,dy,da, 0, WalkNode::DISP); // zero time implies max speed for displacements
00087  *  @endcode
00088  */
00089 class WalkNode : public MCNode<WalkMC,defWalkNodeName,defWalkNodeDesc> {
00090 public:
00091   enum Mode_t {
00092     DISP=0, //!< use with constructors to indicate displacement mode
00093     VEL=1 //!< use with constructors to indicate velocity mode
00094   };
00095   
00096   //! constructor
00097   WalkNode() : MCNode<WalkMC,defWalkNodeName,defWalkNodeDesc>(), req() {}
00098   
00099   //! constructor
00100   WalkNode(const std::string& name, const std::string filename="") :
00101   MCNode<WalkMC,defWalkNodeName,defWalkNodeDesc>(name), req(filename) {}
00102   
00103   //!constructor: velocities in mm/sec and radians/sec
00104   WalkNode(float xvel, float yvel, float avel, const std::string filename="") : 
00105   MCNode<WalkMC,defWalkNodeName,defWalkNodeDesc>(), req(xvel,yvel,avel,filename) {}
00106   
00107   //!constructor: velocities in mm/sec and radians/sec
00108   WalkNode(const std::string& name, float xvel, float yvel, float avel, const std::string filename="") :
00109   MCNode<WalkMC,defWalkNodeName,defWalkNodeDesc>(name), req(xvel,yvel,avel,filename) {}
00110   
00111   //!constructor: displacements in mm and radians, time parameter in seconds but will be extended to fit within max speed
00112   /*! @param x if @a velocityMode is VEL, the speed (mm/s) to move forward, else the distance (mm)
00113    *  @param y if @a velocityMode is VEL, the speed (mm/s) to move to the left, else the distance (mm)
00114    *  @param a if @a velocityMode is VEL, the speed (radians/s) to rotate to the left, else the distance (radians)
00115    *  @param time the duration of the walk (seconds), if isVelocity is false the velocity will still be subject to the walk's calculated limits, so just pass 0 for max speed
00116    *  @param velocityMode controls interpretation of @a x, @a y, and @a a
00117    *  @param filename loads a parameter file to control walk gait */
00118   WalkNode(float x, float y, float a, float time, Mode_t velocityMode, const std::string filename="") : 
00119   MCNode<WalkMC,defWalkNodeName,defWalkNodeDesc>(), req(x,y,a,time,velocityMode,filename) {}
00120   
00121   //!constructor: pass displacement as velocity or distance and time, isVelocity controls interpretation of x, y, and a
00122   /*! @param name an instance name for the node (mostly useful for debugging)
00123    *  @param x if @a velocityMode is VEL, the speed (mm/s) to move forward, else the distance (mm)
00124    *  @param y if @a velocityMode is VEL, the speed (mm/s) to move to the left, else the distance (mm)
00125    *  @param a if @a velocityMode is VEL, the speed (radians/s) to rotate to the left, else the distance (radians)
00126    *  @param time the duration of the walk (seconds), if velocityMode is DISP the velocity will still be subject to the walk's calculated limits, so just pass 0 for max speed
00127    *  @param velocityMode controls interpretation of @a x, @a y, and @a a
00128    *  @param filename loads a parameter file to control walk gait */
00129   WalkNode(const std::string& name, float x, float y, float a, float time, Mode_t velocityMode, const std::string filename="") :
00130   MCNode<WalkMC,defWalkNodeName,defWalkNodeDesc>(name), req(x,y,a,time,velocityMode,filename) {}
00131   
00132   //! sets the velocity of the walk
00133   /*! @param xdist x displacement (mm, positive is forward)
00134    *  @param ydist y displacement (mm, positive is left)
00135    *  @param adist angular displacement (rad, positive is counter-clockwise)
00136    *  @param time how many seconds to take to achieve displacement (limited to walk's max speed, so time=0 implies max speed) */
00137   void setDisplacement(float xdist, float ydist, float adist, float time=0);
00138   
00139   //! sets the velocity of the walk
00140   /*! @param xvel x velocity (mm/s, positive is forward)
00141    *  @param yvel y velocity (mm/s, positive is left)
00142    *  @param avel angular velocity (rad/s, positive is counter-clockwise) */
00143   void setVelocity(float xvel, float yvel, float avel);
00144   
00145   //! sets the velocity of the walk
00146   /*! @param xvel x velocity (mm/s, positive is forward)
00147    *  @param yvel y velocity (mm/s, positive is left)
00148    *  @param avel angular velocity (rad/s, positive is counter-clockwise)
00149    *  @param time is seconds until stopping and posting completion */
00150   void setVelocity(float xvel, float yvel, float avel, float time);
00151   
00152   virtual void stop();
00153   
00154 protected:
00155   virtual void preStart();
00156   virtual void postStart();
00157   
00158   WalkRequest req; //!< stores settings from constructor or a signal transition
00159   
00160 };
00161 
00162 #endif

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