robotoc
robotoc - efficient ROBOT Optimal Control solvers
Loading...
Searching...
No Matches
com_cost.hpp
Go to the documentation of this file.
1#ifndef ROBOTOC_COM_COST_HPP_
2#define ROBOTOC_COM_COST_HPP_
3
4#include "Eigen/Core"
5
16
17
18namespace robotoc {
19
24class CoMCost final : public CostFunctionComponentBase {
25public:
30 CoMCost(const Robot& robot);
31
37 CoMCost(const Robot& robot, const std::shared_ptr<CoMRefBase>& ref);
38
44 CoMCost(const Robot& robot, const Eigen::Vector3d& const_ref);
45
50
55
59 CoMCost(const CoMCost&) = default;
60
64 CoMCost& operator=(const CoMCost&) = default;
65
69 CoMCost(CoMCost&&) noexcept = default;
70
74 CoMCost& operator=(CoMCost&&) noexcept = default;
75
80 void set_ref(const std::shared_ptr<CoMRefBase>& ref);
81
86 void set_const_ref(const Eigen::Vector3d& const_ref);
87
92 void set_weight(const Eigen::Vector3d& weight);
93
99 void set_weight_terminal(const Eigen::Vector3d& weight_terminal);
100
106 void set_weight_impact(const Eigen::Vector3d& weight_impact);
107
113 bool isCostActive(const GridInfo& grid_info) const {
114 if (use_nonconst_ref_) {
115 return ref_->isActive(grid_info);
116 }
117 else {
118 return true;
119 }
120 }
121
129 void evalDiff(const Robot& robot, CostFunctionData& data,
130 const GridInfo& grid_info) const {
131 if (use_nonconst_ref_) {
132 if (ref_->isActive(grid_info)) {
133 ref_->updateRef(grid_info, data.x3d_ref);
134 data.diff_3d = robot.CoM() - data.x3d_ref;
135 }
136 }
137 else {
138 data.diff_3d = robot.CoM() - const_ref_;
139 }
140 }
141
142 double evalStageCost(Robot& robot, const ContactStatus& contact_status,
143 CostFunctionData& data, const GridInfo& grid_info,
144 const SplitSolution& s) const override;
145
146 void evalStageCostDerivatives(Robot& robot, const ContactStatus& contact_status,
147 CostFunctionData& data, const GridInfo& grid_info,
148 const SplitSolution& s,
149 SplitKKTResidual& kkt_residual) const override;
150
151 void evalStageCostHessian(Robot& robot, const ContactStatus& contact_status,
152 CostFunctionData& data, const GridInfo& grid_info,
153 const SplitSolution& s,
154 SplitKKTMatrix& kkt_matrix) const override;
155
157 const GridInfo& grid_info, const SplitSolution& s) const override;
158
160 const GridInfo& grid_info, const SplitSolution& s,
161 SplitKKTResidual& kkt_residual) const override;
162
164 const GridInfo& grid_info, const SplitSolution& s,
165 SplitKKTMatrix& kkt_matrix) const override;
166
167 double evalImpactCost(Robot& robot, const ImpactStatus& impact_status,
168 CostFunctionData& data, const GridInfo& grid_info,
169 const SplitSolution& s) const override;
170
171 void evalImpactCostDerivatives(Robot& robot, const ImpactStatus& impact_status,
172 CostFunctionData& data, const GridInfo& grid_info,
173 const SplitSolution& s,
174 SplitKKTResidual& kkt_residual) const override;
175
176 void evalImpactCostHessian(Robot& robot, const ImpactStatus& impact_status,
177 CostFunctionData& data, const GridInfo& grid_info,
178 const SplitSolution& s,
179 SplitKKTMatrix& kkt_matrix) const override;
180
181 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
182
183private:
184 Eigen::Vector3d const_ref_, weight_, weight_terminal_, weight_impact_;
185 std::shared_ptr<CoMRefBase> ref_;
186 bool use_nonconst_ref_, enable_cost_, enable_cost_terminal_, enable_cost_impact_;
187};
188
189} // namespace robotoc
190
191#endif // ROBOTOC_COM_COST_HPP_
Cost on the position of the center of mass.
Definition: com_cost.hpp:24
CoMCost(const CoMCost &)=default
Default copy constructor.
CoMCost(const Robot &robot, const Eigen::Vector3d &const_ref)
Constructor.
void evalDiff(const Robot &robot, CostFunctionData &data, const GridInfo &grid_info) const
Evaluate the difference between the robot's task-space position status and reference.
Definition: com_cost.hpp:129
void evalStageCostHessian(Robot &robot, const ContactStatus &contact_status, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s, SplitKKTMatrix &kkt_matrix) const override
Computes the Hessian, i.e., the second-order partial derivatives of the stage cost....
void evalTerminalCostHessian(Robot &robot, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s, SplitKKTMatrix &kkt_matrix) const override
Computes the Hessian, i.e., the second-order partial derivatives of the teminal cost....
double evalStageCost(Robot &robot, const ContactStatus &contact_status, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s) const override
Computes the stage cost.
void set_ref(const std::shared_ptr< CoMRefBase > &ref)
Sets the reference CoM position.
CoMCost()
Default constructor.
double evalImpactCost(Robot &robot, const ImpactStatus &impact_status, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s) const override
Computes the impact cost.
void evalImpactCostDerivatives(Robot &robot, const ImpactStatus &impact_status, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s, SplitKKTResidual &kkt_residual) const override
Computes the first-order partial derivatives of the impact cost. This function is always called just ...
void set_weight_impact(const Eigen::Vector3d &weight_impact)
Sets the weight vector for the impact stage.
CoMCost(CoMCost &&) noexcept=default
Default move constructor.
void evalStageCostDerivatives(Robot &robot, const ContactStatus &contact_status, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s, SplitKKTResidual &kkt_residual) const override
Computes the first-order partial derivatives of the stage cost. This function is always called just a...
void set_weight_terminal(const Eigen::Vector3d &weight_terminal)
Sets the weight vector for the terminal stage.
void set_weight(const Eigen::Vector3d &weight)
Sets the weight vector.
CoMCost & operator=(const CoMCost &)=default
Default copy operator.
CoMCost(const Robot &robot)
Constructor.
bool isCostActive(const GridInfo &grid_info) const
Evaluate if the cost is active for given grid_info.
Definition: com_cost.hpp:113
double evalTerminalCost(Robot &robot, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s) const override
Computes the terminal cost.
void evalTerminalCostDerivatives(Robot &robot, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s, SplitKKTResidual &kkt_residual) const override
Computes the first-order partial derivatives of the terminal cost. This function is always called jus...
~CoMCost()
Destructor.
void evalImpactCostHessian(Robot &robot, const ImpactStatus &impact_status, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s, SplitKKTMatrix &kkt_matrix) const override
Computes the Hessian, i.e., the second-order partial derivatives of the impact cost....
void set_const_ref(const Eigen::Vector3d &const_ref)
Sets the const reference CoM position.
CoMCost(const Robot &robot, const std::shared_ptr< CoMRefBase > &ref)
Constructor.
Base class of reference position of the center of mass (CoM).
Definition: com_ref_base.hpp:15
Contact status of robot model.
Definition: contact_status.hpp:32
Base class of components of cost function.
Definition: cost_function_component_base.hpp:25
Impact status of robot model. Wrapper of ContactStatus to treat impacts.
Definition: impact_status.hpp:21
Dynamics and kinematics model of robots. Wraps pinocchio::Model and pinocchio::Data....
Definition: robot.hpp:32
const Eigen::Vector3d & CoM() const
Returns the position of the center of mass. Before calling this function, updateKinematics() or updat...
The KKT matrix split into a time stage.
Definition: split_kkt_matrix.hpp:18
KKT residual split into each time stage.
Definition: split_kkt_residual.hpp:18
Solution to the optimal control problem split into a time stage.
Definition: split_solution.hpp:20
Definition: constraint_component_base.hpp:17
Composed of data used to compute the cost function and its derivatives.
Definition: cost_function_data.hpp:17
Eigen::VectorXd x3d_ref
Vector used for set the reference position of the end-effector in TaskSpace3DCost....
Definition: cost_function_data.hpp:76
Eigen::VectorXd diff_3d
Vector used for computing the difference of the position of the end-effector in TaskSpace3DCost....
Definition: cost_function_data.hpp:84
Grid information.
Definition: grid_info.hpp:24