Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OperationSpaceController to docs and tests and implement corresponding action/action_cfg classes #913

Open
wants to merge 87 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
4f07b85
add operation space control to docs and test skeletons
jtigue-bdai Aug 26, 2024
8da363c
Fixed class name
ozhanozen Aug 31, 2024
5bcaeec
Adds action and action_cfg class for opc
ozhanozen Aug 31, 2024
166dcc5
Separates opc and its config classes to different files to follow dif…
ozhanozen Sep 3, 2024
3ec3aa8
Deduces nDOF rather than taking as an argument
ozhanozen Sep 4, 2024
5113d96
Fixes typo
ozhanozen Sep 4, 2024
68c8830
Renames num_actions to action_dim for consistency
ozhanozen Sep 4, 2024
2218eec
Fixes the dimension the split is applied
ozhanozen Sep 4, 2024
7780801
Fix: concatanes pose_error tuple into a tensor
ozhanozen Sep 4, 2024
7828312
Fixes dimension errors in joint_efforts calculations
ozhanozen Sep 4, 2024
a8b6ac2
draft added for test_franka_pose_abs_fixed
ozhanozen Sep 4, 2024
a6a8f57
Fixes indexing of mass matrix
ozhanozen Sep 4, 2024
e71b475
Fixes dimension errors in inertial compensation calculations
ozhanozen Sep 4, 2024
e278d43
Adds light and vis markers for debugging test case
ozhanozen Sep 4, 2024
6bc2e27
Refactors the test functions and adds tests for pose commands
ozhanozen Sep 5, 2024
b3a1fa2
Refactors test code to move common settings/variables to setUp
ozhanozen Sep 6, 2024
be53a4f
Fixes unwanted change of desired ee targets by moving the update to s…
ozhanozen Sep 6, 2024
79f9a06
Refactor test_opc to include targets with different dimensions
ozhanozen Sep 6, 2024
daa0ccd
Consistency changes
ozhanozen Sep 6, 2024
3c44c8c
Fixes typo in calculation of desired_ee_force
ozhanozen Sep 10, 2024
1b193f2
Adds tests for opc open and closed loop force control
ozhanozen Sep 10, 2024
1bb8c92
Fixes how variable impedance commands are processed
ozhanozen Sep 10, 2024
88d0554
Adds tests for opc variable impedance motion control
ozhanozen Sep 10, 2024
5d0a1ac
Fixes typo in the force control of opc
ozhanozen Sep 11, 2024
7e83847
Converts force control to wrench control in OPC
ozhanozen Sep 11, 2024
52ca355
Fixes opc force control tests and adds tests for hybrid control
ozhanozen Sep 11, 2024
e3c7997
Fixes format in opc files
ozhanozen Sep 11, 2024
39bf177
Fixes typo
ozhanozen Sep 11, 2024
79dc78f
Adjusts default opc values so that there is no need to set unused par…
ozhanozen Sep 11, 2024
3110eb9
Addresses initial comments of PR
ozhanozen Sep 13, 2024
bf4da3b
Changes filename of the opc tes tile
ozhanozen Sep 13, 2024
44eded6
Rotates jacobian inside opc tests to root frame
ozhanozen Sep 13, 2024
5186b8e
Merge branch 'main' into feature/operation_space_controller
ozhanozen Sep 15, 2024
6c99e04
Removes position_abs and position_rel commands from _update_target of…
ozhanozen Sep 15, 2024
ea22726
Changes operationspacecontrol to operationALspacecontrol
ozhanozen Sep 16, 2024
72ca3a8
Changes ee_force_w to ee_force_b for the sake of correctness
ozhanozen Sep 16, 2024
f2a4b0a
Typo fixes
ozhanozen Sep 17, 2024
1f9f8f9
Implements OperationalSpaceControllerAction
ozhanozen Sep 17, 2024
5e30abd
Adds reach environment configuration examples for opc
ozhanozen Sep 17, 2024
cf1074d
Resolves commands in OperationalSpaceControllerAction better
ozhanozen Sep 18, 2024
9d47261
Adjusts opc action examples
ozhanozen Sep 18, 2024
32ac3de
Adds the body_offset to OperationalSpaceControllerAction calculations
ozhanozen Sep 19, 2024
1b1bf07
Tunes opc reach env
ozhanozen Sep 19, 2024
fbd9207
Fixes initialization of contact sensor in opc action class
ozhanozen Sep 19, 2024
2484763
Typo fix: OPC to OSC
ozhanozen Sep 19, 2024
ba0adc0
Changes variable names to explicitly indicate their reference frame
ozhanozen Sep 24, 2024
0804f58
Merge branch 'main' into feature/operation_space_controller
ozhanozen Sep 24, 2024
99bc162
Moves clearing of contact_forces to tearDown
ozhanozen Sep 24, 2024
395635f
Tunes hybrid opc test case
ozhanozen Sep 24, 2024
4b9925d
Removes jacobian calculation in process_actions, which became redunda…
ozhanozen Sep 24, 2024
cd6f7d5
Combines desired_ee_pos and desired_ee_rot and make them a copy of ta…
ozhanozen Sep 26, 2024
027f779
Fixes Jacobian joint indices for floating base articulations
ozhanozen Sep 27, 2024
b7e8911
Adds the osc feature to define target and control axes wrt an arbitra…
ozhanozen Oct 1, 2024
f76e903
resets contact sensor buffers
ozhanozen Oct 2, 2024
43b9482
Naming changes
ozhanozen Oct 2, 2024
e1c09d7
Adds test function to transform targets to task frame and a test for …
ozhanozen Oct 2, 2024
0b3127c
Frame tranformation for PD gains and variable renaming for OSC
ozhanozen Oct 4, 2024
b2ca053
Simplfying vector dimensions
ozhanozen Oct 4, 2024
4ce26e8
Added a test for hybrod control in task frame
ozhanozen Oct 4, 2024
3be12df
Adds osc test case for relative pose tracking in task frame
ozhanozen Oct 4, 2024
58cc0b2
Merge branch 'main' into feature/operation_space_controller
ozhanozen Oct 4, 2024
09c75b1
Typo fix
ozhanozen Oct 4, 2024
ee991e9
Adds osc tutorial script
ozhanozen Oct 4, 2024
344b806
Adds osc tutorial text
ozhanozen Oct 4, 2024
adb87b2
fixes typo
ozhanozen Oct 4, 2024
a1a9002
fixes naming
ozhanozen Oct 4, 2024
e69aafc
Merge branch 'main' into feature/operation_space_controller
ozhanozen Oct 7, 2024
0291d74
Merge branch 'main' into feature/operation_space_controller
ozhanozen Oct 7, 2024
228613b
Adds option to use external task frame with OperationalSpaceControlle…
ozhanozen Oct 7, 2024
18f947e
Merge branch 'main' into feature/operation_space_controller
ozhanozen Oct 8, 2024
5f4251d
Merge branch 'main' into feature/operation_space_controller
ozhanozen Oct 9, 2024
ad0db96
Merge branch 'main' into feature/operation_space_controller
ozhanozen Oct 11, 2024
c013626
Renames the inertial compensation to inertial dynamics decoupling as …
ozhanozen Oct 11, 2024
11b1df5
Makes the partial_inertial_dynamics_decoupling calculations more read…
ozhanozen Oct 11, 2024
928471f
Formating
ozhanozen Oct 11, 2024
a1094ff
typo fix
ozhanozen Oct 11, 2024
76b8ec7
whitespace fix
ozhanozen Oct 11, 2024
9293df8
Docstring/formatting updates
ozhanozen Oct 11, 2024
0c9b3e1
Merge branch 'main' into feature/operation_space_controller
ozhanozen Oct 11, 2024
2d22259
OSC tutorial script docstring
ozhanozen Oct 11, 2024
75fa85b
Updates changelog
ozhanozen Oct 11, 2024
e1f2708
Merge branch 'main' into feature/operation_space_controller
ozhanozen Oct 12, 2024
5cd6bff
Merge remote-tracking branch 'upstream/main' into feature/operation_s…
ozhanozen Dec 10, 2024
0c08f0b
Fixes typo in test
ozhanozen Dec 10, 2024
bd16302
Fixes errors in typo annotations
ozhanozen Dec 10, 2024
1fd4053
Removes unused osc methods
ozhanozen Dec 10, 2024
9d75df4
Updates docs and type annotations related to osc
ozhanozen Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions docs/source/api/lab/omni.isaac.lab.controllers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

