Skip to content

Commit 995654c

Browse files
committed
Update documentation
1 parent 1b3bc58 commit 995654c

File tree

3 files changed

+66
-21
lines changed

3 files changed

+66
-21
lines changed

docs/source/api/lab/isaaclab.controllers.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
DifferentialIKControllerCfg
1212
OperationalSpaceController
1313
OperationalSpaceControllerCfg
14+
PinkIKController
15+
PinkIKControllerCfg
1416

1517
Differential Inverse Kinematics
1618
-------------------------------
@@ -39,3 +41,17 @@ Operational Space controllers
3941
:inherited-members:
4042
:show-inheritance:
4143
:exclude-members: __init__, class_type
44+
45+
Differential Inverse Kinematics Controllers (Based on Pink)
46+
-----------------------------------------------------------
47+
48+
.. autoclass:: isaaclab.controllers.pink_ik.PinkIKController
49+
:members:
50+
:inherited-members:
51+
:show-inheritance:
52+
53+
.. autoclass:: isaaclab.controllers.pink_ik.PinkIKControllerCfg
54+
:members:
55+
:inherited-members:
56+
:show-inheritance:
57+
:exclude-members: __init__, class_type

source/isaaclab/isaaclab/controllers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
from .differential_ik_cfg import DifferentialIKControllerCfg
1616
from .operational_space import OperationalSpaceController
1717
from .operational_space_cfg import OperationalSpaceControllerCfg
18+
from .pink_ik import NullSpacePostureTask, PinkIKController, PinkIKControllerCfg

