robotoc
robotoc - efficient ROBOT Optimal Control solvers
Loading...
Searching...
No Matches
configuration_space_cost.hpp
Go to the documentation of this file.
1#ifndef ROBOTOC_CONFIGURATION_SPACE_COST_HPP_
2#define ROBOTOC_CONFIGURATION_SPACE_COST_HPP_
3
4#include "Eigen/Core"
5
15
16
17namespace robotoc {
18
24public:
25 using Vector6d = Eigen::Matrix<double, 6, 1>;
26
32
39 const std::shared_ptr<ConfigurationSpaceRefBase>& ref);
40
45
50
55
60
65
69 ConfigurationSpaceCost& operator=(ConfigurationSpaceCost&&) noexcept = default;
70
75 void set_ref(const std::shared_ptr<ConfigurationSpaceRefBase>& ref);
76
81 void set_q_ref(const Eigen::VectorXd& q_ref);
82
87 void set_v_ref(const Eigen::VectorXd& v_ref);
88
94 void set_u_ref(const Eigen::VectorXd& u_ref);
95
101 void set_q_weight(const Eigen::VectorXd& q_weight);
102
108 void set_v_weight(const Eigen::VectorXd& v_weight);
109
115 void set_a_weight(const Eigen::VectorXd& a_weight);
116
122 void set_u_weight(const Eigen::VectorXd& u_weight);
123
129 void set_q_weight_terminal(const Eigen::VectorXd& q_weight_terminal);
130
136 void set_v_weight_terminal(const Eigen::VectorXd& v_weight_terminal);
137
143 void set_q_weight_impact(const Eigen::VectorXd& q_weight_impact);
144
150 void set_v_weight_impact(const Eigen::VectorXd& v_weight_impact);
151
158 void set_dv_weight_impact(const Eigen::VectorXd& dv_weight_impact);
159
166 bool isCostConfigActive(const GridInfo& grid_info) const {
167 if (use_nonconst_ref_) {
168 return ref_->isActive(grid_info);
169 }
170 else {
171 return true;
172 }
173 }
174
183 void evalConfigDiff(const Robot& robot, CostFunctionData& data,
184 const GridInfo& grid_info,
185 const Eigen::VectorXd& q) const {
186 if (use_nonconst_ref_) {
187 if (ref_->isActive(grid_info)) {
188 ref_->updateRef(robot, grid_info, data.q_ref);
189 robot.subtractConfiguration(q, data.q_ref, data.qdiff);
190 }
191 }
192 else {
193 robot.subtractConfiguration(q, q_ref_, data.qdiff);
194 }
195 }
196
205 void evalConfigDiffJac(const Robot& robot, CostFunctionData& data,
206 const GridInfo& grid_info,
207 const Eigen::VectorXd& q) const {
208 if (use_nonconst_ref_) {
209 if (ref_->isActive(grid_info)) {
210 robot.dSubtractConfiguration_dqf(q, data.q_ref, data.J_qdiff);
211 }
212 }
213 else {
214 robot.dSubtractConfiguration_dqf(q, q_ref_, data.J_qdiff);
215 }
216 }
217
218 double evalStageCost(Robot& robot, const ContactStatus& contact_status,
219 CostFunctionData& data, const GridInfo& grid_info,
220 const SplitSolution& s) const override;
221
222 void evalStageCostDerivatives(Robot& robot, const ContactStatus& contact_status,
223 CostFunctionData& data, const GridInfo& grid_info,
224 const SplitSolution& s,
225 SplitKKTResidual& kkt_residual) const override;
226
227 void evalStageCostHessian(Robot& robot, const ContactStatus& contact_status,
228 CostFunctionData& data, const GridInfo& grid_info,
229 const SplitSolution& s,
230 SplitKKTMatrix& kkt_matrix) const override;
231
233 const GridInfo& grid_info, const SplitSolution& s) const override;
234
236 const GridInfo& grid_info, const SplitSolution& s,
237 SplitKKTResidual& kkt_residual) const override;
238
240 const GridInfo& grid_info, const SplitSolution& s,
241 SplitKKTMatrix& kkt_matrix) const override;
242
243 double evalImpactCost(Robot& robot, const ImpactStatus& impact_status,
244 CostFunctionData& data, const GridInfo& grid_info,
245 const SplitSolution& s) const override;
246
247 void evalImpactCostDerivatives(Robot& robot, const ImpactStatus& impact_status,
248 CostFunctionData& data, const GridInfo& grid_info,
249 const SplitSolution& s,
250 SplitKKTResidual& kkt_residual) const override;
251
252 void evalImpactCostHessian(Robot& robot, const ImpactStatus& impact_status,
253 CostFunctionData& data, const GridInfo& grid_info,
254 const SplitSolution& s,
255 SplitKKTMatrix& kkt_matrix) const override;
256
257private:
258 int dimq_, dimv_, dimu_;
259 Eigen::VectorXd q_ref_, v_ref_, u_ref_,
260 q_weight_, v_weight_, a_weight_, u_weight_,
261 q_weight_terminal_, v_weight_terminal_,
262 q_weight_impact_, v_weight_impact_, dv_weight_impact_;
263 std::shared_ptr<ConfigurationSpaceRefBase> ref_;
264 bool use_nonconst_ref_,
265 enable_q_cost_, enable_v_cost_, enable_a_cost_, enable_u_cost_,
266 enable_q_cost_terminal_, enable_v_cost_terminal_,
267 enable_q_cost_impact_, enable_v_cost_impact_, enable_dv_cost_impact_;
268};
269
270} // namespace robotoc
271
272
273#endif // ROBOTOC_CONFIGURATION_SPACE_COST_HPP_
Configuration space cost.
Definition: configuration_space_cost.hpp:23
bool isCostConfigActive(const GridInfo &grid_info) const
Evaluate if the cost on the configuration q is active for given grid_info.
Definition: configuration_space_cost.hpp:166
void evalConfigDiffJac(const Robot &robot, CostFunctionData &data, const GridInfo &grid_info, const Eigen::VectorXd &q) const
Evaluate the Jacobian of the difference between the configuration and the reference configuration.
Definition: configuration_space_cost.hpp:205
void set_v_ref(const Eigen::VectorXd &v_ref)
Sets the const reference velocity v.
void set_q_weight(const Eigen::VectorXd &q_weight)
Sets the weight vector on the configuration q.
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_u_weight(const Eigen::VectorXd &u_weight)
Sets the weight on the control input torques u.
ConfigurationSpaceCost(const Robot &robot, const std::shared_ptr< ConfigurationSpaceRefBase > &ref)
Constructor.
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...
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_a_weight(const Eigen::VectorXd &a_weight)
Sets the weight on the acceleration a.
ConfigurationSpaceCost(const ConfigurationSpaceCost &)=default
Default copy constructor.
ConfigurationSpaceCost(ConfigurationSpaceCost &&) noexcept=default
Default move constructor.
void set_v_weight(const Eigen::VectorXd &v_weight)
Sets the weight on the velocity v.
ConfigurationSpaceCost & operator=(const ConfigurationSpaceCost &)=default
Default copy operator.
ConfigurationSpaceCost(const Robot &robot)
Constructor.
void set_q_weight_impact(const Eigen::VectorXd &q_weight_impact)
Sets the weight vector on the configuration q at impact stages.
void evalConfigDiff(const Robot &robot, CostFunctionData &data, const GridInfo &grid_info, const Eigen::VectorXd &q) const
Evaluate the difference between the configuration and the reference configuration.
Definition: configuration_space_cost.hpp:183
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_dv_weight_impact(const Eigen::VectorXd &dv_weight_impact)
Sets the weight vector on the impact change in the velocity dv at the impact stages.
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 set_v_weight_terminal(const Eigen::VectorXd &v_weight_terminal)
Sets the weight vector on the velocity v at the terminal stage.
void set_v_weight_impact(const Eigen::VectorXd &v_weight_impact)
Sets the weight vector on the velocity v at the impact stages.
void set_ref(const std::shared_ptr< ConfigurationSpaceRefBase > &ref)
Sets the reference configuration.
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....
void set_u_ref(const Eigen::VectorXd &u_ref)
Sets the const reference control input torques u.
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 ...
double evalImpactCost(Robot &robot, const ImpactStatus &impact_status, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s) const override
Computes the impact cost.
void set_q_weight_terminal(const Eigen::VectorXd &q_weight_terminal)
Sets the weight vector on the configuration q at the terminal stage.
double evalTerminalCost(Robot &robot, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s) const override
Computes the terminal cost.
ConfigurationSpaceCost()
Default constructor.
void set_q_ref(const Eigen::VectorXd &q_ref)
Sets the const reference configuration q.
Eigen::Matrix< double, 6, 1 > Vector6d
Definition: configuration_space_cost.hpp:25
Base class of the configuration.
Definition: configuration_space_ref_base.hpp:16
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
void subtractConfiguration(const Eigen::MatrixBase< ConfigVectorType1 > &qf, const Eigen::MatrixBase< ConfigVectorType2 > &q0, const Eigen::MatrixBase< TangentVectorType > &qdiff) const
Computes qf - q0 at the tangent space. The result means that the unit velocity from initial configura...
Definition: robot.hxx:97
void dSubtractConfiguration_dqf(const Eigen::MatrixBase< ConfigVectorType1 > &qf, const Eigen::MatrixBase< ConfigVectorType2 > &q0, const Eigen::MatrixBase< MatrixType > &dqdiff_dqf) const
Computes the partial derivative of the function of subtraction qf - q0 w.r.t. the terminal configurat...
Definition: robot.hxx:112
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::MatrixXd J_qdiff
Jacobian of the difference of the configurations used in JointSpaceCost. Be allocated only when Robot...
Definition: cost_function_data.hpp:119
Eigen::VectorXd q_ref
Vector used for computing the time-varying reference configuration in ConfigurationCost....
Definition: cost_function_data.hpp:68
Eigen::VectorXd qdiff
Vector used for computing the difference of the configurations in JointSpaceCost. Be allocated only w...
Definition: cost_function_data.hpp:61
Grid information.
Definition: grid_info.hpp:24