Set initial position of robot / articulation before simulation starts in Python

Dear community,

when I load a robot e.g. the UR10 the initial position is not often quite useful to embed into a useful scenario.
Is there a way to set the joints values prior to running the simulation?
If not, how can I submit a feature request, as this is a very useful setting given that robots like the UR are spawned straight flat on the “ground” which is terrible for a lot of environments. You would in general not expect that a robot stars in packing position or always in initial position (e.g. due to singularities).

Kind regards,

Heiko

Following is code to change robot initial position and pose.
I checked the script with the robot created by “[Create]->[Isaac]->[Robots]->[Universal Robots]->[UR10]”.
The initial position can be changed at any time.
But the initial pose can be changed when simulation running.

import omni
import math
from pxr import UsdGeom, Gf
from omni.isaac.dynamic_control import _dynamic_control

stage = omni.usd.get_context().get_stage()

#articulation_path = "your/robot/articulation/root"
articulation_path = "/UR10"
x = 0.0
y = 0.0
z = 1.0
roll = 0.0
pitch = 0.0
yaw = 0.0
joint_name = ["shoulder_pan_joint", "shoulder_lift_joint", "elbow_joint", "wrist_1_joint", "wrist_2_joint", "wrist_3_joint"]
joint_command_interfaces = ["position", "position", "position", "position", "position", "position"]
joint_initial_values = [0.0, -1.57, 0.0, -1.57, 0.0, 0.0]

obj = stage.GetPrimAtPath(articulation_path)
if obj.IsValid():
    print("is valid")
    obj_xform = UsdGeom.Xformable(obj)
    obj_xform.ClearXformOpOrder()

    translate_op = obj_xform.AddTranslateOp()
    translate_op.Set((x, y, z))

    rotate_op = obj_xform.AddRotateXYZOp()
    rotate_op.Set((roll*180.0/math.pi, pitch*180.0/math.pi, yaw*180.0/math.pi))
    
    dc = _dynamic_control.acquire_dynamic_control_interface()
    art = dc.get_articulation(articulation_path)
        
    for index in range(len(joint_name)):
        dof_ptr = dc.find_articulation_dof(art, joint_name[index])
        if joint_command_interfaces[index] == "position":
            dc.set_dof_position(dof_ptr, joint_initial_values[index])
            dc.set_dof_position_target(dof_ptr, joint_initial_values[index])

        elif joint_command_interfaces[index] == "velocity":
            dc.set_dof_velocity(dof_ptr, joint_initial_values[index])
            dc.set_dof_velocity_target(dof_ptr, joint_initial_values[index])

I hope this is helpful.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.