00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <towr/initialization/quadruped_gait_generator.h>
00031
00032 #include <cassert>
00033 #include <iostream>
00034
00035 #include <towr/models/endeffector_mappings.h>
00036
00037 namespace towr {
00038
00039 QuadrupedGaitGenerator::QuadrupedGaitGenerator ()
00040 {
00041 int n_ee = 4;
00042 ContactState init(n_ee, false);
00043
00044 II_ = init;
00045 PI_ = bI_ = IP_ = Ib_ = init;
00046 Pb_ = bP_ = BI_ = IB_ = PP_ = bb_ = init;
00047 Bb_ = BP_ = bB_ = PB_ = init;
00048 BB_ = init;
00049
00050
00051 II_ = ContactState(n_ee, false);
00052
00053 PI_.at(LH) = true;
00054 bI_.at(RH) = true;
00055 IP_.at(LF) = true;
00056 Ib_.at(RF) = true;
00057
00058 Pb_.at(LH) = true; Pb_.at(RF) = true;
00059 bP_.at(RH) = true; bP_.at(LF) = true;
00060 BI_.at(LH) = true; BI_.at(RH) = true;
00061 IB_.at(LF) = true; IB_.at(RF) = true;
00062 PP_.at(LH) = true; PP_.at(LF) = true;
00063 bb_.at(RH) = true; bb_.at(RF) = true;
00064
00065 Bb_.at(LH) = true; Bb_.at(RH) = true; Bb_.at(RF)= true;
00066 BP_.at(LH) = true; BP_.at(RH) = true; BP_.at(LF)= true;
00067 bB_.at(RH) = true; bB_.at(LF) = true; bB_.at(RF)= true;
00068 PB_.at(LH) = true; PB_.at(LF) = true; PB_.at(RF)= true;
00069
00070 BB_ = ContactState(n_ee, true);
00071
00072
00073 SetGaits({Stand});
00074 }
00075
00076 void
00077 QuadrupedGaitGenerator::SetCombo (Combos combo)
00078 {
00079 switch (combo) {
00080 case C0: SetGaits({Stand, Walk2, Walk2, Walk2, Walk2E, Stand}); break;
00081 case C1: SetGaits({Stand, Run2, Run2, Run2, Run2E, Stand}); break;
00082 case C2: SetGaits({Stand, Run3, Run3, Run3, Run3E, Stand}); break;
00083 case C3: SetGaits({Stand, Hop1, Hop1, Hop1, Hop1E, Stand}); break;
00084 case C4: SetGaits({Stand, Hop3, Hop3, Hop3, Hop3E, Stand}); break;
00085 default: assert(false); std::cout << "Gait not defined\n"; break;
00086 }
00087 }
00088
00089 QuadrupedGaitGenerator::GaitInfo
00090 QuadrupedGaitGenerator::GetGait(Gaits gait) const
00091 {
00092 switch (gait) {
00093 case Stand: return GetStrideStand();
00094 case Flight: return GetStrideFlight();
00095 case Walk1: return GetStrideWalk();
00096 case Walk2: return GetStrideWalkOverlap();
00097 case Walk2E: return RemoveTransition(GetStrideWalkOverlap());
00098 case Run1: return GetStrideTrot();
00099 case Run2: return GetStrideTrotFly();
00100 case Run2E: return GetStrideTrotFlyEnd();
00101 case Run3: return GetStridePace();
00102 case Run3E: return GetStridePaceEnd();
00103 case Hop1: return GetStrideBound();
00104 case Hop1E: return GetStrideBoundEnd();
00105 case Hop2: return GetStridePronk();
00106 case Hop3: return GetStrideGallop();
00107 case Hop3E: return RemoveTransition(GetStrideGallop());
00108 case Hop5: return GetStrideLimp();
00109 default: assert(false);
00110 }
00111 }
00112
00113 QuadrupedGaitGenerator::GaitInfo
00114 QuadrupedGaitGenerator::GetStrideStand () const
00115 {
00116 auto times =
00117 {
00118 0.3,
00119 };
00120 auto contacts =
00121 {
00122 BB_,
00123 };
00124
00125 return std::make_pair(times, contacts);
00126 }
00127
00128 QuadrupedGaitGenerator::GaitInfo
00129 QuadrupedGaitGenerator::GetStrideFlight () const
00130 {
00131 auto times =
00132 {
00133 0.3,
00134 };
00135 auto contacts =
00136 {
00137 Bb_,
00138 };
00139
00140 return std::make_pair(times, contacts);
00141 }
00142
00143 QuadrupedGaitGenerator::GaitInfo
00144 QuadrupedGaitGenerator::GetStridePronk () const
00145 {
00146 double push = 0.3;
00147 double flight = 0.4;
00148 double land = 0.3;
00149
00150 auto times =
00151 {
00152 push, flight, land
00153 };
00154 auto phase_contacts =
00155 {
00156 BB_, II_, BB_,
00157 };
00158
00159 return std::make_pair(times, phase_contacts);
00160 }
00161
00162 QuadrupedGaitGenerator::GaitInfo
00163 QuadrupedGaitGenerator::GetStrideWalk () const
00164 {
00165 double step = 0.3;
00166 double stand = 0.2;
00167 auto times =
00168 {
00169 step, stand, step, stand,
00170 step, stand, step, stand,
00171 };
00172 auto phase_contacts =
00173 {
00174 bB_, BB_, Bb_, BB_,
00175 PB_, BB_, BP_, BB_
00176 };
00177
00178 return std::make_pair(times, phase_contacts);
00179 }
00180
00181 QuadrupedGaitGenerator::GaitInfo
00182 QuadrupedGaitGenerator::GetStrideWalkOverlap () const
00183 {
00184 double three = 0.25;
00185 double lateral = 0.13;
00186 double diagonal = 0.13;
00187
00188 auto times =
00189 {
00190 three, lateral, three,
00191 diagonal,
00192 three, lateral, three,
00193 diagonal,
00194 };
00195 auto phase_contacts =
00196 {
00197 bB_, bb_, Bb_,
00198 Pb_,
00199 PB_, PP_, BP_,
00200 bP_,
00201 };
00202
00203 return std::make_pair(times, phase_contacts);
00204 }
00205
00206 QuadrupedGaitGenerator::GaitInfo
00207 QuadrupedGaitGenerator::GetStrideTrot () const
00208 {
00209 double t_step = 0.3;
00210 double t_stand = 0.2;
00211 auto times =
00212 {
00213 t_step, t_stand, t_step, t_stand,
00214 };
00215 auto phase_contacts =
00216 {
00217 bP_, BB_, Pb_, BB_,
00218 };
00219
00220 return std::make_pair(times, phase_contacts);
00221 }
00222
00223 QuadrupedGaitGenerator::GaitInfo
00224 QuadrupedGaitGenerator::GetStrideTrotFly () const
00225 {
00226 double stand = 0.4;
00227 double flight = 0.1;
00228 auto times =
00229 {
00230 stand, flight,
00231 stand, flight,
00232 };
00233 auto phase_contacts =
00234 {
00235 bP_, II_,
00236 Pb_, II_,
00237 };
00238
00239 return std::make_pair(times, phase_contacts);
00240 }
00241
00242 QuadrupedGaitGenerator::GaitInfo
00243 QuadrupedGaitGenerator::GetStrideTrotFlyEnd () const
00244 {
00245 auto times =
00246 {
00247 0.4,
00248 };
00249 auto phase_contacts =
00250 {
00251 bP_
00252 };
00253
00254 return std::make_pair(times, phase_contacts);
00255 }
00256
00257 QuadrupedGaitGenerator::GaitInfo
00258 QuadrupedGaitGenerator::GetStridePace () const
00259 {
00260 double stand = 0.3;
00261 double flight = 0.1;
00262
00263 auto times =
00264 {
00265 stand, flight, stand, flight
00266 };
00267 auto phase_contacts =
00268 {
00269 PP_, II_, bb_, II_,
00270 };
00271
00272 return std::make_pair(times, phase_contacts);
00273 }
00274
00275 QuadrupedGaitGenerator::GaitInfo
00276 QuadrupedGaitGenerator::GetStridePaceEnd () const
00277 {
00278 auto times =
00279 {
00280 0.3,
00281 };
00282 auto phase_contacts =
00283 {
00284 PP_,
00285 };
00286
00287 return std::make_pair(times, phase_contacts);
00288 }
00289
00290 QuadrupedGaitGenerator::GaitInfo
00291 QuadrupedGaitGenerator::GetStrideBound () const
00292 {
00293 double stand = 0.3;
00294 double flight = 0.1;
00295
00296 auto times =
00297 {
00298 stand, flight, stand, flight
00299 };
00300 auto phase_contacts =
00301 {
00302 BI_, II_, IB_, II_
00303 };
00304
00305 return std::make_pair(times, phase_contacts);
00306 }
00307
00308 QuadrupedGaitGenerator::GaitInfo
00309 QuadrupedGaitGenerator::GetStrideBoundEnd () const
00310 {
00311 auto times =
00312 {
00313 0.3,
00314 };
00315 auto phase_contacts =
00316 {
00317 BI_,
00318 };
00319
00320 return std::make_pair(times, phase_contacts);
00321 }
00322
00323 QuadrupedGaitGenerator::GaitInfo
00324 QuadrupedGaitGenerator::GetStrideGallop () const
00325 {
00326 double A = 0.3;
00327 double B = 0.2;
00328 double C = 0.2;
00329 auto times =
00330 {
00331 B, A, B,
00332 C,
00333 B, A, B,
00334 C
00335 };
00336 auto phase_contacts =
00337 {
00338 Bb_, BI_, BP_,
00339 bP_,
00340 bB_, IB_, PB_,
00341 Pb_
00342 };
00343
00344 return std::make_pair(times, phase_contacts);
00345 }
00346
00347 QuadrupedGaitGenerator::GaitInfo
00348 QuadrupedGaitGenerator::GetStrideLimp () const
00349 {
00350 double A = 0.1;
00351 double B = 0.2;
00352 double C = 0.1;
00353
00354 auto times =
00355 {
00356 A, B, C,
00357 A, B, C,
00358 };
00359 auto phase_contacts =
00360 {
00361 Bb_, BB_, IP_,
00362 Bb_, BB_, IP_,
00363 };
00364
00365 return std::make_pair(times, phase_contacts);
00366 }
00367
00368 }