Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3672d6e
added basic interface for isaacsim
LeaStef Apr 22, 2025
0a7b3d6
create world with dt
LeaStef Apr 24, 2025
73d07bb
implemented method connect in interface for isaacsim
LeaStef Apr 25, 2025
f34bf78
implemented method get_feedback to provide joint angles and joint ang…
LeaStef Apr 25, 2025
e2fe8ac
implemented sned_target_angles
LeaStef Apr 28, 2025
6578760
add method to provide pose
LeaStef May 1, 2025
b953b7f
example script to make arm follow cube
LeaStef May 1, 2025
a2ca838
added methods getOreintation() and set_xyz to isaac interface
LeaStef May 6, 2025
0362a48
switched urdf import to xml import
LeaStef May 13, 2025
6e1e766
interface adapted to h1, locked robote pelvis orientation so it does …
LeaStef May 16, 2025
8149846
fixed getfeedback to work only for arm DOFs
LeaStef May 20, 2025
4e70b1a
added config file for H1
LeaStef May 21, 2025
25ab5ca
added matrix for segment lengths of arm
LeaStef May 23, 2025
59d3925
added articulation view
LeaStef May 23, 2025
fb9445b
working example with floating robot
LeaStef Jun 17, 2025
0d70a58
implementation method quaternion, Tx, R
LeaStef Jun 20, 2025
adfa03d
floating control now works for ur5 and jaco2
LeaStef Jun 24, 2025
9e412b8
adapted tu num of controlled DOF
LeaStef Jun 24, 2025
bc7a01e
generalized send u
LeaStef Jun 24, 2025
361b35c
new implementation of the method connect, following the structure of …
LeaStef Jun 25, 2025
00471ef
Create a visual-only cube (no collision)
LeaStef Jun 27, 2025
96b2151
fixed gains of arm joints, which were to stiff for force control
LeaStef Jul 7, 2025
04d54a8
fixed def M
LeaStef Jul 7, 2025
823aa6f
Example with force_osc working
LeaStef Jul 8, 2025
c2593a2
added example linear path gaussian velocity
LeaStef Jul 8, 2025
1da42b9
adaptations for no EE
LeaStef Jul 10, 2025
fc6bd28
force control working for UR5 and jaco2
LeaStef Jul 10, 2025
f7bbb1e
adapted mass matrix to extract the correct, controlled joints
LeaStef Jul 14, 2025
4ec172c
added torso joint and used standing method in setup for h1
LeaStef Jul 15, 2025
53067fb
integrated robot H1 with hands
LeaStef Jul 16, 2025
62cdbec
fixed method set_gains_force_control so it adresses the right joints
LeaStef Jul 16, 2025
ff9299a
adapted method send_forces to work with abritary list of joint indices
LeaStef Jul 16, 2025
b1cb9ea
fixed helper methods for arbitrary indices
LeaStef Jul 17, 2025
15dca0a
removed coriolis forces from function for gravity compensation
LeaStef Jul 30, 2025
4d51236
fixed indexing of jacobian due to non-fixed base
LeaStef Aug 6, 2025
0e1a270
fixed method M
LeaStef Aug 7, 2025
24db8ef
force control OSC working for H1 without gravity
LeaStef Aug 11, 2025
090944b
fixed offset for virtual EE
LeaStef Aug 14, 2025
e6df5fe
fixed calc of body_link in J() and removed obsolete h1 setup
LeaStef Aug 15, 2025
429213d
works with gravity now on all 4 robots (weird fix for h1)
LeaStef Aug 19, 2025
be900e3
example force_osc_xyz_linear_path_gaussian_velocity works with ur5 an…
LeaStef Aug 20, 2025
c503fbe
added documentation
LeaStef Aug 21, 2025
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
Prev Previous commit
Next Next commit
added articulation view
  • Loading branch information
LeaStef committed Aug 21, 2025
commit 59d39253c14e29567c98490b0e500fc867c5808f
194 changes: 136 additions & 58 deletions abr_control/interfaces/nv_isaacsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,71 +21,138 @@ def __init__(self, robot_config, dt=0.001, force_download=False):
self.dt = dt # time step
self.count = 0 # keep track of how many times send forces is called

