GaitedFootsteps.h
Go to the documentation of this file.00001
00002 #ifndef INCLUDED_GaitedFootsteps_h_
00003 #define INCLUDED_GaitedFootsteps_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "Shared/fmat.h"
00021 #include "Shared/RobotInfo.h"
00022 #include "Motion/XWalkParameters.h"
00023 #include "Planners/PlannerObstacles.h"
00024 #include <tr1/functional>
00025
00026 class KinematicJoint;
00027
00028 class GaitedFootsteps {
00029 public:
00030 GaitedFootsteps()
00031 : speed(0), flightDuration(0), stepDuration(), relaxation(1), rotDist(0), stepReorient(true), stepRehab(true),
00032 kinematics(NULL), ncand(), p(), ground(), gravity(), neutrals(), groups(), obstacles()
00033 {}
00034
00035 struct State {
00036 State() : pos(), oriRot(fmat::Matrix<2,2>::identity()), oriAngle(0), phase(0) {}
00037 fmat::Column<2> pos;
00038 fmat::Matrix<2,2> oriRot;
00039 fmat::fmatReal oriAngle;
00040 fmat::Column<2> footPos[NumLegs];
00041 float legJoints[NumLegJoints];
00042 unsigned int phase;
00043 static fmat::fmatReal ROUND;
00044 static const fmat::fmatReal ORIROUND;
00045 size_t hash() const {
00046 const long x = static_cast<long>(pos[0]*ROUND);
00047 const long y = static_cast<long>(pos[1]*ROUND);
00048 const long a = static_cast<long>(oriAngle*ORIROUND);
00049
00050 return std::tr1::hash<fmat::fmatReal>()((x<<16) + (a<<8) + y);
00051 }
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 bool operator==(const State& st) const {
00064
00065
00066
00067
00068 const long mx = static_cast<long>(pos[0]*ROUND);
00069 const long my = static_cast<long>(pos[1]*ROUND);
00070 const long ma = static_cast<long>(oriAngle*ORIROUND);
00071 const long stx = static_cast<long>(st.pos[0]*ROUND);
00072 const long sty = static_cast<long>(st.pos[1]*ROUND);
00073 const long sta = static_cast<long>(st.oriAngle*ORIROUND);
00074 return mx==stx && my==sty && ma==sta;
00075 }
00076 friend std::ostream& operator<<(std::ostream& os, const State& st) {
00077 return os << &st << ": " << st.pos << " @ " << st.oriAngle << '\n'
00078 << fmat::SubMatrix<2,NumLegs,const float>(&st.footPos[0][0]) << std::endl;
00079 }
00080 };
00081
00082 ~GaitedFootsteps();
00083
00084
00085 bool validate(const State& st) const;
00086
00087
00088 float heuristic(const State& st, const State& goal) const;
00089
00090
00091
00092 const std::vector<std::pair<float,GaitedFootsteps::State> >& expand(const State* parent, const State& st, const State& goal) const;
00093
00094 void setGait(const KinematicJoint& kj, const XWalkParameters& xp, size_t discretization);
00095
00096 void addObstacle(PlannerObstacle2D* obs) { obstacles.push_back(obs); }
00097 std::vector< PlannerObstacle2D* >& getObstacles() { return obstacles; }
00098 const std::vector< PlannerObstacle2D* >& getObstacles() const { return obstacles; }
00099
00100 float speed;
00101 float flightDuration;
00102 float stepDuration;
00103 float relaxation;
00104 float rotDist;
00105
00106 bool stepReorient;
00107 bool stepRehab;
00108
00109 KinematicJoint * kinematics;
00110 KinematicJoint* childMap[NumReferenceFrames];
00111 struct StepData {
00112 StepData() : pos() {}
00113 fmat::Column<3> pos;
00114 #if defined(TGT_IS_MANTIS)
00115 static const int JointsPerLeg = 4;
00116 #endif
00117 float legJoints[JointsPerLeg];
00118
00119 };
00120 size_t ncand;
00121 XWalkParameters p;
00122 fmat::Column<3> ground;
00123 fmat::Column<3> gravity;
00124 std::vector< fmat::Column<2> > neutrals;
00125 std::vector< std::set<size_t> > groups;
00126 std::vector< PlannerObstacle2D* > obstacles;
00127
00128 PlannerObstacle2D* checkObstacles(const fmat::Column<2>& pt) const;
00129 bool addRotation(const State& st, float strideAngle, float strideDist, const fmat::Column<2>& strideDir, const fmat::Column<2>& stride, std::vector<std::pair<float,GaitedFootsteps::State> >& candidates, float maxDist) const;
00130 void addCandidate(const State* parent, const State& st, float angle, std::vector<std::pair<float,GaitedFootsteps::State> >& candidates, float maxDist=0) const;
00131
00132 private:
00133 GaitedFootsteps(const GaitedFootsteps&);
00134 GaitedFootsteps& operator=(const GaitedFootsteps&);
00135 };
00136
00137 #endif