DifferentialIKController
DifferentialIKControllerCfg
OperationSpaceController
OperationSpaceControllerCfg

Differential Inverse Kinematics
-------------------------------
Expand All @@ -23,3 +25,17 @@ Differential Inverse Kinematics
:inherited-members:
:show-inheritance:
:exclude-members: __init__, class_type

Operational Space controllers
-----------------------------

.. autoclass:: OperationalSpaceController
:members:
:inherited-members:
:show-inheritance:

.. autoclass:: OperationalSpaceControllerCfg
:members:
:inherited-members:
:show-inheritance:
:exclude-members: __init__, class_type
175 changes: 175 additions & 0 deletions docs/source/tutorials/05_controllers/run_osc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
Using an operational space controller
=============================

.. currentmodule:: omni.isaac.lab

Sometimes, controlling the end-effector pose of the robot using a differential IK controller is not sufficient.
For example, we might want to enforce a very specific pose tracking error dynamics in the task space, actuate the robot
with joint effort/torque commands, or apply a contact force at a specific direction while controlling the motion of
the other directions (e.g., washing the surface of the table with a cloth). In such tasks, we can use an
operational space controller (OSC).

Reference for the operational space control:
- [1] O Khatib. A unified approach for motion and force control of robot manipulators: The operational space
formulation. IEEE Journal of Robotics and Automation, 3(1):43–53, 1987. URL http://dx.doi.org/10.1109/JRA.1987.1087068.
- [2] https://ethz.ch/content/dam/ethz/special-interest/mavt/robotics-n-intelligent-systems/rsl-dam/documents/RobotDynamics2017/RD_HS2017script.pdf