self.q = np.zeros(self.robot_config.N_JOINTS) # joint angles
self.dq = np.zeros(self.robot_config.N_JOINTS) # joint_velocities
#self.q = np.zeros(self.robot_config.N_JOINTS) # joint angles
#self.initial_q = np.zeros(self.robot_config.N_JOINTS) # joint angles
#self.dq = np.zeros(self.robot_config.N_JOINTS) # joint_velocities

self.prim_path = "/World/robot"
self.name = "robot"
self.name = self.robot_config.xml_dir.rsplit('/', 1)[-1]
#self.name = "robot"
#robot_name = self.robot_config.xml_dir.rsplit('/', 1)[-1]


#self.misc_handles = {} # for tracking miscellaneous object handles


def connect(self, load_scene=True):
if load_scene:
"""All initial setup."""
self.simulation_app = SimulationApp({"headless": False})
from isaacsim.core.api import World # type: ignore
import omni.isaac.core.utils.stage as stage_utils # type: ignore
import omni.kit.commands # type: ignore
import omni
from isaacsim.robot.policy.examples.robots.h1 import H1FlatTerrainPolicy
from isaacsim.storage.native import get_assets_root_path


# Create a world
self.world = World(physics_dt=self.dt,rendering_dt=self.dt)
self.stage = omni.usd.get_context().get_stage()
self.world.add_physics_callback("send_actions", self.send_actions)
self.world.scene.add_default_ground_plane()
def connect(self, joint_names=None):
"""
joint_names: list, optional (Default: None)
list of joint names to send control signal to and get feedback from
if None, the joints in the kinematic tree connecting the end-effector
to the world are used
"""


"""All initial setup."""
self.simulation_app = SimulationApp({"headless": False})
from isaacsim.core.api import World # type: ignore
import omni.isaac.core.utils.stage as stage_utils # type: ignore
import omni.kit.commands # type: ignore
import omni
from isaacsim.robot.policy.examples.robots.h1 import H1FlatTerrainPolicy
from isaacsim.storage.native import get_assets_root_path
from omni.isaac.core.articulations import Articulation, ArticulationView# type: ignore
import omni.isaac.core.utils.stage as stage_utils # type: ignore
from isaacsim.core.api.robots import Robot
from isaacsim.core.api.controllers.articulation_controller import ArticulationController
# Create a world
self.world = World(physics_dt=self.dt,rendering_dt=self.dt)
self.context = omni.usd.get_context()
self.stage = self.context.get_stage()
self.world.add_physics_callback("send_actions", self.send_actions)
self.world.scene.add_default_ground_plane()




'''
assets_root_path = get_assets_root_path()

assets_root_path = get_assets_root_path()

# Load Jaco2 robot
stage_utils.add_reference_to_stage(
usd_path=assets_root_path + "/Isaac/Robots/Kinova/Jaco2/J2N6S300/j2n6s300_instanceable.usd",
# Robots/Kinova/Jaco2/J2N7S300/j2n7s300_instanceable.usd --> 7 DOF arm , not compatible with ABR controller
prim_path=self.prim_path,
)

robot = self.world.scene.add(Robot(prim_path=self.prim_path, name=self.name))
'''


'''
# Load H1 robot


self.h1 = H1FlatTerrainPolicy(
prim_path=self.prim_path,
name=self.name,
usd_path=assets_root_path + "/Isaac/Robots/Unitree/H1/h1.usd",
position=np.array([0, 0, 1.05]),
)
stage_utils.add_reference_to_stage(
self.h1 = H1FlatTerrainPolicy(
prim_path=self.prim_path,
name=self.name,
usd_path=assets_root_path + "/Isaac/Robots/Unitree/H1/h1.usd",
position=np.array([0, 0, 1.05]),
)
stage_utils.add_reference_to_stage(
usd_path=assets_root_path + "/Isaac/Robots/Unitree/H1/h1.usd",
prim_path=self.prim_path,
)

else:
self.world = SimulationApp.getWorld()

# Get the articulation
from omni.isaac.core.articulations import Articulation# type: ignore
import omni.isaac.core.utils.stage as stage_utils # type: ignore

'''

# Resetting the world needs to be called before querying anything related to an articulation specifically.
# Its recommended to always do a reset after adding your assets, for physics handles to be propagated properly


self.world.reset()
# Load robot
self.articulation = Articulation(prim_path=self.prim_path, name=self.name)
self.articulation = Articulation(prim_path=self.prim_path, name=self.name + "_articulation")
self.articulation.initialize()
print("DOF names:", self.articulation.dof_names)


