robotoc
robotoc - efficient ROBOT Optimal Control solvers
Loading...
Searching...
No Matches
task_space_3d_cost.hpp
Go to the documentation of this file.
1#ifndef ROBOTOC_TASK_SPACE_3D_COST_HPP_
2#define ROBOTOC_TASK_SPACE_3D_COST_HPP_
3
4#include <string>
5
6#include "Eigen/Core"
7
18
19
20namespace robotoc {
21
27public:
33 TaskSpace3DCost(const Robot& robot, const int frame_id);
34
40 TaskSpace3DCost(const Robot& robot, const std::string& frame_name);
41
48 TaskSpace3DCost(const Robot& robot, const int frame_id,
49 const std::shared_ptr<TaskSpace3DRefBase>& ref);
50
57 TaskSpace3DCost(const Robot& robot, const int frame_id,
58 const Eigen::Vector3d& const_ref);
59
66 TaskSpace3DCost(const Robot& robot, const std::string& frame_name,
67 const std::shared_ptr<TaskSpace3DRefBase>& ref);
68
75 TaskSpace3DCost(const Robot& robot, const std::string& frame_name,
76 const Eigen::Vector3d& const_ref);
77
82
87
92
97
101 TaskSpace3DCost(TaskSpace3DCost&&) noexcept = default;
102
106 TaskSpace3DCost& operator=(TaskSpace3DCost&&) noexcept = default;
107
112 void set_ref(const std::shared_ptr<TaskSpace3DRefBase>& ref);
113
118 void set_const_ref(const Eigen::Vector3d& const_ref);
119
124 void set_weight(const Eigen::Vector3d& weight);
125
131 void set_weight_terminal(const Eigen::Vector3d& weight_terminal);
132
138 void set_weight_impact(const Eigen::Vector3d& weight_impact);
139
145 bool isCostActive(const GridInfo& grid_info) const {
146 if (use_nonconst_ref_) {
147 return ref_->isActive(grid_info);
148 }
149 else {
150 return true;
151 }
152 }
153
161 void evalDiff(const Robot& robot, CostFunctionData& data,
162 const GridInfo& grid_info) const {
163 if (use_nonconst_ref_) {
164 if (ref_->isActive(grid_info)) {
165 ref_->updateRef(grid_info, data.x3d_ref);
166 data.diff_3d = robot.framePosition(frame_id_) - data.x3d_ref;
167 }
168 }
169 else {
170 data.diff_3d = robot.framePosition(frame_id_) - const_ref_;
171 }
172 }
173
174 double evalStageCost(Robot& robot, const ContactStatus& contact_status,
175 CostFunctionData& data, const GridInfo& grid_info,
176 const SplitSolution& s) const override;
177
178 void evalStageCostDerivatives(Robot& robot, const ContactStatus& contact_status,
179 CostFunctionData& data, const GridInfo& grid_info,
180 const SplitSolution& s,
181 SplitKKTResidual& kkt_residual) const override;
182
183 void evalStageCostHessian(Robot& robot, const ContactStatus& contact_status,
184 CostFunctionData& data, const GridInfo& grid_info,
185 const SplitSolution& s,
186 SplitKKTMatrix& kkt_matrix) const override;
187
189 const GridInfo& grid_info,
190 const SplitSolution& s) const override;
191
193 const GridInfo& grid_info,
194 const SplitSolution& s,
195 SplitKKTResidual& kkt_residual) const override;
196
198 const GridInfo& grid_info,
199 const SplitSolution& s,
200 SplitKKTMatrix& kkt_matrix) const override;
201
202 double evalImpactCost(Robot& robot, const ImpactStatus& impact_status,
203 CostFunctionData& data, const GridInfo& grid_info,
204 const SplitSolution& s) const override;
205
206 void evalImpactCostDerivatives(Robot& robot, const ImpactStatus& impact_status,
207 CostFunctionData& data, const GridInfo& grid_info,
208 const SplitSolution& s,
209 SplitKKTResidual& kkt_residual) const override;
210
211 void evalImpactCostHessian(Robot& robot, const ImpactStatus& impact_status,
212 CostFunctionData& data, const GridInfo& grid_info,
213 const SplitSolution& s,
214 SplitKKTMatrix& kkt_matrix) const override;
215
216 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
217
218private:
219 int frame_id_;
220 Eigen::Vector3d const_ref_, weight_, weight_terminal_, weight_impact_;
221 std::shared_ptr<TaskSpace3DRefBase> ref_;
222 bool use_nonconst_ref_, enable_cost_, enable_cost_terminal_, enable_cost_impact_;
223};
224
225} // namespace robotoc
226
227
228#endif // ROBOTOC_TASK_SPACE_3D_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 Eigen::Vector3d & framePosition(const int frame_id) const
Returns the position of the frame. Before calling this function, updateKinematics() or updateFrameKin...
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 position.
Definition: task_space_3d_cost.hpp:26
TaskSpace3DCost(const Robot &robot, const int frame_id)
Constructor.
TaskSpace3DCost(const Robot &robot, const std::string &frame_name, const std::shared_ptr< TaskSpace3DRefBase > &ref)
Constructor.
~TaskSpace3DCost()
Destructor.
TaskSpace3DCost & operator=(const TaskSpace3DCost &)=default
Default copy operator.
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 set_const_ref(const Eigen::Vector3d &const_ref)
Sets the const reference task-space position.
TaskSpace3DCost(const Robot &robot, const std::string &frame_name, const Eigen::Vector3d &const_ref)
Constructor.
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 ...
TaskSpace3DCost(TaskSpace3DCost &&) 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...
TaskSpace3DCost(const TaskSpace3DCost &)=default
Default copy constructor.
void set_weight(const Eigen::Vector3d &weight)
Sets the weight vector.
TaskSpace3DCost(const Robot &robot, const std::string &frame_name)
Constructor.
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 evalTerminalCost(Robot &robot, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s) const override
Computes the terminal 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 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....
TaskSpace3DCost(const Robot &robot, const int frame_id, const Eigen::Vector3d &const_ref)
Constructor.
void set_ref(const std::shared_ptr< TaskSpace3DRefBase > &ref)
Sets the reference task-space position.
bool isCostActive(const GridInfo &grid_info) const
Evaluate if the cost is active for given grid_info.
Definition: task_space_3d_cost.hpp:145
void set_weight_impact(const Eigen::Vector3d &weight_impact)
Sets the weight vector for the impact stage.
TaskSpace3DCost()
Default constructor.
void set_weight_terminal(const Eigen::Vector3d &weight_terminal)
Sets the weight vector for the terminal stage.
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....
double evalImpactCost(Robot &robot, const ImpactStatus &impact_status, CostFunctionData &data, const GridInfo &grid_info, const SplitSolution &s) const override
Computes the impact cost.
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_3d_cost.hpp:161
TaskSpace3DCost(const Robot &robot, const int frame_id, const std::shared_ptr< TaskSpace3DRefBase > &ref)
Constructor.
Base class of reference task space position.
Definition: task_space_3d_ref_base.hpp:15
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