source/isaaclab/isaaclab/controllers/pink_ik/pink_ik.py

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77
88
This module provides integration between Pink inverse kinematics solver and IsaacLab.
99
Pink is a differentiable inverse kinematics solver framework that provides task-space control capabilities.
10+
11+
Reference:
12+
Pink IK Solver: https://github.com/stephane-caron/pink
1013
"""
1114

15+
from __future__ import annotations
16+
1217
import numpy as np
1318
import torch
19+
from typing import TYPE_CHECKING
1420

1521
from pink import solve_ik
1622
from pink.configuration import Configuration
@@ -21,21 +27,38 @@
2127
from isaaclab.utils.string import resolve_matching_names_values
2228

2329
from .null_space_posture_task import NullSpacePostureTask
24-
from .pink_ik_cfg import PinkIKControllerCfg
30+
31+
if TYPE_CHECKING:
32+
from .pink_ik_cfg import PinkIKControllerCfg
2533

2634

2735
class PinkIKController:
2836
"""Integration of Pink IK controller with Isaac Lab.
2937
30-
The Pink IK controller is available at: https://github.com/stephane-caron/pink
38+
The Pink IK controller solves differential inverse kinematics through weighted tasks. Each task is defined
39+
by a residual function e(q) that is driven to zero (e.g., e(q) = p_target - p_ee(q) for end-effector positioning).
40+
The controller computes joint velocities v satisfying J_e(q)v = -αe(q), where J_e(q) is the task Jacobian.
41+
Multiple tasks are resolved through weighted optimization, formulating a quadratic program that minimizes
42+
weighted task errors while respecting joint velocity limits.
43+
44+
It supports user defined tasks, and we have provided a NullSpacePostureTask for maintaining desired joint configurations.
45+
46+
Reference:
47+
Pink IK Solver: https://github.com/stephane-caron/pink
3148
"""
3249

3350
def __init__(self, cfg: PinkIKControllerCfg, robot_cfg: ArticulationCfg, device: str):
3451
"""Initialize the Pink IK Controller.
3552
3653
Args:
37-
cfg: The configuration for the controller.
38-
device: The device to use for computations (e.g., 'cuda:0').
54+
cfg: The configuration for the Pink IK controller containing task definitions, solver parameters,
55+
and joint configurations.
56+
robot_cfg: The robot articulation configuration containing initial joint positions and robot
57+
specifications.
58+
device: The device to use for computations (e.g., 'cuda:0', 'cpu').
59+
60+
Raises:
61+
KeyError: When Pink joint names cannot be matched to robot configuration joint positions.
3962
"""
4063
# Initialize the robot model from URDF and mesh files
4164
self.robot_wrapper = RobotWrapper.BuildFromURDF(cfg.urdf_path, cfg.mesh_path, root_joint=None)
@@ -63,6 +86,7 @@ def __init__(self, cfg: PinkIKControllerCfg, robot_cfg: ArticulationCfg, device:
6386

6487
# Set the default targets for each task from the configuration
6588
for task in cfg.variable_input_tasks:
89+
# If task is a NullSpacePostureTask, set the target to the initial joint positions
6690
if isinstance(task, NullSpacePostureTask):
6791
task.set_target(self.init_joint_positions)
6892
continue
@@ -91,30 +115,29 @@ def __init__(self, cfg: PinkIKControllerCfg, robot_cfg: ArticulationCfg, device:
91115
self.cfg = cfg
92116
self.device = device
93117

94-
def reorder_array(self, input_array: list[float], reordering_array: list[int]) -> list[float]:
118+
def _reorder_array(self, input_array: list[float], reordering_array: list[int]) -> list[float]:
95119
"""Reorder the input array based on the provided ordering.
96120
121+
This utility method is used to convert between Isaac Lab and Pink joint ordering conventions.
122+
97123
Args:
98-
input_array: The array to reorder.
99-
reordering_array: The indices to use for reordering.
124+
input_array: The array to reorder, typically joint positions or velocities.
125+
reordering_array: The indices to use for reordering, mapping from source to target ordering.
100126
101127
Returns:
102-
Reordered array.
128+
Reordered array following the target joint ordering convention.
103129
"""
104130
return [input_array[i] for i in reordering_array]
105131

106-
def initialize(self):
107-
"""Initialize the internals of the controller.
108-
109-
This method is called during setup but before the first compute call.
110-
"""
111-
pass
112-
113132
def update_null_space_joint_targets(self, curr_joint_pos: np.ndarray):
114133
"""Update the null space joint targets.
115134
135+
This method updates the target joint positions for null space posture tasks based on the current
136+
joint configuration. This is useful for maintaining desired joint configurations when the primary
137+
task allows redundancy.
138+
116139
Args:
117-
curr_joint_pos: The current joint positions.
140+
curr_joint_pos: The current joint positions of shape (num_joints,).
118141
"""
119142
for task in self.cfg.variable_input_tasks:
120143
if isinstance(task, NullSpacePostureTask):
@@ -127,15 +150,20 @@ def compute(
127150
) -> torch.Tensor:
128151
"""Compute the target joint positions based on current state and tasks.
129152
153+
Performs inverse kinematics using the Pink solver to compute target joint positions that satisfy
154+
the defined tasks. The solver uses quadratic programming to find optimal joint velocities that
155+
minimize task errors while respecting constraints.
156+
130157
Args:
131-
curr_joint_pos: The current joint positions.
132-
dt: The time step for computing joint position changes.
158+
curr_joint_pos: The current joint positions of shape (num_joints,).
159+
dt: The time step for computing joint position changes in seconds.
133160
134161
Returns:
135-
The target joint positions as a tensor.
162+
The target joint positions as a tensor of shape (num_joints,) on the specified device.
163+
If the IK solver fails, returns the current joint positions unchanged to maintain stability.
136164
"""
137165
# Initialize joint positions for Pink, including the root and universal joints
138-
joint_positions_pink = np.array(self.reorder_array(curr_joint_pos, self.isaac_lab_to_pink_ordering))
166+
joint_positions_pink = np.array(self._reorder_array(curr_joint_pos, self.isaac_lab_to_pink_ordering))
139167

140168
# Update Pink's robot configuration with the current joint positions
141169
self.pink_configuration.update(joint_positions_pink)
@@ -165,7 +193,7 @@ def compute(
165193

166194
# Reorder the joint angle changes back to Isaac Lab conventions
167195
joint_vel_isaac_lab = torch.tensor(
168-
self.reorder_array(pink_joint_angle_changes, self.pink_to_isaac_lab_ordering),
196+
self._reorder_array(pink_joint_angle_changes, self.pink_to_isaac_lab_ordering),
169197
device=self.device,
170198
dtype=torch.float,
171199
)

0 commit comments

Comments
 (0)