self.articulation_view = ArticulationView(prim_paths_expr=self.prim_path, name=self.name + "_view")
self.world.scene.add(self.articulation_view)

articulation_controller = ArticulationController()
articulation_controller.initialize(self.articulation_view)


# necessary so self.q and self.dq are accessible
self.world.initialize_physics()

# get the robot's initial joint angle
#TODO maybe replace with articulation.get_default_state()
self.initial_q = self.get_feedback(arm_only=False)["q"]


self.joint_pos_addrs = []
self.joint_vel_addrs = []
self.joint_dyn_addrs = []



if joint_names is None:
# if no joint names provided, get addresses of joints in the kinematic
# tree from end-effector (EE) to world body
#bodyid = mujoco.mj_name2id(self.model, mujoco.mjtObj.mjOBJ_BODY, "EE")

#bodyid = self.articulation.get_dof_index('right_elbow_joint')
#l_id = self.articulation.get_link_index("right_elbow_joint") # get the link index of the right elbow joint
#bodyid = self.articulation.get_link_index("EE")
dof_names = self.articulation.dof_names
print("DOF names:", dof_names)
#bodid = self.articulation.dof_names.index("EE")
#bodyid = self.articulation_controller
#bodyid = self.articulation.get_dof_index("EE")

# and working back to the world body
#while self.model.body_parentid[bodyid] != 0:
while bodyid > 1:
print (bodyid)
#first_joint = self.articulation.get_joint_index("EE")
#num_joints = self.model.body_jntnum[bodyid]



self.robot_config._connect(
#self.articulation,
self.articulation_view,
self.joint_pos_addrs,
self.joint_vel_addrs,
)



Expand Down Expand Up @@ -129,7 +196,6 @@ def send_target_angles(self, q):
#TODO make more general, with flag
#TODO use same flag for jaco2 and H1

print("LENGTH q:", len(q))
# full jaco2 arm with hand DOF
if np.size(q) == 12:
self.articulation.set_joint_positions(q)
Expand All @@ -138,19 +204,24 @@ def send_target_angles(self, q):
self.articulation.set_joint_positions(q)
# only jaco2 arm
if np.size(q) == 6:
fb = self.get_feedback(with_hand=True)
fb = self.get_feedback(arm_only=False)
fb_q = fb["q"]
fb_q[:6] = q
self.articulation.set_joint_positions(fb_q)
# only H1 right arm
# only H1 right arm
if np.size(q) == 4:
fb = self.get_feedback(arm_only=False)
fb_q = fb["q"]
fb_q = self.initial_q

#fb = self.get_feedback(arm_only=False)
#fb_q = fb["q"]

fb_q [6] = q[0] # right_shoulder_pitch_joint
fb_q [10] = q[1] # right_shoulder_roll_joint
fb_q [14] = q[2] # right_shoulder_yaw_joint
fb_q [18] = q[3] # right_elbow_joint
self.articulation.set_joint_positions(fb_q)


else:
print("The method send_target_angles of the isaacsim interface does not support the number of joint angles that are attempted to be set.")
# move simulation ahead one time step
Expand All @@ -175,18 +246,24 @@ def get_feedback(self, arm_only=True):
self.dq = dq
# get only DOF of the arm
else:
tmp = np.zeros(4)
tmp[0] = q[6] # right_shoulder_pitch_joint
tmp[1] = q[10] # right_shoulder_roll_joint
tmp[2] = q[14] # right_shoulder_yaw_joint
tmp[3] = q[18] # right_elbow_joint
self.q = tmp

tmp[0] = dq[6] # right_shoulder_pitch_joint
tmp[1] = dq[10] # right_shoulder_roll_joint
tmp[2] = dq[14] # right_shoulder_yaw_joint
tmp[3] = dq[18] # right_elbow_joint
self.dq = tmp
if self.name == "jaco2":
# get only the right arm DOF of the jaco 2 without hand
self.q = q[:6]
self.dq = dq[:6]
elif self.name == "h1":
# get only the right arm DOF of the H1 robot
tmp = np.zeros(4)
tmp[0] = q[6] # right_shoulder_pitch_joint
tmp[1] = q[10] # right_shoulder_roll_joint
tmp[2] = q[14] # right_shoulder_yaw_joint
tmp[3] = q[18] # right_elbow_joint
self.q = tmp

