robotoc
robotoc - efficient ROBOT Optimal Control solvers
Loading...
Searching...
No Matches
task_space_6d_cost.hpp
Go to the documentation of this file.
1#ifndef ROBOTOC_TASK_SPACE_6D_COST_HPP_
2#define ROBOTOC_TASK_SPACE_6D_COST_HPP_
3
4#include <string>
5
6#include "Eigen/Core"
7
11#include "robotoc/robot/se3.hpp"
18
19
20namespace robotoc {
21
27public:
28 using Vector6d = Eigen::Matrix<double, 6, 1>;
29
35 TaskSpace6DCost(const Robot& robot, const int frame_id);
36
42 TaskSpace6DCost(const Robot& robot, const std::string& frame_name);
49 TaskSpace6DCost(const Robot& robot, const int frame_id,
50 const std::shared_ptr<TaskSpace6DRefBase>& ref);
51
58 TaskSpace6DCost(const Robot& robot, const int frame_id,
59 const SE3& const_ref);
60
68 TaskSpace6DCost(const Robot& robot, const int frame_id,
69 const Eigen::Vector3d& const_position_ref,
70 const Eigen::Matrix3d& const_rotation_ref);
71
78 TaskSpace6DCost(const Robot& robot, const std::string& frame_name,
79 const std::shared_ptr<TaskSpace6DRefBase>& ref);
80
87 TaskSpace6DCost(const Robot& robot, const std::string& frame_name,
88 const SE3& const_ref);
89
97 TaskSpace6DCost(const Robot& robot, const std::string& frame_name,
98 const Eigen::Vector3d& const_position_ref,
99 const Eigen::Matrix3d& const_rotation_ref);
100
105
110
115
120
124 TaskSpace6DCost(TaskSpace6DCost&&) noexcept = default;
125
129 TaskSpace6DCost& operator=(TaskSpace6DCost&&) noexcept = default;
130
135 void set_ref(const std::shared_ptr<TaskSpace6DRefBase>& ref);
136
141 void set_const_ref(const SE3& const_ref);
142
148 void set_const_ref(const Eigen::Vector3d& const_position_ref,
149 const Eigen::Matrix3d& const_rotation_ref);
150
156 void set_weight(const Eigen::Vector3d& weight_position,
157 const Eigen::Vector3d& weight_rotation);
158
166 void set_weight_terminal(const Eigen::Vector3d& weight_position_terminal,
167 const Eigen::Vector3d& weight_rotation_terminal);
168
176 void set_weight_impact(const Eigen::Vector3d& weight_position_impact,
177 const Eigen::Vector3d& weight_rotation_impact);
178
184 bool isCostActive(const GridInfo& grid_info) const {
185 if (use_nonconst_ref_) {
186 return ref_->isActive(grid_info);
187 }
188 else {
189 return true;
190 }
191 }
192
200 void evalDiff(const Robot& robot, CostFunctionData& data,
201 const GridInfo& grid_info) const {
202 if (use_nonconst_ref_) {
203 if (ref_->isActive(grid_info)) {
204 ref_->updateRef(grid_info, data.x6d_ref);
205 data.x6d_ref_inv = data.x6d_ref.inverse();
206 data.diff_x6d = data.x6d_ref_inv * robot.framePlacement(frame_id_);
207 data.diff_6d = Log6Map(data.diff_x6d);
208 }
209 }
210 else {
211 data.diff_x6d = const_ref_inv_ * robot.framePlacement(frame_id_);
212 data.diff_6d = Log6Map(data.diff_x6d);
213 }
214 }
215
216 double evalStageCost(Robot& robot, const ContactStatus& contact_status,
217 CostFunctionData& data, const GridInfo& grid_info,
218 const SplitSolution& s) const override;
219
220 void evalStageCostDerivatives(Robot& robot, const ContactStatus& contact_status,
221 CostFunctionData& data, const GridInfo& grid_info,
222 const SplitSolution& s,
223 SplitKKTResidual& kkt_residual) const override;
224
225 void evalStageCostHessian(Robot& robot, const ContactStatus& contact_status,
226 CostFunctionData& data, const GridInfo& grid_info,
227 const SplitSolution& s,
228 SplitKKTMatrix& kkt_matrix) const override;
229
231 const GridInfo& grid_info,
232 const SplitSolution& s) const override;
233
235 const GridInfo& grid_info,
236 const SplitSolution& s,
237 SplitKKTResidual& kkt_residual) const override;
238
240 const GridInfo& grid_info,
241 const SplitSolution& s,
242 SplitKKTMatrix& kkt_matrix) const override;
243
244 double evalImpactCost(Robot& robot, const ImpactStatus& impact_status,
245 CostFunctionData& data, const GridInfo& grid_info,
246 const SplitSolution& s) const override;
247
248 void evalImpactCostDerivatives(Robot& robot, const ImpactStatus& impact_status,
249 CostFunctionData& data, const GridInfo& grid_info,
250 const SplitSolution& s,
251 SplitKKTResidual& kkt_residual) const override;
252
253 void evalImpactCostHessian(Robot& robot, const ImpactStatus& impact_status,
254 CostFunctionData& data, const GridInfo& grid_info,
255 const SplitSolution& s,
256 SplitKKTMatrix& kkt_matrix) const override;
257
258 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
259
260private:
261 int frame_id_;
262 SE3 const_ref_, const_ref_inv_;
263 Eigen::VectorXd weight_, weight_terminal_, weight_impact_;
264 std::shared_ptr<TaskSpace6DRefBase> ref_;
265 bool use_nonconst_ref_, enable_cost_, enable_cost_terminal_, enable_cost_impact_;
266};
267
268} // namespace robotoc
269
270
271#endif // ROBOTOC_TASK_SPACE_6D_COST_HPP_
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 SE3 & framePlacement(const int frame_id) const
Returns the SE(3) of the frame. Before calling this function, updateKinematics() or updateFrameKinema...
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
Cost on the task space placement (SE(3)).
Definition: task_space_6d_cost.hpp:26
TaskSpace6DCost(const Robot &robot, const int frame_id, const std::shared_ptr< TaskSpace6DRefBase > &ref)
Constructor.
TaskSpace6DCost(const Robot &robot, const std::string &frame_name)
Constructor.
TaskSpace6DCost(const TaskSpace6DCost &)=default
Default copy constructor.
Eigen::Matrix< double, 6, 1 > Vector6d
Definition: task_space_6d_cost.hpp:28
void set_ref(const std::shared_ptr< TaskSpace6DRefBase > &ref)
Sets the reference task-space placement.
TaskSpace6DCost(const Robot &robot, const int frame_id)
Constructor.
TaskSpace6DCost(const Robot &robot, const std::string &frame_name, const SE3 &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: task_space_6d_cost.hpp:200
void set_weight(const Eigen::Vector3d &weight_position, const Eigen::Vector3d &weight_rotation)
Sets the weight vector.
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 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...
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...
bool isCostActive(const GridInfo &grid_info) const
Evaluate if the cost is active for given grid_info.
Definition: task_space_6d_cost.hpp:184
TaskSpace6DCost(const Robot &robot, const int frame_id, const SE3 &const_ref)
Constructor.
double evalTerminalCost(Robot &robot, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s) const override
Computes the terminal cost.
void set_weight_terminal(const Eigen::Vector3d &weight_position_terminal, const Eigen::Vector3d &weight_rotation_terminal)
Sets the weight vector at the terminal stage.
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....
double evalStageCost(Robot &robot, const ContactStatus &contact_status, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s) const override
Computes 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....
TaskSpace6DCost(const Robot &robot, const std::string &frame_name, const Eigen::Vector3d &const_position_ref, const Eigen::Matrix3d &const_rotation_ref)
Constructor.
void set_weight_impact(const Eigen::Vector3d &weight_position_impact, const Eigen::Vector3d &weight_rotation_impact)
Sets the weight vector at the impact stage.
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_const_ref(const SE3 &const_ref)
Sets the const reference task-space placement.
double evalImpactCost(Robot &robot, const ImpactStatus &impact_status, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s) const override
Computes the impact cost.
TaskSpace6DCost()
Default constructor.
~TaskSpace6DCost()
Destructor.
TaskSpace6DCost(const Robot &robot, const std::string &frame_name, const std::shared_ptr< TaskSpace6DRefBase > &ref)
Constructor.
TaskSpace6DCost(TaskSpace6DCost &&) noexcept=default
Default move constructor.
TaskSpace6DCost(const Robot &robot, const int frame_id, const Eigen::Vector3d &const_position_ref, const Eigen::Matrix3d &const_rotation_ref)
Constructor.
TaskSpace6DCost & operator=(const TaskSpace6DCost &)=default
Default copy operator.
Base class of reference task space placement (position and orientation).
Definition: task_space_6d_ref_base.hpp:16
Definition: constraint_component_base.hpp:17
const Eigen::Matrix< double, 6, 1 > Log6Map(const SE3Type &SE3_obj)
Applies Log6 map that transforms the SE3 into 6-dimensional vector.
Definition: se3.hpp:23
pinocchio::SE3 SE3
Using pinocchio::SE3 without its namespace.
Definition: se3.hpp:15
Composed of data used to compute the cost function and its derivatives.
Definition: cost_function_data.hpp:17
Eigen::VectorXd diff_6d
Vector used for computing the difference of the position and rotation of the end-effector in TaskSpac...
Definition: cost_function_data.hpp:92
SE3 x6d_ref_inv
Vector used for computing the inverse of the reference SE3 of the end-effector in TaskSpace6DCost.
Definition: cost_function_data.hpp:104
SE3 diff_x6d
Vector used for computing the difference of the SE3 of the end-effector in TaskSpace6DCost....
Definition: cost_function_data.hpp:111
SE3 x6d_ref
Vector used for computing the reference SE3 of the end-effector in TaskSpace6DCost.
Definition: cost_function_data.hpp:98
Grid information.
Definition: grid_info.hpp:24