In this tutorial, we will learn how to use an OSC to control the robot.
We will use the :class:`controllers.OperationalSpaceController` class to apply a constant force perpendicular to a
tilted wall surface while tracking a desired end-effector pose in all the other directions.

The Code
~~~~~~~~

The tutorial corresponds to the ``run_osc.py`` script in the
``source/standalone/tutorials/05_controllers`` directory.


.. dropdown:: Code for run_osc.py
:icon: code

.. literalinclude:: ../../../../source/standalone/tutorials/05_controllers/run_osc.py
:language: python
:emphasize-lines: 122-134
:linenos:


Creating an Operational Space Controller
----------------------------------------

The :class:`~controllers.OperationalSpaceController` class computes the joint
efforts/torques for a robot to do simultaneous motion and force control in task space.

The reference frame of this task space could be an arbitrary coordinate frame in Euclidean space. By default,
it is the robot's base frame. However, in certain cases, it could be easier to define target coordinates w.r.t. a
different frame. In such cases, the pose of this task reference frame, w.r.t. to the robot's base frame, should be
provided in the set_command method's current_task_frame_pose_b argument. For example, in this tutorial, it makes sense
to define the target commands w.r.t. a frame that is parallel to the wall surface, as the force control direction
would be then only nonzero in the z-axis of this frame. The target pose, which is set to have the same orientation
as the wall surface, is such a candidate and is used as the task frame in this tutorial. Therefore, all the arguments
to the :class:`~controllers.OperationalSpaceControllerCfg` should be set with this task reference frame in mind.

For the motion control, the task space targets could be given as absolute (i.e., defined w.r.t. the robot base,
target_types: "pose_abs") or relative the the end-effector's current pose (i.e., target_types: "pose_rel").
For the force control, the task space targets could be given as absolute (i.e., defined w.r.t. the robot base,
target_types: "force_abs"). If it is desired to apply pose and force control simultaneously, the target_types
should be a list such as ["pose_abs", "wrench_abs"] or ["pose_rel", "wrench_abs"].

The axes that the motion and force control will be applied can be specified using the motion_control_axes_task and
force_control_axes_task arguments, respectively. These lists should consist of 0/1 for all six axes (position and
rotation) and be complementary to each other (e.g., for the x-axis, if the motion_control_axes_task is 0, the
force_control_axes_task should be 1).

For the motion control axes, desired stiffness, and damping ratio values can be specified using the
motion_control_stiffness and motion_damping_ratio_task arguments, which can be a scalar (same value for all axes)
or a list of six scalars, one value corresponding to each axis. If desired, the stiffness and damping ratio values
could be a command parameter (e.g., to learn the values using RL or change them on the go). For this,
impedance_mode should be either "variable_kp" to include the stiffness values within the command or "variable" to
include both the stiffness and damping ratio values. In these cases, motion_stiffness_limits_task and
motion_damping_limits_task should be set as well, which puts bounds on the stiffness and damping ratio values.

For contact force control, it is possible to apply an open-loop force control by not setting the
contact_wrench_stiffness_task, or apply a closed-loop force control (with the feed-forward term) by setting
the desired stiffness values using the contact_wrench_stiffness_task argument, which can be a scalar or a list
of six scalars. Please note that, currently, only the linear part of the contact wrench (hence the first three
elements of the contact_wrench_stiffness_task) is considered in the closed-loop control, as the rotational part
cannot be measured with the contact sensors.

