0
# Inverse Kinematics and Dynamics
1
2
Compute inverse kinematics solutions for robotic manipulation and inverse dynamics for force computation and control. Essential for robotic applications requiring precise end-effector positioning and force control.
3
4
## Capabilities
5
6
### Inverse Kinematics
7
8
```python { .api }
9
def calculateInverseKinematics(bodyUniqueId, endEffectorLinkIndex, targetPosition, targetOrientation=None, lowerLimits=None, upperLimits=None, jointRanges=None, restPoses=None, maxNumIterations=20, residualThreshold=1e-4, physicsClientId=0):
10
"""
11
Calculate inverse kinematics solution for target end-effector pose.
12
13
Args:
14
bodyUniqueId (int): Robot body unique ID
15
endEffectorLinkIndex (int): End effector link index
16
targetPosition (list): Target position [x, y, z]
17
targetOrientation (list, optional): Target orientation quaternion [x, y, z, w]
18
lowerLimits (list, optional): Joint lower limits
19
upperLimits (list, optional): Joint upper limits
20
jointRanges (list, optional): Joint ranges for null space optimization
21
restPoses (list, optional): Rest pose joint angles
22
maxNumIterations (int, optional): Maximum IK iterations. Defaults to 20.
23
residualThreshold (float, optional): Convergence threshold. Defaults to 1e-4.
24
physicsClientId (int, optional): Physics client ID. Defaults to 0.
25
26
Returns:
27
list: Joint angles solution
28
"""
29
30
def calculateInverseKinematics2(bodyUniqueId, endEffectorLinkIndices, targetPositions, targetOrientations=None, lowerLimits=None, upperLimits=None, jointRanges=None, restPoses=None, jointDamping=None, solver=0, maxNumIterations=20, residualThreshold=1e-4, physicsClientId=0):
31
"""Calculate IK for multiple end effectors simultaneously."""
32
```
33
34
### Inverse Dynamics
35
36
```python { .api }
37
def calculateInverseDynamics(bodyUniqueId, objPositions, objVelocities, objAccelerations, physicsClientId=0):
38
"""
39
Calculate joint torques using inverse dynamics.
40
41
Args:
42
bodyUniqueId (int): Body unique ID
43
objPositions (list): Joint positions
44
objVelocities (list): Joint velocities
45
objAccelerations (list): Desired joint accelerations
46
physicsClientId (int, optional): Physics client ID. Defaults to 0.
47
48
Returns:
49
list: Required joint torques
50
"""
51
```
52
53
### Jacobian Computation
54
55
```python { .api }
56
def calculateJacobian(bodyUniqueId, linkIndex, localPosition, objPositions, objVelocities, objAccelerations, physicsClientId=0):
57
"""
58
Calculate Jacobian matrices for given configuration.
59
60
Returns:
61
tuple: (linearJacobian, angularJacobian)
62
"""
63
64
def calculateMassMatrix(bodyUniqueId, objPositions, physicsClientId=0):
65
"""Calculate mass matrix for given configuration."""
66
```
67
68
## Usage Examples
69
70
### Basic Inverse Kinematics
71
72
```python
73
import pybullet as p
74
75
p.connect(p.GUI)
76
robotId = p.loadURDF("kuka_iiwa/model.urdf")
77
78
# Target end-effector position
79
targetPos = [0.5, 0.2, 0.7]
80
targetOrn = p.getQuaternionFromEuler([0, -math.pi/2, 0])
81
82
# Calculate IK solution
83
jointPositions = p.calculateInverseKinematics(
84
robotId,
85
6, # End effector link index
86
targetPos,
87
targetOrn
88
)
89
90
# Apply solution
91
for i, pos in enumerate(jointPositions):
92
p.setJointMotorControl2(robotId, i, p.POSITION_CONTROL, targetPosition=pos)
93
```
94
95
[Complete documentation with detailed examples and usage patterns]