inverse-kinematics-3d.py
Go to the documentation of this file.
1 import numpy as np
2 import pinocchio
3 from numpy.linalg import norm, solve
4 
5 model = pinocchio.buildSampleModelManipulator()
6 data = model.createData()
7 
8 JOINT_ID = 6
9 oMdes = pinocchio.SE3(np.eye(3), np.array([1.0, 0.0, 1.0]))
10 
12 eps = 1e-4
13 IT_MAX = 1000
14 DT = 1e-1
15 damp = 1e-12
16 
17 it = 0
18 while True:
19  pinocchio.forwardKinematics(model, data, q)
20  iMd = data.oMi[JOINT_ID].actInv(oMdes)
21  err = iMd.translation
22  if norm(err) < eps:
23  success = True
24  break
25  if it >= IT_MAX:
26  success = False
27  break
28  J = pinocchio.computeJointJacobian(model, data, q, JOINT_ID) # in joint frame
29  J = -J[:3, :] # linear part of the Jacobian
30  v = -J.T.dot(solve(J.dot(J.T) + damp * np.eye(3), err))
31  q = pinocchio.integrate(model, q, v * DT)
32  if not it % 10:
33  print("%d: error = %s" % (it, err.T))
34  it += 1
35 
36 if success:
37  print("Convergence achieved!")
38 else:
39  print(
40  "\nWarning: the iterative algorithm has not reached convergence to "
41  "the desired precision"
42  )
43 
44 print(f"\nresult: {q.flatten().tolist()}")
45 print(f"\nfinal error: {err.T}")
pinocchio::SE3Tpl< context::Scalar, context::Options >
pinocchio::forwardKinematics
void forwardKinematics(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< ConfigVectorType > &q, const Eigen::MatrixBase< TangentVectorType1 > &v, const Eigen::MatrixBase< TangentVectorType2 > &a)
Update the joint placements, spatial velocities and spatial accelerations according to the current jo...
pinocchio::cholesky::solve
Mat & solve(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const DataTpl< Scalar, Options, JointCollectionTpl > &data, const Eigen::MatrixBase< Mat > &y)
Return the solution of using the Cholesky decomposition stored in data given the entry ....
pinocchio::integrate
void integrate(const LieGroupGenericTpl< LieGroupCollection > &lg, const Eigen::MatrixBase< ConfigIn_t > &q, const Eigen::MatrixBase< Tangent_t > &v, const Eigen::MatrixBase< ConfigOut_t > &qout)
Visit a LieGroupVariant to call its integrate method.
pinocchio::neutral
Eigen::Matrix< typename LieGroupCollection::Scalar, Eigen::Dynamic, 1, LieGroupCollection::Options > neutral(const LieGroupGenericTpl< LieGroupCollection > &lg)
Visit a LieGroupVariant to get the neutral element of it.
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
Author(s):
autogenerated on Sun Dec 22 2024 03:41:09