For the motion control, inertial_dynamics_decoupling should be set to True to use the robot's inertia matrix
to decouple the desired accelerations in the task space. This is important for the motion control to be accurate,
especially for rapid movements. This inertial decoupling accounts for the coupling between all the six motion axes.
If desired, the inertial coupling between the translational and rotational axes could be ignored by setting the
partial_inertial_dynamics_decoupling to True.

If it is desired to include the gravity compensation in the operational space command, the gravity_compensation
should be set to True.

The included OSC implementation performs the computation in a batched format and uses PyTorch operations.

In this tutorial, we will use "pose_abs" for controlling the motion in all axes except the z-axis and "wrench_abs"
for controlling the force in the z-axis. Moreover, we will include the full inertia decoupling in the motion control
and not include the gravity compensation, as the gravity is disabled from the robot configuration. Finally, we set the
impedance mode to "variable_kp" to dynamically change the stiffness values (motion_damping_ratio_task is set to 1: the
kd values adapt according to kp values to maintain a critically damped response).

.. literalinclude:: ../../../../source/standalone/tutorials/05_controllers/run_osc.py
:language: python
:start-at: # Create the OSC
:end-at: osc = OperationalSpaceController(osc_cfg, num_envs=scene.num_envs, device=sim.device)

Updating the states of the robot
--------------------------------------------

The OSC implementation is a computation-only class. Thus, it expects the user to provide the necessary information
about the robot. This includes the robot's Jacobian matrix, mass/inertia matrix, end-effector pose, velocity, and
contact force, all in the root frame. Moreover, the user should provide gravity compensation vector, if desired.

.. literalinclude:: ../../../../source/standalone/tutorials/05_controllers/run_osc.py
:language: python
:start-at: # Update robot states
:end-before: return jacobian_b, mass_matrix, gravity, ee_pose_b, ee_vel_b, root_pose_w, ee_pose_w, ee_force_b


Computing robot command
-----------------------

The OSC separates the operation of setting the desired command and computing the desired joint positions.
To set the desired command, the user should provide command vector, which includes the target commands
(i.e., in the order they appear in the target_types argument of the OSC configuration),
and the desired stiffness and damping ratio values if the impedance_mode is set to "variable_kp" or "variable".
They should be all in the same coordinate frame as the task frame (e.g., indicated with _task subscript) and
concatanated together.

In this tutorial, the desired wrench is already defined w.r.t. the task frame, and the desired pose is transformed
to the task frame as the following:

.. literalinclude:: ../../../../source/standalone/tutorials/05_controllers/run_osc.py
:language: python
:start-at: # Convert the target commands to the task frame
:end-at: return command, task_frame_pose_b

The OSC command is set with the command vector in the task frame, the end-effector pose in the base frame, and the
task (reference) frame pose in the base frame as the following. This information is needed, as the internal
computations are done in the base frame.

.. literalinclude:: ../../../../source/standalone/tutorials/05_controllers/run_osc.py
:language: python
:start-at: # set the osc command
:end-at: osc.set_command(command=command, current_ee_pose_b=ee_pose_b, current_task_frame_pose_b=task_frame_pose_b)

The joint effort/torque values are computed using the provided robot states and the desired command as the following:

.. literalinclude:: ../../../../source/standalone/tutorials/05_controllers/run_osc.py
:language: python
:start-at: # compute the joint commands
:end-at: # apply actions


The computed joint effort/torque targets can then be applied on the robot.

.. literalinclude:: ../../../../source/standalone/tutorials/05_controllers/run_osc.py
:language: python
:start-at: # apply actions
:end-at: robot.write_data_to_sim()


The Code Execution
~~~~~~~~~~~~~~~~~~

You can now run the script and see the result:

.. code-block:: bash

./isaaclab.sh -p source/standalone/tutorials/05_controllers/run_osc.py --num_envs 128

The script will start a simulation with 128 robots. The robots will be controlled using the OSC.
The current and desired end-effector poses should be displayed using frame markers in addition to the red tilted wall.
You should see that the robot reaches the desired pose while applying a constant force perpendicular to the wall
surface.

.. figure:: ../../_static/tutorials/tutorial_operational_space_controller.jpg
:align: center
:figwidth: 100%
:alt: result of run_osc.py

To stop the simulation, you can either close the window or press ``Ctrl+C`` in the terminal.
1 change: 1 addition & 0 deletions docs/source/tutorials/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,4 @@ tutorials show you how to use motion generators to control the robots at the tas
:titlesonly:

05_controllers/run_diff_ik
05_controllers/run_osc
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@

from .differential_ik import DifferentialIKController
from .differential_ik_cfg import DifferentialIKControllerCfg
from .operational_space import OperationalSpaceController
from .operational_space_cfg import OperationalSpaceControllerCfg
Loading