tmp[0] = dq[6] # right_shoulder_pitch_joint
tmp[1] = dq[10] # right_shoulder_roll_joint
tmp[2] = dq[14] # right_shoulder_yaw_joint
tmp[3] = dq[18] # right_elbow_joint
self.dq = tmp
return {"q": self.q, "dq": self.dq}


Expand Down Expand Up @@ -240,5 +317,6 @@ def send_actions(self, dt):
from pxr import Gf # type: ignore
prim=self.stage.GetPrimAtPath(pelvis_prim_path)
prim.GetAttribute("xformOp:orient").Set(Gf.Quatd(1.0 ,0.0 ,0.0 ,0.0))
prim.GetAttribute("xformOp:translate").Set(Gf.Vec3f(0.0 ,0.0 ,0.02))
#prim.GetAttribute("xformOp:orient").Set(Gf.Quatd(0.70711 ,0.70711 ,0.0 ,0.0))

117 changes: 117 additions & 0 deletions examples/isaacsim/position_joint_control_inverse_kinematics_H1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
"""
Running the joint controller with an inverse kinematics path planner
for a Mujoco simulation. The path planning system will generate
a trajectory in joint space that moves the end effector in a straight line
to the target, which changes every n time steps.
"""
import numpy as np
#from abr_control.arms.mujoco_config import MujocoConfig as arm
from abr_control.arms import unitree_H1 as arm
#import glfw
from abr_control.controllers import path_planners
#from abr_control.interfaces.mujoco import Mujoco
from abr_control.interfaces.nv_isaacsim import IsaacSim
from abr_control.utils import transformations
from flying_cube import FlyingCube

'''
from abr_control.arms import ur5 as arm1
ur5 = arm1.Config()
print("ur5: ", ur5.N_JOINTS)
print("L: ", len(ur5.L))
from abr_control.arms import jaco2 as arm2
jaco = arm2.Config()
print("jaco: ", jaco.N_JOINTS)
print("L: ", len(jaco.L))

from abr_control.arms import onejoint as arm3
onejoint = arm3.Config()
print("onejoint: ", onejoint.N_JOINTS)
print("L: ", len(onejoint.L))

from abr_control.arms import twojoint as arm4
twojoint = arm4.Config()
print("twojoint: ", twojoint.N_JOINTS)

print("L: ", len(twojoint.L))

from abr_control.arms import threejoint as arm5
threejoint = arm5.Config()
print("threejoint: ", threejoint.N_JOINTS)
print("L: ", len(threejoint.L))
'''

robot_config = arm.Config()
#print("h1: ", robot_config.N_JOINTS)
#print("L: ", len(robot_config.L))


# create our path planner
n_timesteps = 2000
path_planner = path_planners.InverseKinematics(robot_config)

# create our interface
dt = 0.001
interface = IsaacSim(robot_config, dt=dt)
interface.connect()
interface.send_target_angles(robot_config.START_ANGLES)
feedback = interface.get_feedback()
isaac_target = FlyingCube(interface.dt, interface.world, name="target", prim_path="/World/target")




#inertias = interface.articulation_view.get_body_inertias()

#inertias_right_shoulder_pitch_joint = interface.articulation_view.get_body_inertias(body_indices=np.array([6]))


try:
print("\nSimulation starting...")
print("Click to move the target.\n")

count = 0
while 1:

if count % n_timesteps == 0:
print("Moving target...")
feedback = interface.get_feedback()
target_xyz = np.array(
[
np.random.random() * 0.5 + 0.2,
np.random.random() * 1.1 - 0.9,
np.random.random() * 1.0 + 0.9,
]
)
R = robot_config.R("EE", q=feedback["q"])
#R = robot_config.R("wrist_3_joint", q=feedback["q"])

target_orientation = transformations.euler_from_matrix(R, "sxyz")
# update the position of the target
interface.set_xyz("target", target_xyz)

# can use 3 different methods to calculate inverse kinematics
# see inverse_kinematics.py file for details
path_planner.generate_path(
position=feedback["q"],
target_position=np.hstack([target_xyz, target_orientation]),
method=3,
dt=0.005,
n_timesteps=n_timesteps,
plot=False,
)

# returns desired [position, velocity]
target = path_planner.next()[0]

# use position control
interface.send_target_angles(target[: robot_config.N_JOINTS])
#interface.world.step(render=True) # execute one physics step and one rendering step

count += 1

finally:
# stop and reset the simulation
interface.disconnect()

print("Simulation terminated...")