parameters.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 
30 #include <towr/parameters.h>
32 
33 #include <algorithm>
34 #include <numeric> // std::accumulate
35 #include <math.h> // fabs
36 #include <cassert>
37 
38 namespace towr {
39 
41 {
42  // constructs optimization variables
45  ee_polynomials_per_swing_phase_ = 2; // so step can at least lift leg
46 
47  // parameters related to specific constraints (only used when it is added as well)
51  dt_constraint_base_motion_ = duration_base_polynomial_/4.; // only for base RoM constraint
52  bound_phase_duration_ = std::make_pair(0.2, 1.0); // used only when optimizing phase durations, so gait
53 
54  // a minimal set of basic constraints
55  constraints_.push_back(Terrain);
56  constraints_.push_back(Dynamic); //Ensures that the dynamic model is fullfilled at discrete times.
57  constraints_.push_back(BaseAcc); // so accelerations don't jump between polynomials
58  constraints_.push_back(EndeffectorRom); //Ensures that the range of motion is respected at discrete times.
59  constraints_.push_back(Force); // ensures unilateral forces and inside the friction cone.
60  constraints_.push_back(Swing); // creates smoother swing motions, not absolutely required.
61 
62  // optional costs to e.g penalize endeffector forces
63  // costs_.push_back({ForcesCostID, 1.0}); weighed by 1.0 relative to other costs
64 
65  // bounds on final 6DoF base state
70 
71  // additional restrictions are set directly on the variables in nlp_factory,
72  // such as e.g. initial and endeffector,...
73 }
74 
75 void
76 
78 {
79  constraints_.push_back(TotalTime);
80 }
81 
84 {
85  std::vector<double> base_spline_timings_;
86  double dt = duration_base_polynomial_;
87  double t_left = GetTotalTime ();
88 
89  double eps = 1e-10; // since repeated subtraction causes inaccuracies
90  while (t_left > eps) {
91  double duration = t_left>dt? dt : t_left;
92  base_spline_timings_.push_back(duration);
93 
94  t_left -= dt;
95  }
96 
97  return base_spline_timings_;
98 }
99 
100 int
102 {
103  return ee_phase_durations_.at(ee).size();
104 }
105 
106 int
108 {
109  return ee_in_contact_at_start_.size();
110 }
111 
112 double
114 {
115  std::vector<double> T_feet;
116 
117  for (const auto& v : ee_phase_durations_)
118  T_feet.push_back(std::accumulate(v.begin(), v.end(), 0.0));
119 
120  // safety check that all feet durations sum to same value
121  double T = T_feet.empty()? 0.0 : T_feet.front(); // take first foot as reference
122  for (double Tf : T_feet)
123  assert(fabs(Tf - T) < 1e-6);
124 
125  return T;
126 }
127 
128 bool
130 {
131  // if total time is constrained, then timings are optimized
133  auto v = constraints_; // shorthand
134  return std::find(v.begin(), v.end(), c) != v.end();
135 }
136 
137 } // namespace towr
std::pair< double, double > bound_phase_duration_
Definition: parameters.h:212
sets SplineAccConstraint
Definition: parameters.h:146
sets DynamicConstraint
Definition: parameters.h:139
int force_polynomials_per_stance_phase_
Number of polynomials to parameterize each contact force during stance phase.
Definition: parameters.h:195
sets RangeOfMotionConstraint
Definition: parameters.h:140
ConstraintName
Identifiers to be used to add certain constraints to the optimization problem.
Definition: parameters.h:139
double GetTotalTime() const
Total duration [s] of the motion.
Definition: parameters.cc:113
std::vector< int > bounds_final_ang_vel_
Definition: parameters.h:201
sets SwingConstraint
Definition: parameters.h:144
sets ForceConstraint
Definition: parameters.h:143
std::vector< int > bounds_final_lin_pos_
which dimensions (x,y,z) of the final base state should be bounded
Definition: parameters.h:201
VecTimes GetBasePolyDurations() const
The durations of each base polynomial in the spline (lin+ang).
Definition: parameters.cc:83
int ee_polynomials_per_swing_phase_
Number of polynomials to parameterize foot movement during swing phases.
Definition: parameters.h:192
double dt_constraint_range_of_motion_
Interval at which the range of motion constraint is enforced.
Definition: parameters.h:183
int GetEECount() const
The number of endeffectors.
Definition: parameters.cc:107
std::vector< int > bounds_final_lin_vel_
Definition: parameters.h:201
double duration_base_polynomial_
Fixed duration of each cubic polynomial describing the base motion.
Definition: parameters.h:189
double dt_constraint_dynamic_
Interval at which the dynamic constraint is enforced.
Definition: parameters.h:180
bool IsOptimizeTimings() const
True if the phase durations should be optimized over.
Definition: parameters.cc:129
std::vector< VecTimes > ee_phase_durations_
Number and initial duration of each foot&#39;s swing and stance phases.
Definition: parameters.h:168
void OptimizePhaseDurations()
Specifies that timings of all feet, so the gait, should be optimized.
Definition: parameters.cc:77
double force_limit_in_normal_direction_
The maximum allowable force [N] in normal direction.
Definition: parameters.h:198
sets TotalDurationConstraint
Definition: parameters.h:141
double dt_constraint_base_motion_
Interval at which the base motion constraint is enforced.
Definition: parameters.h:186
std::vector< double > VecTimes
Definition: parameters.h:158
std::vector< int > bounds_final_ang_pos_
Definition: parameters.h:201
Parameters()
Default parameters to get started.
Definition: parameters.cc:40
std::vector< bool > ee_in_contact_at_start_
True if the foot is initially in contact with the terrain.
Definition: parameters.h:171
UsedConstraints constraints_
Which constraints should be used in the optimization problem.
Definition: parameters.h:174
unsigned int EEID
Definition: parameters.h:159
int GetPhaseCount(EEID ee) const
The number of phases allowed for endeffector ee.
Definition: parameters.cc:101
sets TerrainConstraint
Definition: parameters.h:142


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