inverse-kinematics-3d.cpp
Go to the documentation of this file.
1 #include <iostream>
2 
8 
9 int main(int /* argc */, char ** /* argv */)
10 {
14 
15  const int JOINT_ID = 6;
16  const pinocchio::SE3 oMdes(Eigen::Matrix3d::Identity(), Eigen::Vector3d(1., 0., 1.));
17 
18  Eigen::VectorXd q = pinocchio::neutral(model);
19  const double eps = 1e-4;
20  const int IT_MAX = 1000;
21  const double DT = 1e-1;
22  const double damp = 1e-12;
23 
24  pinocchio::Data::Matrix6x joint_jacobian(6, model.nv);
25  joint_jacobian.setZero();
26 
27  bool success = false;
28  Eigen::Vector3d err;
29  Eigen::VectorXd v(model.nv);
30  for (int i = 0;; i++)
31  {
33  const pinocchio::SE3 iMd = data.oMi[JOINT_ID].actInv(oMdes);
34  err = iMd.translation(); // in joint frame
35  if (err.norm() < eps)
36  {
37  success = true;
38  break;
39  }
40  if (i >= IT_MAX)
41  {
42  success = false;
43  break;
44  }
46  model, data, q, JOINT_ID, joint_jacobian); // joint_jacobian expressed in the joint frame
47  const auto J = -joint_jacobian.topRows<3>(); // Jacobian associated with the error
48  const Eigen::Matrix3d JJt = J * J.transpose() + damp * Eigen::Matrix3d::Identity();
49  v.noalias() = -J.transpose() * JJt.ldlt().solve(err);
51  if (!(i % 10))
52  std::cout << i << ": error = " << err.transpose() << std::endl;
53  }
54 
55  if (success)
56  {
57  std::cout << "Convergence achieved!" << std::endl;
58  }
59  else
60  {
61  std::cout
62  << "\nWarning: the iterative algorithm has not reached convergence to the desired precision"
63  << std::endl;
64  }
65 
66  std::cout << "\nresult: " << q.transpose() << std::endl;
67  std::cout << "\nfinal error: " << err.transpose() << std::endl;
68 }
inverse-kinematics-3d.success
bool success
Definition: inverse-kinematics-3d.py:23
pinocchio::DataTpl
Definition: context/generic.hpp:25
pinocchio::forwardKinematics
void forwardKinematics(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q)
Update the joint placements according to the current joint configuration.
pinocchio::SE3Tpl
Definition: context/casadi.hpp:29
inverse-kinematics.i
int i
Definition: inverse-kinematics.py:17
kinematics.hpp
dpendulum.DT
int DT
Definition: dpendulum.py:14
setup.data
data
Definition: cmake/cython/setup.in.py:48
inverse-kinematics-3d.J
J
Definition: inverse-kinematics-3d.py:28
explog.hpp
inverse-kinematics-3d.iMd
iMd
Definition: inverse-kinematics-3d.py:20
pinocchio::buildModels::manipulator
void manipulator(ModelTpl< Scalar, Options, JointCollectionTpl > &model)
Create a 6-DOF kinematic chain shoulder-elbow-wrist.
main
int main(int, char **)
Definition: inverse-kinematics-3d.cpp:9
anymal-simulation.model
model
Definition: anymal-simulation.py:8
joint-configuration.hpp
inverse-kinematics-3d.IT_MAX
int IT_MAX
Definition: inverse-kinematics-3d.py:13
pinocchio::integrate
void integrate(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType > &v, const Eigen::MatrixBase< ReturnType > &qout)
Integrate a configuration vector for the specified model for a tangent vector during one unit time.
Definition: joint-configuration.hpp:70
cartpole.v
v
Definition: cartpole.py:153
inverse-kinematics-3d.damp
int damp
Definition: inverse-kinematics-3d.py:15
inverse-kinematics-3d.err
err
Definition: inverse-kinematics-3d.py:21
q
q
inverse-kinematics-3d.oMdes
oMdes
Definition: inverse-kinematics-3d.py:9
pinocchio::computeJointJacobian
void computeJointJacobian(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const JointIndex joint_id, const Eigen::MatrixBase< Matrix6Like > &J)
Computes the Jacobian of a specific joint frame expressed in the local frame of the joint and store t...
dcrba.eps
int eps
Definition: dcrba.py:458
pinocchio::DataTpl::Matrix6x
Eigen::Matrix< Scalar, 6, Eigen::Dynamic, Options > Matrix6x
The 6d jacobian type (temporary)
Definition: multibody/data.hpp:92
inverse-kinematics-3d.JOINT_ID
int JOINT_ID
Definition: inverse-kinematics-3d.py:8
pinocchio::neutral
void neutral(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ReturnType > &qout)
Return the neutral configuration element related to the model configuration space.
Definition: joint-configuration.hpp:363
sample-models.hpp
jacobian.hpp
pinocchio::ModelTpl
Definition: context/generic.hpp:20


pinocchio
Author(s):
autogenerated on Thu Dec 19 2024 03:41:29