quadruped_gait_generator.cc
Go to the documentation of this file.
1 /******************************************************************************
2 Copyright (c) 2018, Alexander W. Winkler. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
6 
7 * Redistributions of source code must retain the above copyright notice, this
8  list of conditions and the following disclaimer.
9 
10 * Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation
12  and/or other materials provided with the distribution.
13 
14 * Neither the name of the copyright holder nor the names of its
15  contributors may be used to endorse or promote products derived from
16  this software without specific prior written permission.
17 
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 ******************************************************************************/
29 
31 
32 #include <cassert>
33 #include <iostream>
34 
36 
37 namespace towr {
38 
40 {
41  int n_ee = 4;
42  ContactState init(n_ee, false);
43 
44  II_ = init; // flight_phase
45  PI_ = bI_ = IP_ = Ib_ = init; // single contact
46  Pb_ = bP_ = BI_ = IB_ = PP_ = bb_ = init; // two leg support
47  Bb_ = BP_ = bB_ = PB_ = init; // three-leg support
48  BB_ = init; // four-leg support phase
49 
50  // flight_phase
51  II_ = ContactState(n_ee, false);
52  // one stanceleg
53  PI_.at(LH) = true;
54  bI_.at(RH) = true;
55  IP_.at(LF) = true;
56  Ib_.at(RF) = true;
57  // two stancelegs
58  Pb_.at(LH) = true; Pb_.at(RF) = true;
59  bP_.at(RH) = true; bP_.at(LF) = true;
60  BI_.at(LH) = true; BI_.at(RH) = true;
61  IB_.at(LF) = true; IB_.at(RF) = true;
62  PP_.at(LH) = true; PP_.at(LF) = true;
63  bb_.at(RH) = true; bb_.at(RF) = true;
64  // three stancelegs
65  Bb_.at(LH) = true; Bb_.at(RH) = true; Bb_.at(RF)= true;
66  BP_.at(LH) = true; BP_.at(RH) = true; BP_.at(LF)= true;
67  bB_.at(RH) = true; bB_.at(LF) = true; bB_.at(RF)= true;
68  PB_.at(LH) = true; PB_.at(LF) = true; PB_.at(RF)= true;
69  // four stancelgs
70  BB_ = ContactState(n_ee, true);
71 
72  // default gait
73  SetGaits({Stand});
74 }
75 
76 void
78 {
79  switch (combo) {
80  case C0: SetGaits({Stand, Walk2, Walk2, Walk2, Walk2E, Stand}); break; // overlap-walk
81  case C1: SetGaits({Stand, Run2, Run2, Run2, Run2E, Stand}); break; // fly trot
82  case C2: SetGaits({Stand, Run3, Run3, Run3, Run3E, Stand}); break; // pace
83  case C3: SetGaits({Stand, Hop1, Hop1, Hop1, Hop1E, Stand}); break; // bound
84  case C4: SetGaits({Stand, Hop3, Hop3, Hop3, Hop3E, Stand}); break; // gallop
85  default: assert(false); std::cout << "Gait not defined\n"; break;
86  }
87 }
88 
91 {
92  switch (gait) {
93  case Stand: return GetStrideStand();
94  case Flight: return GetStrideFlight();
95  case Walk1: return GetStrideWalk();
96  case Walk2: return GetStrideWalkOverlap();
98  case Run1: return GetStrideTrot();
99  case Run2: return GetStrideTrotFly();
100  case Run2E: return GetStrideTrotFlyEnd();
101  case Run3: return GetStridePace();
102  case Run3E: return GetStridePaceEnd();
103  case Hop1: return GetStrideBound();
104  case Hop1E: return GetStrideBoundEnd();
105  case Hop2: return GetStridePronk();
106  case Hop3: return GetStrideGallop();
107  case Hop3E: return RemoveTransition(GetStrideGallop());
108  case Hop5: return GetStrideLimp();
109  default: assert(false); // gait not implemented
110  }
111 }
112 
115 {
116  auto times =
117  {
118  0.3,
119  };
120  auto contacts =
121  {
122  BB_,
123  };
124 
125  return std::make_pair(times, contacts);
126 }
127 
130 {
131  auto times =
132  {
133  0.3,
134  };
135  auto contacts =
136  {
137  Bb_,
138  };
139 
140  return std::make_pair(times, contacts);
141 }
142 
145 {
146  double push = 0.3;
147  double flight = 0.4;
148  double land = 0.3;
149 
150  auto times =
151  {
152  push, flight, land
153  };
154  auto phase_contacts =
155  {
156  BB_, II_, BB_,
157  };
158 
159  return std::make_pair(times, phase_contacts);
160 }
161 
164 {
165  double step = 0.3;
166  double stand = 0.2;
167  auto times =
168  {
169  step, stand, step, stand,
170  step, stand, step, stand,
171  };
172  auto phase_contacts =
173  {
174  bB_, BB_, Bb_, BB_,
175  PB_, BB_, BP_, BB_
176  };
177 
178  return std::make_pair(times, phase_contacts);
179 }
180 
183 {
184  double three = 0.25;
185  double lateral = 0.13;
186  double diagonal = 0.13;
187 
188  auto times =
189  {
190  three, lateral, three,
191  diagonal,
192  three, lateral, three,
193  diagonal,
194  };
195  auto phase_contacts =
196  {
197  bB_, bb_, Bb_,
198  Pb_, // start lifting RH
199  PB_, PP_, BP_,
200  bP_, // start lifting LH
201  };
202 
203  return std::make_pair(times, phase_contacts);
204 }
205 
208 {
209  double t_step = 0.3;
210  double t_stand = 0.2;
211  auto times =
212  {
213  t_step, t_stand, t_step, t_stand,
214  };
215  auto phase_contacts =
216  {
217  bP_, BB_, Pb_, BB_,
218  };
219 
220  return std::make_pair(times, phase_contacts);
221 }
222 
225 {
226  double stand = 0.4;
227  double flight = 0.1;
228  auto times =
229  {
230  stand, flight,
231  stand, flight,
232  };
233  auto phase_contacts =
234  {
235  bP_, II_,
236  Pb_, II_,
237  };
238 
239  return std::make_pair(times, phase_contacts);
240 }
241 
244 {
245  auto times =
246  {
247  0.4,
248  };
249  auto phase_contacts =
250  {
251  bP_
252  };
253 
254  return std::make_pair(times, phase_contacts);
255 }
256 
259 {
260  double stand = 0.3;
261  double flight = 0.1;
262 
263  auto times =
264  {
265  stand, flight, stand, flight
266  };
267  auto phase_contacts =
268  {
269  PP_, II_, bb_, II_,
270  };
271 
272  return std::make_pair(times, phase_contacts);
273 }
274 
277 {
278  auto times =
279  {
280  0.3,
281  };
282  auto phase_contacts =
283  {
284  PP_,
285  };
286 
287  return std::make_pair(times, phase_contacts);
288 }
289 
292 {
293  double stand = 0.3;
294  double flight = 0.1;
295 
296  auto times =
297  {
298  stand, flight, stand, flight
299  };
300  auto phase_contacts =
301  {
302  BI_, II_, IB_, II_
303  };
304 
305  return std::make_pair(times, phase_contacts);
306 }
307 
310 {
311  auto times =
312  {
313  0.3,
314  };
315  auto phase_contacts =
316  {
317  BI_,
318  };
319 
320  return std::make_pair(times, phase_contacts);
321 }
322 
325 {
326  double A = 0.3; // both feet in air
327  double B = 0.2; // overlap
328  double C = 0.2; // transition front->hind
329  auto times =
330  {
331  B, A, B,
332  C,
333  B, A, B,
334  C
335  };
336  auto phase_contacts =
337  {
338  Bb_, BI_, BP_, // front legs swing forward
339  bP_, // transition phase
340  bB_, IB_, PB_, // hind legs swing forward
341  Pb_
342  };
343 
344  return std::make_pair(times, phase_contacts);
345 }
346 
349 {
350  double A = 0.1; // three in contact
351  double B = 0.2; // all in contact
352  double C = 0.1; // one in contact
353 
354  auto times =
355  {
356  A, B, C,
357  A, B, C,
358  };
359  auto phase_contacts =
360  {
361  Bb_, BB_, IP_,
362  Bb_, BB_, IP_,
363  };
364 
365  return std::make_pair(times, phase_contacts);
366 }
367 
368 } /* namespace towr */
Gaits
Predefined strides, each with a different gait diagram.
GaitInfo RemoveTransition(const GaitInfo &g) const
Combos
Predefined combinations of different strides.
void SetGaits(const std::vector< Gaits > &gaits)
Sets the times_ and contacts_ variables according to the gaits.
GaitInfo GetGait(Gaits gait) const override
std::pair< VecTimes, std::vector< ContactState >> GaitInfo
void SetCombo(Combos combo) override
Sets a specific sequence of gaits.
std::vector< bool > ContactState


towr
Author(s): Alexander W. Winkler
autogenerated on Fri Apr 2 2021 02:14:16