Skip to content

Commit a79f7c0

Browse files
committed
example force_osc_xyz_linear_path_gaussian_velocity works with ur5 and jaco2
1 parent 8521619 commit a79f7c0

File tree

4 files changed

+47
-75
lines changed

4 files changed

+47
-75
lines changed

abr_control/arms/isaacsim_config.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ def __init__(self, robot_type):
1515
robot_type: string
1616
the name of the arm model to load.
1717
"""
18-
1918
self.robot_type = robot_type
2019
self.env_idx = 0 # Assuming only one robot
2120
self.ee_link_name = "EE" # name used for virtual end-effector, overwritten if one exists already
@@ -26,8 +25,8 @@ def __init__(self, robot_type):
2625
self.EE_parent_link = "wrist_3_link"
2726
self.ee_offset=[0., 0., 0.]
2827
START_ANGLES = "0 -.67 -.67 0 0 0"
29-
self.target_min = np.array([-0.6, -0.5, 0.5])
30-
self.target_range = np.array([0.9, 1.1, 0.3])
28+
self.target_min = np.array([-0.4, -0.4, 0.3]) # np.array([-0.6, -0.5, 0.5])
29+
self.target_max = np.array([0.4, 0.4, 0.6])
3130
self.controlled_dof = ['shoulder_pan_joint', 'shoulder_lift_joint', 'elbow_joint', 'wrist_1_joint', 'wrist_2_joint', 'wrist_3_joint']
3231
print(f"Virtual end effector with name '{self.ee_link_name}' is attached, as robot has none.")
3332

@@ -37,8 +36,8 @@ def __init__(self, robot_type):
3736
self.EE_parent_link = "j2n6s300_link_6"
3837
self.ee_link_name = "j2n6s300_end_effector"
3938
START_ANGLES = "2.0 3.14 1.57 4.71 0.0 3.04"
40-
self.target_min = np.array([-0.5, -0.5, 0.5])
41-
self.target_range = [1, 1, 0.5]
39+
self.target_min = np.array([-0.4, -0.4, 0.3]) # np.array([-0.5, -0.5, 0.5])
40+
self.target_max = np.array([0.4, 0.4, 0.6])
4241
self.controlled_dof = ['j2n6s300_joint_1', 'j2n6s300_joint_2', 'j2n6s300_joint_3', 'j2n6s300_joint_4', 'j2n6s300_joint_5', 'j2n6s300_joint_6']
4342
print(f"End effector with name '{self.ee_link_name}' specified in UDS, using it ...")
4443

@@ -49,11 +48,7 @@ def __init__(self, robot_type):
4948
self.ee_offset=[0.26455, 0.00118, -0.0209] # for H1
5049
START_ANGLES = "0. 0. 0. 0."
5150
self.target_min = np.array([0.12, -0.4, 1.4])
52-
self.target_range = np.array([
53-
0.4 - 0.12, # x range
54-
0.05 - (-0.4), # y range
55-
2.2 - 1.4 # z range
56-
])
51+
self.target_max = np.array([0.4, 0.05, 2.2])
5752
self.controlled_dof = ['right_shoulder_pitch_joint','right_shoulder_roll_joint', 'right_shoulder_yaw_joint','right_elbow_joint']
5853
self.lock_prim_standing = '/World/robot/pelvis'
5954
print(f"Virtual end effector with name '{self.ee_link_name}' is attached, as robot has none.")
@@ -65,11 +60,7 @@ def __init__(self, robot_type):
6560
self.ee_link_name = "right_hand_link"
6661
START_ANGLES = "0. 0. 0. 0. 0."
6762
self.target_min = np.array([0.12, -0.4, 1.4])
68-
self.target_range = np.array([
69-
0.49 - 0.12, # x range
70-
0.05 - (-0.4), # y range
71-
2.2 - 1.4 # z range
72-
])
63+
self.target_max = np.array([0.49, 0.05, 2.2])
7364
self.controlled_dof = ['right_shoulder_pitch_joint','right_shoulder_roll_joint', 'right_shoulder_yaw_joint','right_elbow_joint','right_hand_joint']
7465
self.lock_prim_standing = '/World/robot/pelvis'
7566
print(f"End effector with name '{self.ee_link_name}' specified in UDS, using it ...")

abr_control/interfaces/nv_isaacsim.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def get_feedback(self):
157157
def set_xyz(self, name, xyz):
158158
"""Set the position of an object in the environment.
159159
160-
prim_path : string
160+
name : string
161161
the prim_path of the prim
162162
xyz : np.array
163163
the [x,y,z] location of the target [meters]
@@ -166,6 +166,23 @@ def set_xyz(self, name, xyz):
166166
xformable = UsdGeom.Xformable(prim)
167167
transform_matrix = Gf.Matrix4d().SetTranslate(Gf.Vec3d(xyz[0], xyz[1], xyz[2]))
168168
xformable.MakeMatrixXform().Set(transform_matrix)
169+
170+
171+
def set_orientation(self, name, quat_wxyz):
172+
"""Set the position of an object in the environment.
173+
174+
name : string
175+
the prim_path of the prim
176+
quat_wxyz : np.array
177+
the [w,x,y,z] quaternion representation of the target orientation
178+
"""
179+
prim = self.robot_config._get_prim(name)
180+
xformable = UsdGeom.Xformable(prim)
181+
quat = Gf.Quatd(quat_wxyz[0], Gf.Vec3d(quat_wxyz[1],
182+
quat_wxyz[2],
183+
quat_wxyz[3]))
184+
transform_matrix = Gf.Matrix4d().SetRotate(quat)
185+
xformable.MakeMatrixXform().Set(transform_matrix)
169186

