robotoc
robotoc - efficient ROBOT Optimal Control solvers
Loading...
Searching...
No Matches
solution_interpolator.hpp
Go to the documentation of this file.
1#ifndef ROBOTOC_SOLUTION_INTERPOLATOR_HPP_
2#define ROBOTOC_SOLUTION_INTERPOLATOR_HPP_
3
9
10
11namespace robotoc {
12
18public:
24
29
34
39
44
48 SolutionInterpolator& operator=(SolutionInterpolator&&) noexcept = default;
49
51
57 void store(const TimeDiscretization& time_discretization,
58 const Solution& solution);
59
66 void interpolate(const Robot& robot,
67 const TimeDiscretization& time_discretization,
68 Solution& solution) const;
69
74 bool hasStoredSolution() const { return has_stored_solution_; }
75
76private:
77 InterpolationOrder order_;
78 TimeDiscretization stored_time_discretization_;
79 Solution stored_solution_;
80 bool has_stored_solution_;
81
82 int findStoredGridIndexAtImpactByTime(const double t) const {
83 const int N = stored_time_discretization_.size() - 1;
84 constexpr double eps = 1.0e-06;
85 for (int i=1; i<N; ++i) {
86 if ((stored_time_discretization_[i].type == GridType::Impact)
87 && (numerics::isApprox(t, stored_time_discretization_[i].t, eps))) {
88 return i;
89 }
90 }
91 return -1;
92 }
93
94 int findStoredGridIndexAtLiftByTime(const double t) const {
95 const int N = stored_time_discretization_.size() - 1;
96 constexpr double eps = 1.0e-06;
97 for (int i=1; i<N; ++i) {
98 if ((stored_time_discretization_[i].type == GridType::Lift)
99 && (numerics::isApprox(t, stored_time_discretization_[i].t, eps))) {
100 return i;
101 }
102 }
103 return -1;
104 }
105
106 int findStoredGridIndexBeforeTime(const double t) const {
107 if (t < stored_time_discretization_[0].t) return -1;
108 const int N = stored_time_discretization_.size() - 1;
109 for (int i=0; i<N; ++i) {
110 if (t < stored_time_discretization_[i+1].t) {
111 if (stored_time_discretization_[i].type == GridType::Impact) {
112 return i+1;
113 }
114 else {
115 return i;
116 }
117 }
118 }
119 return N;
120 }
121
122 static void interpolate(const Robot& robot, const SplitSolution& s1,
123 const SplitSolution& s2, const double alpha,
124 SplitSolution& s);
125
126 static void interpolatePartial(const Robot& robot, const SplitSolution& s1,
127 const SplitSolution& s2, const double alpha,
128 SplitSolution& s);
129
130 static void initEventSolution(const Robot& robot, const SplitSolution& s1,
131 const SplitSolution& s2, const double alpha,
132 SplitSolution& s);
133
134 static void modifyImpactSolution(SplitSolution& s);
135
136 static void modifyTerminalSolution(SplitSolution& s);
137};
138
139} // namespace robotoc
140
141#endif // ROBOTOC_SOLUTION_INTERPOLATOR_HPP_
Dynamics and kinematics model of robots. Wraps pinocchio::Model and pinocchio::Data....
Definition: robot.hpp:32
Solution interpolator.
Definition: solution_interpolator.hpp:17
bool hasStoredSolution() const
Check if this has a stored solution.
Definition: solution_interpolator.hpp:74
~SolutionInterpolator()=default
Default destructor.
SolutionInterpolator(const SolutionInterpolator &)=default
Default copy constructor.
void store(const TimeDiscretization &time_discretization, const Solution &solution)
Stores the current time discretization and solution.
SolutionInterpolator(SolutionInterpolator &&) noexcept=default
Default move constructor.
SolutionInterpolator & operator=(const SolutionInterpolator &)=default
Default copy assign operator.
void setInterpolationOrder(const InterpolationOrder order)
void interpolate(const Robot &robot, const TimeDiscretization &time_discretization, Solution &solution) const
Interpolates the solution.
SolutionInterpolator(const InterpolationOrder order=InterpolationOrder::Linear)
Constructor.
Time discretization of the optimal control problem.
Definition: time_discretization.hpp:20
int size() const
Returns the number of grids.
Definition: time_discretization.hpp:75
bool isApprox(const double x, const double y, const double eps=std::sqrt(std::numeric_limits< double >::epsilon()))
Definition: numerics.hpp:10
Definition: constraint_component_base.hpp:17
aligned_vector< SplitSolution > Solution
Solution to the optimal control problem.
Definition: solution.hpp:16
InterpolationOrder
Order of the interpolation.
Definition: interpolation_order.hpp:10