Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

GaitedFootstepMC.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_GaitedFootstepMC_h_
00003 #define INCLUDED_GaitedFootstepMC_h_
00004 
00005 #include "Motion/MotionCommand.h"
00006 #include "Motion/MotionManager.h"
00007 #include "Motion/XWalkMC.h"
00008 #include "Planners/GaitedFootsteps.h"
00009 #include "Shared/get_time.h"
00010 
00011 //! Executes a series of footsteps, probably generated by applying astar() to a GaitedFootsteps domain
00012 class GaitedFootstepMC : public MotionCommand {
00013 public:
00014   //! Constructor
00015   GaitedFootstepMC()
00016     : MotionCommand(), xp(), ground(), gravity(), steps(), curStep(0),
00017     xySpeed(fmat::pack(30,30)), aSpeed(0.2f), newStep(false), stepStartTime(0), stepDuration(0), contactMsg()
00018   {
00019     setGait(::config->motion.makePath("xwalk.plist"), true);
00020     if(kine==NULL) {
00021       kine = new KinematicJoint;
00022       kine->loadFile(::config->makePath(config->motion.kinematics).c_str());
00023       kine->buildChildMap(childMap,0,NumReferenceFrames);
00024     }
00025   }
00026   
00027   virtual int updateOutputs();
00028   virtual int isDirty() { return curStep+1 < steps.size(); }
00029   virtual int isAlive() { return curStep+1 < steps.size(); }
00030   
00031   //! Assign gait settings
00032   void setGait(const XWalkParameters& p, bool resetSpeeds=true) {
00033     xp=p;
00034     xp.packGroundGravity(ground,gravity);
00035     if(resetSpeeds)
00036       setSpeed(xp.getMaxXVel(),xp.getMaxYVel(),xp.getMaxAVel());
00037   }
00038   
00039   //! Load gait parameters from a file
00040   void setGait(const std::string& file, bool resetSpeeds=true) {
00041     xp.loadFile(file.c_str());
00042     if(resetSpeeds)
00043       setSpeed(xp.getMaxXVel(),xp.getMaxYVel(),xp.getMaxAVel());
00044   }
00045   
00046   //! Specify steps to perform
00047   void setSteps(const std::vector<GaitedFootsteps::State>& st) {
00048     steps=st;
00049     stepStartTime = get_time() / 1000.0;
00050     stepDuration = 0;
00051     curStep=-1u;
00052     advanceStep();
00053   }
00054   
00055   //! Specify speeds for translation (mm/s) and rotation (rad/s)
00056   /*! Does not take affect until next step */
00057   void setSpeed(fmat::fmatReal x, fmat::fmatReal y, fmat::fmatReal a) {
00058     xySpeed[0]=x; xySpeed[1]=y; aSpeed=a;
00059   }
00060 
00061 protected:
00062   //! updates active step and returns offset of body position from current step's initial location
00063   fmat::Column<2> curBodyOffset(double t);
00064   
00065   //! increments #curStep and dependent values
00066   bool advanceStep(); 
00067   
00068   //! solves inverse kinematics and send affected output values to motion manager
00069   void solveIK(unsigned int leg, const IKSolver::Point& tgt);
00070   
00071   virtual void doStart() {}
00072   virtual void doStop() {}
00073 
00074   XWalkParameters xp;
00075   fmat::Column<3> ground;
00076   fmat::Column<3> gravity;
00077   
00078   std::vector<GaitedFootsteps::State> steps;
00079   unsigned int curStep; //!< current #step index, indicates transition to curStep+1, never increments past steps.size()-1
00080   fmat::Column<2> xySpeed;
00081   fmat::fmatReal aSpeed;
00082   bool newStep;
00083   double stepStartTime; //!< clock time in second of beginning of step
00084   double stepDuration; //!< duration in seconds
00085   bool support[NumLegs]; //!< set to true if the leg is in support phase (i.e. not moving to new contact)
00086   DriverMessaging::FixedPoints contactMsg; //!< list of current contact points, for better Mirage simulation
00087 
00088   static KinematicJoint* kine;
00089   static KinematicJoint* childMap[NumReferenceFrames];
00090 };
00091 
00092 /*! @file
00093  * @brief Defines GaitedFootstepMC, which executes a series of footsteps, probably generated by applying astar() to a GaitedFootsteps domain
00094  * @author Ethan Tira-Thompson (ejt) (Creator)
00095  */
00096 
00097 #endif

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