inverse-kinematics.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-6;
23 
25  J.setZero();
26 
27  bool success = false;
28  typedef Eigen::Matrix<double, 6, 1> Vector6d;
29  Vector6d err;
30  Eigen::VectorXd v(model.nv);
31  for (int i = 0;; i++)
32  {
34  const pinocchio::SE3 iMd = data.oMi[JOINT_ID].actInv(oMdes);
35  err = pinocchio::log6(iMd).toVector(); // in joint frame
36  if (err.norm() < eps)
37  {
38  success = true;
39  break;
40  }
41  if (i >= IT_MAX)
42  {
43  success = false;
44  break;
45  }
46  pinocchio::computeJointJacobian(model, data, q, JOINT_ID, J); // J in joint frame
48  pinocchio::Jlog6(iMd.inverse(), Jlog);
49  J = -Jlog * J;
51  JJt.noalias() = J * J.transpose();
52  JJt.diagonal().array() += damp;
53  v.noalias() = -J.transpose() * JJt.ldlt().solve(err);
55  if (!(i % 10))
56  std::cout << i << ": error = " << err.transpose() << std::endl;
57  }
58 
59  if (success)
60  {
61  std::cout << "Convergence achieved!" << std::endl;
62  }
63  else
64  {
65  std::cout
66  << "\nWarning: the iterative algorithm has not reached convergence to the desired precision"
67  << std::endl;
68  }
69 
70  std::cout << "\nresult: " << q.transpose() << std::endl;
71  std::cout << "\nfinal error: " << err.transpose() << std::endl;
72 }
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::Jlog6
void Jlog6(const SE3Tpl< Scalar, Options > &M, const Eigen::MatrixBase< Matrix6Like > &Jlog)
Derivative of log6.
Definition: spatial/explog.hpp:668
pinocchio::buildModels::manipulator
void manipulator(ModelTpl< Scalar, Options, JointCollectionTpl > &model)
Create a 6-DOF kinematic chain shoulder-elbow-wrist.
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::log6
MotionTpl< Scalar, Options > log6(const SE3Tpl< Scalar, Options > &M)
Log: SE3 -> se3.
Definition: spatial/explog.hpp:435
main
int main(int, char **)
Definition: inverse-kinematics.cpp: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...
pinocchio::DataTpl::Matrix6
Eigen::Matrix< Scalar, 6, 6, Options > Matrix6
Definition: multibody/data.hpp:96
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