robotoc
robotoc - efficient ROBOT Optimal Control solvers
Loading...
Searching...
No Matches
point_contact.hxx
Go to the documentation of this file.
1#ifndef ROBOTOC_POINT_CONTACT_HXX_
2#define ROBOTOC_POINT_CONTACT_HXX_
3
5
6#include "pinocchio/algorithm/joint-configuration.hpp"
7#include "pinocchio/algorithm/frames.hpp"
8#include "pinocchio/algorithm/kinematics-derivatives.hpp"
9#include "pinocchio/algorithm/frames-derivatives.hpp"
10
11#include <cassert>
12
13
14namespace robotoc {
15
16template <typename VectorType1, typename VectorType2>
18 const pinocchio::Model& model, const pinocchio::Data& data,
19 const Eigen::MatrixBase<VectorType1>& desired_contact_position,
20 const Eigen::MatrixBase<VectorType2>& baumgarte_residual) const {
21 assert(desired_contact_position.size() == 3);
22 assert(baumgarte_residual.size() == 3);
23 const_cast<Eigen::MatrixBase<VectorType2>&> (baumgarte_residual).noalias()
24 = pinocchio::getFrameClassicalAcceleration(model, data, contact_frame_id_,
25 pinocchio::LOCAL).linear();
26 (const_cast<Eigen::MatrixBase<VectorType2>&> (baumgarte_residual)).noalias()
28 * pinocchio::getFrameVelocity(model, data, contact_frame_id_,
29 pinocchio::LOCAL).linear();
30 (const_cast<Eigen::MatrixBase<VectorType2>&> (baumgarte_residual)).noalias()
32 * (data.oMf[contact_frame_id_].translation()-desired_contact_position);
33}
34
35
36template <typename MatrixType1, typename MatrixType2, typename MatrixType3>
38 const pinocchio::Model& model, pinocchio::Data& data,
39 const Eigen::MatrixBase<MatrixType1>& baumgarte_partial_dq,
40 const Eigen::MatrixBase<MatrixType2>& baumgarte_partial_dv,
41 const Eigen::MatrixBase<MatrixType3>& baumgarte_partial_da) {
42 assert(baumgarte_partial_dq.cols() == dimv_);
43 assert(baumgarte_partial_dv.cols() == dimv_);
44 assert(baumgarte_partial_da.cols() == dimv_);
45 assert(baumgarte_partial_dq.rows() == 3);
46 assert(baumgarte_partial_dv.rows() == 3);
47 assert(baumgarte_partial_da.rows() == 3);
48 pinocchio::getFrameAccelerationDerivatives(model, data, contact_frame_id_,
49 pinocchio::LOCAL,
50 frame_v_partial_dq_,
51 frame_a_partial_dq_,
52 frame_a_partial_dv_,
53 frame_a_partial_da_);
54 // Skew matrices and LOCAL frame Jacobian are needed to convert the
55 // frame acceleration derivatives into the "classical" acceleration
56 // derivatives.
57 pinocchio::getFrameJacobian(model, data, contact_frame_id_,
58 pinocchio::LOCAL, J_frame_);
59 v_frame_ = pinocchio::getFrameVelocity(model, data, contact_frame_id_,
60 pinocchio::LOCAL);
61 pinocchio::skew(v_frame_.linear(), v_linear_skew_);
62 pinocchio::skew(v_frame_.angular(), v_angular_skew_);
63 const_cast<Eigen::MatrixBase<MatrixType1>&> (baumgarte_partial_dq)
64 = frame_a_partial_dq_.template topRows<3>();
65 const_cast<Eigen::MatrixBase<MatrixType1>&> (baumgarte_partial_dq).noalias()
66 += v_angular_skew_ * frame_v_partial_dq_.template topRows<3>();
67 const_cast<Eigen::MatrixBase<MatrixType1>&> (baumgarte_partial_dq).noalias()
68 -= v_linear_skew_ * frame_v_partial_dq_.template bottomRows<3>();
69 const_cast<Eigen::MatrixBase<MatrixType2>&> (baumgarte_partial_dv)
70 = frame_a_partial_dv_.template topRows<3>();
71 const_cast<Eigen::MatrixBase<MatrixType2>&> (baumgarte_partial_dv).noalias()
72 += v_angular_skew_ * J_frame_.template topRows<3>();
73 const_cast<Eigen::MatrixBase<MatrixType2>&> (baumgarte_partial_dv).noalias()
74 -= v_linear_skew_ * J_frame_.template bottomRows<3>();
75 const_cast<Eigen::MatrixBase<MatrixType3>&> (baumgarte_partial_da)
76 = frame_a_partial_da_.template topRows<3>();
77 (const_cast<Eigen::MatrixBase<MatrixType1>&> (baumgarte_partial_dq)).noalias()
79 * frame_v_partial_dq_.template topRows<3>();
80 (const_cast<Eigen::MatrixBase<MatrixType2>&> (baumgarte_partial_dv)).noalias()
82 * frame_a_partial_da_.template topRows<3>();
83 (const_cast<Eigen::MatrixBase<MatrixType1>&> (baumgarte_partial_dq)).noalias()
84 += info_.baumgarte_position_gain * data.oMf[contact_frame_id_].rotation()
85 * J_frame_.template topRows<3>();
86}
87
88
89template <typename VectorType>
91 const pinocchio::Model& model, const pinocchio::Data& data,
92 const Eigen::MatrixBase<VectorType>& velocity_residual) const {
93 assert(velocity_residual.size() == 3);
94 const_cast<Eigen::MatrixBase<VectorType>&> (velocity_residual).noalias()
95 = pinocchio::getFrameVelocity(model, data, contact_frame_id_,
96 pinocchio::LOCAL).linear();
97}
98
99
100template <typename MatrixType1, typename MatrixType2>
102 const pinocchio::Model& model, pinocchio::Data& data,
103 const Eigen::MatrixBase<MatrixType1>& velocity_partial_dq,
104 const Eigen::MatrixBase<MatrixType2>& velocity_partial_dv) {
105 assert(velocity_partial_dq.cols() == dimv_);
106 assert(velocity_partial_dv.cols() == dimv_);
107 assert(velocity_partial_dq.rows() == 3);
108 assert(velocity_partial_dv.rows() == 3);
109 pinocchio::getFrameVelocityDerivatives(model, data, contact_frame_id_,
110 pinocchio::LOCAL,
111 frame_v_partial_dq_,
112 frame_a_partial_da_);
113 (const_cast<Eigen::MatrixBase<MatrixType1>&> (velocity_partial_dq)).noalias()
114 = frame_v_partial_dq_.template topRows<3>();
115 (const_cast<Eigen::MatrixBase<MatrixType2>&> (velocity_partial_dv)).noalias()
116 = frame_a_partial_da_.template topRows<3>();
117}
118
119
120template <typename VectorType1, typename VectorType2>
122 const pinocchio::Model& model, const pinocchio::Data& data,
123 const Eigen::MatrixBase<VectorType1>& desired_contact_position,
124 const Eigen::MatrixBase<VectorType2>& position_residual) const {
125 assert(desired_contact_position.size() == 3);
126 assert(position_residual.size() == 3);
127 (const_cast<Eigen::MatrixBase<VectorType2>&> (position_residual))
128 = (data.oMf[contact_frame_id_].translation()-desired_contact_position);
129}
130
131
132template <typename MatrixType>
134 const pinocchio::Model& model, pinocchio::Data& data,
135 const Eigen::MatrixBase<MatrixType>& position_partial_dq) {
136 assert(position_partial_dq.cols() == dimv_);
137 assert(position_partial_dq.rows() == 3);
138 pinocchio::getFrameJacobian(model, data, contact_frame_id_,
139 pinocchio::LOCAL, J_frame_);
140 (const_cast<Eigen::MatrixBase<MatrixType>&> (position_partial_dq)).noalias()
141 = data.oMf[contact_frame_id_].rotation() * J_frame_.template topRows<3>();
142}
143
144} // namespace robotoc
145
146#endif // ROBOTOC_POINT_CONTACT_HXX_
void computeBaumgarteResidual(const pinocchio::Model &model, const pinocchio::Data &data, const Eigen::MatrixBase< VectorType1 > &desired_contact_position, const Eigen::MatrixBase< VectorType2 > &baumgarte_residual) const
Computes the residual of the contact constraints considered by the Baumgarte's stabilization method....
Definition: point_contact.hxx:17
void computeContactVelocityDerivatives(const pinocchio::Model &model, pinocchio::Data &data, const Eigen::MatrixBase< MatrixType1 > &velocity_partial_dq, const Eigen::MatrixBase< MatrixType2 > &velocity_partial_dv)
Computes the partial derivatives of the contact velocity constraints. Before calling this function,...
Definition: point_contact.hxx:101
void computeContactPositionResidual(const pinocchio::Model &model, const pinocchio::Data &data, const Eigen::MatrixBase< VectorType1 > &desired_contact_position, const Eigen::MatrixBase< VectorType2 > &position_residual) const
Computes the residual of the contact position constraints. Before calling this function,...
Definition: point_contact.hxx:121
void computeBaumgarteDerivatives(const pinocchio::Model &model, pinocchio::Data &data, const Eigen::MatrixBase< MatrixType1 > &baumgarte_partial_dq, const Eigen::MatrixBase< MatrixType2 > &baumgarte_partial_dv, const Eigen::MatrixBase< MatrixType3 > &baumgarte_partial_da)
Computes the partial derivatives of the contact constraints considered by the Baumgarte's stabilizati...
Definition: point_contact.hxx:37
void computeContactVelocityResidual(const pinocchio::Model &model, const pinocchio::Data &data, const Eigen::MatrixBase< VectorType > &velocity_residual) const
Computes the residual of the contact velocity constraints. Before calling this function,...
Definition: point_contact.hxx:90
void computeContactPositionDerivative(const pinocchio::Model &model, pinocchio::Data &data, const Eigen::MatrixBase< MatrixType > &position_partial_dq)
Computes the partial derivative of the contact position constraint with respect to the configuratio...
Definition: point_contact.hxx:133
Definition: constraint_component_base.hpp:17
double baumgarte_velocity_gain
The velocity gain of the Baumgarte's stabilization method. Default is 0.0.
Definition: contact_model_info.hpp:78
double baumgarte_position_gain
The position gain of the Baumgarte's stabilization method. Default is 0.0.
Definition: contact_model_info.hpp:72