Homepage Demos Overview Downloads Tutorials Reference
Credits
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Search

WalkMC.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 
00003 //This class is ported from Carnegie Mellon's 2001 Robosoccer entry, and falls under their license:
00004 /*=========================================================================
00005     CMPack'02 Source Code Release for OPEN-R SDK v1.0
00006     Copyright (C) 2002 Multirobot Lab [Project Head: Manuela Veloso]
00007     School of Computer Science, Carnegie Mellon University
00008   -------------------------------------------------------------------------
00009     This software is distributed under the GNU General Public License,
00010     version 2.  If you do not have a copy of this licence, visit
00011     www.gnu.org, or write: Free Software Foundation, 59 Temple Place,
00012     Suite 330 Boston, MA 02111-1307 USA.  This program is distributed
00013     in the hope that it will be useful, but WITHOUT ANY WARRANTY,
00014     including MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00015   -------------------------------------------------------------------------
00016     Additionally licensed to Sony Corporation under the following terms:
00017 
00018     This software is provided by the copyright holders AS IS and any
00019     express or implied warranties, including, but not limited to, the
00020     implied warranties of merchantability and fitness for a particular
00021     purpose are disclaimed.  In no event shall authors be liable for
00022     any direct, indirect, incidental, special, exemplary, or consequential
00023     damages (including, but not limited to, procurement of substitute
00024     goods or services; loss of use, data, or profits; or business
00025     interruption) however caused and on any theory of liability, whether
00026     in contract, strict liability, or tort (including negligence or
00027     otherwise) arising in any way out of the use of this software, even if
00028     advised of the possibility of such damage.
00029   =========================================================================
00030 */
00031 
00032 #ifndef INCLUDED_WalkMC_h
00033 #define INCLUDED_WalkMC_h
00034 
00035 #include "MotionCommand.h"
00036 #include "Geometry.h"
00037 #include "Kinematics.h"
00038 #include "Path.h"
00039 #include "Shared/get_time.h"
00040 #include "OutputCmd.h"
00041 
00042 //! A nice walking class from Carnegie Mellon University's 2001 Robosoccer team, modified to fit this framework, see their <a href="../CMPack_license.txt">license</a>
00043 /*! Moves the feet through a looping path in order to walk - default parameters use
00044  *  a walk low to the ground so you don't walk over the ball.
00045  *
00046  *  This portion of the code falls under CMPack's license:
00047  *  @verbinclude CMPack_license.txt
00048  */
00049 class WalkMC : public MotionCommand {
00050 public:
00051   typedef SplinePath<vector3d,double> splinepath; //!<for convenience
00052   typedef HermiteSplineSegment<vector3d,double> spline; //!<for convenience
00053 
00054   //! holds state about each leg's path
00055   struct LegWalkState {
00056     LegWalkState() : airpath(), air(0) {} //!< constructor
00057     spline airpath; //!< the path to follow
00058     bool air; //!< true if in the air
00059   };
00060   
00061   //! holds parameters about how to move each leg
00062   struct LegParam {
00063     LegParam() : neutral(), lift_vel(), down_vel(), lift_time(0), down_time(0) {} //!< constructor
00064     vector3d neutral; //!< defines the "neutral" point of each leg - where it is in midstep
00065     vector3d lift_vel; //!< give the velocities to use when raising the paw
00066     vector3d down_vel; //!< give the velocities to use when lowering the paw
00067     double lift_time; //!< the time (as percentage of WalkParam::period) in the cycle to lift (so you can set different offsets between the paws)
00068     double down_time; //!< the time (as percentage of WalkParam::period) in the cycle to put down (so you can set different offsets between the paws)
00069   };
00070 
00071   //! holds more general parameters about the walk
00072   struct WalkParam {
00073     WalkParam() : body_height(0), body_angle(0), hop(0), sway(0), period(0), reserved() {} //!< constructor
00074     LegParam leg[4]; //!< a set of LegParam's, one for each leg
00075     double body_height; //!< the height to hold the body (mm)
00076     double body_angle; //!< the angle to hold the body (rad - 0 is level)
00077     double hop;  //!< sinusoidal hop amplitude
00078     double sway; //!< sinusoidal sway in y direction
00079     long period; //!< the time between steps
00080     long reserved; //!< live with it
00081   };
00082 
00083   //! constructor
00084   WalkMC(const char* pfile=NULL);
00085 
00086   virtual void DoStart(); //!< sends an activate LocomotionEvent
00087   virtual void DoStop();  //!< sends a deactivate LocomotionEvent
00088 
00089   virtual int updateOutputs(); //!< calculates current positions of the paws
00090   virtual int isDirty() { return !isPaused && (target_vel_xya.x!=0 || target_vel_xya.y!=0 || target_vel_xya.z!=0); } //!< returns true if we are walking
00091   virtual int isAlive() { return true; } //!< always true - never autoprunes
00092 
00093   //! loads parameters from a file (@todo use LoadSave)
00094   void load(const char* pfile);
00095   //! saves parameters to a file (@todo use LoadSave)
00096   void save(const char* pfile) const;
00097   //! set the direction to walk - can specify x (forward), y (left), and angular (counterclockwise) velocities
00098   void setTargetVelocity(double dx,double dy,double da);
00099   //! returns current velocity we're trying to go
00100   const vector3d& getTargetVelocity() { return target_vel_xya; }
00101   //! returns the velocity we're actually moving (subject to clipping at max_accel_xya), doesn't reflect value of getPaused()...
00102   const vector3d& getCurVelocity() const { return vel_xya;}
00103   //! returns the time we've been traveling along the current vector
00104   unsigned int getTravelTime() { return get_time()-travelTime; }
00105   
00106   void setPaused(bool p) { isPaused=p; } //!< if set to true, will stop moving
00107   bool getPaused() const { return isPaused; } //!< if is true, we aren't moving
00108   void setHeight(double h) { wp.body_height=h; } //!< sets WalkParam::body_height of #wp
00109   double getHeight() { return wp.body_height; } //!< gets WalkParam::body_height of #wp
00110   void setAngle(double a) { wp.body_angle=a; } //!< sets WalkParam::body_angle of #wp
00111   double getAngle() { return wp.body_angle; } //!< gets WalkParam::body_angle of #wp
00112   void setHop(double h) { wp.hop=h; } //!< sets WalkParam::hop of #wp
00113   double getHop() { return wp.hop; } //!< gets WalkParam::hop of #wp
00114   void setSway(double h) { wp.sway=h; } //!< sets WalkParam::sway of #wp
00115   double getSway() { return wp.sway; } //!< gets WalkParam::sway of #wp
00116   void setPeriod(long p) { wp.period=p; } //!< sets WalkParam::period of #wp
00117   long getPeriod() { return wp.period; } //!< gets WalkParam::period of #wp
00118 
00119   //! takes current leg positions from WorldState and tries to match the point in the cycle most like it
00120   void resetLegPos();
00121 
00122   static const float MAX_DX; //!< ==180 mm/sec
00123   static const float MAX_DY; //!< ==140 mm/sec
00124   static const float MAX_DA; //!< ==1.8 rad/sec
00125   static const vector3d max_accel_xya; //!< vector version of MAX_DX,MAX_DY,MAX_DA
00126 
00127  protected:
00128   //! holds current joint commands
00129   OutputCmd cmds[NumOutputs][NumFrames];
00130 
00131  protected:
00132   //! does some setup stuff, calls load(pfile)
00133   void init(const char* pfile);
00134 
00135   bool isPaused; //!< true if we are paused
00136 
00137   WalkParam wp; //!< current walking parameters (note that it's not static - different WalkMC's can have different setting, handy...
00138   LegWalkState legw[NumLegs]; //!< current state of each leg
00139   vector3d legpos[NumLegs]; //!< current position of each leg
00140   splinepath body_loc; //!< the path the body goes through while walking (?)
00141   splinepath body_angle; //!< the path the body goes through while walking (?)
00142 
00143   vector3d pos_delta; //!< how much we've moved
00144   double angle_delta; //!< how much we've turned
00145   
00146   unsigned int travelTime; //!< the time since the last call to setTargetVelocity - handy to check the time we've been traveling current vector
00147   int time; //!< time of last call to updateJointCmds()
00148   int TimeStep; //!< time to pretend passes between each call to updateJointCmds() - usually RobotInfo::FrameTime, unless you want to make it walk in slow motion (handy sometimes for debugging)
00149   
00150   vector3d vel_xya; //!< the current velocity we're moving
00151   vector3d target_vel_xya; //!< the velocity that was requested
00152 };
00153 
00154 /* struct LegState{
00155    long attr,reserved;
00156    point3d pos;
00157    double angles[3];
00158    };
00159    
00160    struct HeadState{
00161    long attr,reserved;
00162    vector3d target;
00163    double angles[3];
00164    };
00165    
00166    struct BodyState{
00167    BodyPosition pos;
00168    LegState leg[4];
00169    HeadState head;
00170    }; 
00171 */
00172 
00173 /*! @file
00174  * @brief Describes WalkMC, a MotionCommand for walking around
00175  * @author CMU RoboSoccer 2001-2002 (Creator)
00176  * @author ejt (ported)
00177  * 
00178  * @verbinclude CMPack_license.txt
00179  *
00180  * $Author: ejt $
00181  * $Name: tekkotsu-1_4_1 $
00182  * $Revision: 1.8 $
00183  * $State: Exp $
00184  * $Date: 2003/04/09 03:33:57 $
00185  */
00186 
00187 #endif

Tekkotsu v1.4
Generated Sat Jul 19 00:06:32 2003 by Doxygen 1.3.2