170187

171188
# method that humanoid does not fall over
@@ -200,12 +217,16 @@ def create_target_prim(self, prim_path="/World/target", size = .1, color=np.arra
200217
cube_prim.GetPrim().CreateAttribute("physics:collisionEnabled", Sdf.ValueTypeNames.Bool).Set(False)
201218
return cube_prim
202219

203-
204-
def set_target_random(self, name="target"):
205-
target_min = self.robot_config.target_min
206-
target_range = self.robot_config.target_range
207-
target_xyz = target_min + np.random.rand(3) * target_range
208-
self.set_xyz(name, target_xyz)
220+
221+
def create_random_pos(self):
222+
pos_target = np.array(
223+
[
224+
np.random.uniform(low=self.robot_config.target_min[0], high=self.robot_config.target_max[0]),
225+
np.random.uniform(low=self.robot_config.target_min[1], high=self.robot_config.target_max[1]),
226+
np.random.uniform(low=self.robot_config.target_min[2], high=self.robot_config.target_max[2]),
227+
]
228+
)
229+
return pos_target
209230

210231

211232
# setting max_force via PhysX DriveAPI

examples/IsaacSim/force_osc_xyz.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
if len(sys.argv) > 1:
1616
arm_model = sys.argv[1]
1717
else:
18-
arm_model = "ur5" # "h1_hands" / "h1" / jaco2 / ur5
18+
arm_model = "h1" # works with "h1_hands" / "h1" / jaco2 / ur5
1919
robot_config = arm(arm_model)
2020

21-
dt = 0.005
21+
dt = 0.005 # 200 Hz
2222
target_name="target"
2323

2424
# create our IsaacSim interface
@@ -51,10 +51,7 @@
5151
try:
5252
# get the end-effector's initial position
5353
feedback = interface.get_feedback()
54-
start = robot_config.Tx(robot_config.ee_link_name, feedback["q"])
55-
56-
# make the target offset from that start position
57-
interface.set_target_random()
54+
interface.set_xyz("target", interface.create_random_pos())
5855

5956
count = 0
6057
print("\nSimulation starting...\n")

examples/IsaacSim/force_osc_xyz_linear_path_gaussian_velocity_WIP.py renamed to examples/IsaacSim/force_osc_xyz_linear_path_gaussian_velocity.py

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
if len(sys.argv) > 1:
2222
arm_model = sys.argv[1]
2323
else:
24-
arm_model = "jaco2"
25-
# initialize our robot config for the jaco2
24+
arm_model = "jaco2" # works with jaco2 / ur5
2625
robot_config = arm(arm_model)
2726

2827
ctrlr_dof = [True, True, True, False, False, False]
@@ -32,16 +31,14 @@
3231
print(stars)
3332
print(dof_print)
3433
print(stars)
35-
dt = 0.007 # 143 Hz
36-
#dt = 0.001 # 1000 Hz
34+
dt = 0.005 # 200 Hz
3735
target_prim_path="/World/target"
3836

3937
# create our interface
40-
interface = IsaacSim(robot_config, dt=dt)
38+
interface = IsaacSim(robot_config, dt)
4139
interface.connect()
4240
interface.send_target_angles(robot_config.START_ANGLES)
4341
isaac_target = interface.create_target_prim(prim_path=target_prim_path)
44-
interface.fix_arm_joint_gains()
4542

4643
# damp the movements of the arm
4744
damping = Damping(robot_config, kv=10)
@@ -66,35 +63,17 @@
6663
target_track = []
6764

6865

69-
70-
71-
72-
73-
74-
75-
76-
77-
78-
7966
print("\nSimulation starting...\n")
8067
for ii in range(0, n_targets):
8168
feedback = interface.get_feedback()
82-
hand_xyz = robot_config.Tx("EE", feedback["q"])
83-
84-
pos_target = np.array(
85-
[
86-
np.random.uniform(low=-0.4, high=0.4),
87-
np.random.uniform(low=-0.4, high=0.4),
88-
np.random.uniform(low=0.3, high=0.6),
89-
]
90-
)
91-
69+
hand_xyz = robot_config.Tx(robot_config.ee_link_name, feedback["q"])
70+
pos_target = interface.create_random_pos()
9271
path_planner.generate_path(
9372
start_position=hand_xyz, target_position=pos_target, max_velocity=2
9473
)
9574

96-
#interface.set_xyz("target", pos_target)
97-
interface.set_xyz(target_prim_path, pos_target)
75+
interface.set_xyz("target", pos_target)
76+
#interface.set_xyz(target_prim_path, pos_target)
9877
at_target = 0
9978
count = 0
10079

@@ -103,10 +82,9 @@
10382
break
10483
filtered_target = path_planner.next()
10584
interface.set_xyz(target_prim_path, filtered_target[:3])
106-
#interface.set_xyz("target_orientation", filtered_target[:3])
10785

10886
feedback = interface.get_feedback()
109-
hand_xyz = robot_config.Tx("EE", feedback["q"])
87+
hand_xyz = robot_config.Tx(robot_config.ee_link_name, feedback["q"])
11088

11189
u = ctrlr.generate(
11290
q=feedback["q"],
@@ -128,26 +106,11 @@
128106
count += 1
129107

130108

131-
132-
133-
134-
135-
136-
137-
138-
139-
140-
141-
142-
143-
144-
145-
146109
try:
147110
print("\nSimulation starting...\n")
148111
for ii in range(0, n_targets):
149112
feedback = interface.get_feedback()
150-
hand_xyz = robot_config.Tx("EE", feedback["q"])
113+
hand_xyz = robot_config.Tx(robot_config.ee_link_name, feedback["q"])
151114

152115
pos_target = np.array(
153116
[
@@ -174,7 +137,7 @@
174137
#interface.set_xyz("target_orientation", filtered_target[:3])
175138

176139
feedback = interface.get_feedback()
177-
hand_xyz = robot_config.Tx("EE", feedback["q"])
140+
hand_xyz = robot_config.Tx(robot_config.ee_link_name, feedback["q"])
178141

179142
u = ctrlr.generate(
180143
q=feedback["q"],

0 commit comments

Comments
 (0)