MCPcopy Create free account
hub / github.com/bulletphysics/bullet3 / computeIK

Method computeIK

examples/SharedMemory/IKTrajectoryHelper.cpp:40–187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38}
39
40bool IKTrajectoryHelper::computeIK(const double endEffectorTargetPosition[3],
41 const double endEffectorTargetOrientation[4],
42 const double endEffectorWorldPosition[3],
43 const double endEffectorWorldOrientation[4],
44 const double* q_current, int numQ, int endEffectorIndex,
45 double* q_new, int ikMethod, const double* linear_jacobian, const double* angular_jacobian, int jacobian_size, const double dampIk[6])
46{
47 MatrixRmn AugMat;
48 bool useAngularPart = (ikMethod == IK2_VEL_DLS_WITH_ORIENTATION || ikMethod == IK2_VEL_DLS_WITH_ORIENTATION_NULLSPACE || ikMethod == IK2_VEL_SDLS_WITH_ORIENTATION) ? true : false;
49
50 Jacobian ikJacobian(useAngularPart, numQ, 1);
51
52 ikJacobian.Reset();
53
54 bool UseJacobianTargets1 = false;
55
56 if (UseJacobianTargets1)
57 {
58 ikJacobian.SetJtargetActive();
59 }
60 else
61 {
62 ikJacobian.SetJendActive();
63 }
64 VectorR3 targets;
65 targets.Set(endEffectorTargetPosition[0], endEffectorTargetPosition[1], endEffectorTargetPosition[2]);
66 ikJacobian.ComputeJacobian(&targets); // Set up Jacobian and deltaS vectors
67
68 // Set one end effector world position from Bullet
69 VectorRn deltaS(3);
70 for (int i = 0; i < 3; ++i)
71 {
72 deltaS.Set(i, dampIk[i] * (endEffectorTargetPosition[i] - endEffectorWorldPosition[i]));
73 }
74
75 // Set one end effector world orientation from Bullet
76 VectorRn deltaR(3);
77 if (useAngularPart)
78 {
79 btQuaternion startQ(endEffectorWorldOrientation[0], endEffectorWorldOrientation[1], endEffectorWorldOrientation[2], endEffectorWorldOrientation[3]);
80 btQuaternion endQ(endEffectorTargetOrientation[0], endEffectorTargetOrientation[1], endEffectorTargetOrientation[2], endEffectorTargetOrientation[3]);
81 btQuaternion deltaQ = endQ * startQ.inverse();
82 float angle = deltaQ.getAngle();
83 btVector3 axis = deltaQ.getAxis();
84 if (angle > PI)
85 {
86 angle -= 2.0 * PI;
87 }
88 else if (angle < -PI)
89 {
90 angle += 2.0 * PI;
91 }
92 float angleDot = angle;
93 btVector3 angularVel = angleDot * axis.normalize();
94 for (int i = 0; i < 3; ++i)
95 {
96 deltaR.Set(i, dampIk[i + 3] * angularVel[i]);
97 }

Calls 15

SetJtargetActiveMethod · 0.80
SetJendActiveMethod · 0.80
SetDeltaSMethod · 0.80
SetJendTransMethod · 0.80
GetLengthMethod · 0.80
CalcDeltaThetasDLS2Method · 0.80
CalcDeltaThetasSDLSMethod · 0.80
ZeroDeltaThetasMethod · 0.80

Tested by

no test coverage detected