Skip to content

Commit 3c088d2

Browse files
committed
pre-commit fixes
1 parent 2092664 commit 3c088d2

File tree

3 files changed

+84
-48
lines changed

3 files changed

+84
-48
lines changed

smacc2_sm_reference_library/sm_panda_cl_moveit2z_cb_inventory_isaacsim/launch/sm_panda_cl_moveit2z_cb_inventory_isaacsim.launch.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,14 @@ def launch_setup(context, *args, **kwargs):
201201
name="trajectory_bridge",
202202
output="screen",
203203
prefix=trajectory_bridge_prefix,
204-
parameters=[{
205-
"joint_command_topic": "joint_commands",
206-
"joint_state_topic": "joint_states",
207-
"action_name": "panda_arm_controller/follow_joint_trajectory",
208-
"use_sim_time": True,
209-
}],
204+
parameters=[
205+
{
206+
"joint_command_topic": "joint_commands",
207+
"joint_state_topic": "joint_states",
208+
"action_name": "panda_arm_controller/follow_joint_trajectory",
209+
"use_sim_time": True,
210+
}
211+
],
210212
arguments=["--ros-args", "--log-level", "INFO"],
211213
)
212214

smacc2_sm_reference_library/sm_panda_cl_moveit2z_cb_inventory_isaacsim/scripts/setup_ros2_bridge.py

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@
8989
path_str = str(prim.GetPath())
9090
if "panda" in path_str.lower() or "franka" in path_str.lower():
9191
# Show robot prims up to 5 levels deep
92-
if path_str.count("/") <= 5 and ("instanceable" in path_str.lower() or path_str.endswith("panda")):
92+
if path_str.count("/") <= 5 and (
93+
"instanceable" in path_str.lower() or path_str.endswith("panda")
94+
):
9395
print(f" Found: {path_str} (type: {prim.GetTypeName()})")
9496
print("\nAll top-level prims under /World:")
9597
world_prim = stage.GetPrimAtPath("/World")
@@ -168,10 +170,22 @@
168170
("Context.outputs:context", "PublishClock.inputs:context"),
169171
("ReadSimTime.outputs:simulationTime", "PublishJointState.inputs:timeStamp"),
170172
("ReadSimTime.outputs:simulationTime", "PublishClock.inputs:timeStamp"),
171-
("SubscribeJointState.outputs:jointNames", "ArticulationController.inputs:jointNames"),
172-
("SubscribeJointState.outputs:positionCommand", "ArticulationController.inputs:positionCommand"),
173-
("SubscribeJointState.outputs:velocityCommand", "ArticulationController.inputs:velocityCommand"),
174-
("SubscribeJointState.outputs:effortCommand", "ArticulationController.inputs:effortCommand"),
173+
(
174+
"SubscribeJointState.outputs:jointNames",
175+
"ArticulationController.inputs:jointNames",
176+
),
177+
(
178+
"SubscribeJointState.outputs:positionCommand",
179+
"ArticulationController.inputs:positionCommand",
180+
),
181+
(
182+
"SubscribeJointState.outputs:velocityCommand",
183+
"ArticulationController.inputs:velocityCommand",
184+
),
185+
(
186+
"SubscribeJointState.outputs:effortCommand",
187+
"ArticulationController.inputs:effortCommand",
188+
),
175189
],
176190
og.Controller.Keys.SET_VALUES: [
177191
("ArticulationController.inputs:robotPath", FRANKA_STAGE_PATH),
@@ -184,6 +198,7 @@
184198
print(" MoveIt2 ActionGraph created successfully")
185199
except Exception as e:
186200
import traceback
201+
187202
print(f" ERROR creating MoveIt2 ActionGraph: {e}")
188203
print(f" Full traceback:")
189204
traceback.print_exc()
@@ -237,15 +252,30 @@
237252
("createViewport.outputs:execOut", "getRenderProduct.inputs:execIn"),
238253
("createViewport.outputs:viewport", "getRenderProduct.inputs:viewport"),
239254
("getRenderProduct.outputs:execOut", "setCamera.inputs:execIn"),
240-
("getRenderProduct.outputs:renderProductPath", "setCamera.inputs:renderProductPath"),
255+
(
256+
"getRenderProduct.outputs:renderProductPath",
257+
"setCamera.inputs:renderProductPath",
258+
),
241259
("setCamera.outputs:execOut", "cameraHelperRgb.inputs:execIn"),
242260
("setCamera.outputs:execOut", "cameraHelperInfo.inputs:execIn"),
243261
("setCamera.outputs:execOut", "cameraHelperDepth.inputs:execIn"),
244262
("setCamera.outputs:execOut", "cameraHelperPointCloud.inputs:execIn"),
245-
("getRenderProduct.outputs:renderProductPath", "cameraHelperRgb.inputs:renderProductPath"),
246-
("getRenderProduct.outputs:renderProductPath", "cameraHelperInfo.inputs:renderProductPath"),
247-
("getRenderProduct.outputs:renderProductPath", "cameraHelperDepth.inputs:renderProductPath"),
248-
("getRenderProduct.outputs:renderProductPath", "cameraHelperPointCloud.inputs:renderProductPath"),
263+
(
264+
"getRenderProduct.outputs:renderProductPath",
265+
"cameraHelperRgb.inputs:renderProductPath",
266+
),
267+
(
268+
"getRenderProduct.outputs:renderProductPath",
269+
"cameraHelperInfo.inputs:renderProductPath",
270+
),
271+
(
272+
"getRenderProduct.outputs:renderProductPath",
273+
"cameraHelperDepth.inputs:renderProductPath",
274+
),
275+
(
276+
"getRenderProduct.outputs:renderProductPath",
277+
"cameraHelperPointCloud.inputs:renderProductPath",
278+
),
249279
],
250280
og.Controller.Keys.SET_VALUES: [
251281
("createViewport.inputs:viewportId", 1),
@@ -271,6 +301,7 @@
271301

272302
except Exception as e:
273303
import traceback
304+
274305
print(f" ERROR creating ZED Camera OmniGraph: {e}")
275306
print(f" Full traceback:")
276307
traceback.print_exc()
@@ -301,7 +332,9 @@
301332
print(" 2. In a separate terminal, run:")
302333
print(" source /opt/ros/jazzy/setup.bash")
303334
print(" source ~/workspaces/isaac_ros-dev/install/setup.bash")
304-
print(" ros2 launch sm_panda_cl_moveit2z_cb_inventory_isaacsim sm_panda_cl_moveit2z_cb_inventory_isaacsim.launch.py")
335+
print(
336+
" ros2 launch sm_panda_cl_moveit2z_cb_inventory_isaacsim sm_panda_cl_moveit2z_cb_inventory_isaacsim.launch.py"
337+
)
305338
print("\n" + "=" * 60)
306339

307340
# Debug: Print panda structure if verbose

smacc2_sm_reference_library/sm_panda_cl_moveit2z_cb_inventory_isaacsim/scripts/trajectory_bridge.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,23 @@
2626

2727
class TrajectoryBridge(Node):
2828
def __init__(self):
29-
super().__init__('trajectory_bridge')
29+
super().__init__("trajectory_bridge")
3030

3131
self.callback_group = ReentrantCallbackGroup()
3232

3333
# Parameters
34-
self.declare_parameter('joint_command_topic', 'joint_commands')
35-
self.declare_parameter('joint_state_topic', 'joint_states')
36-
self.declare_parameter('action_name', 'panda_arm_controller/follow_joint_trajectory')
37-
self.declare_parameter('position_tolerance', 0.01) # radians
38-
self.declare_parameter('goal_time_tolerance', 1.0) # seconds
34+
self.declare_parameter("joint_command_topic", "joint_commands")
35+
self.declare_parameter("joint_state_topic", "joint_states")
36+
self.declare_parameter("action_name", "panda_arm_controller/follow_joint_trajectory")
37+
self.declare_parameter("position_tolerance", 0.01) # radians
38+
self.declare_parameter("goal_time_tolerance", 1.0) # seconds
3939

40-
joint_command_topic = self.get_parameter('joint_command_topic').value
41-
joint_state_topic = self.get_parameter('joint_state_topic').value
42-
action_name = self.get_parameter('action_name').value
40+
joint_command_topic = self.get_parameter("joint_command_topic").value
41+
joint_state_topic = self.get_parameter("joint_state_topic").value
42+
action_name = self.get_parameter("action_name").value
4343

4444
# Publisher for joint commands to Isaac Sim
45-
self.joint_command_pub = self.create_publisher(
46-
JointState,
47-
joint_command_topic,
48-
10
49-
)
45+
self.joint_command_pub = self.create_publisher(JointState, joint_command_topic, 10)
5046

5147
# Subscriber for joint states from Isaac Sim
5248
self.current_joint_state = None
@@ -56,7 +52,7 @@ def __init__(self):
5652
joint_state_topic,
5753
self.joint_state_callback,
5854
10,
59-
callback_group=self.callback_group
55+
callback_group=self.callback_group,
6056
)
6157

6258
# Action server for MoveIt2
@@ -67,13 +63,13 @@ def __init__(self):
6763
execute_callback=self.execute_trajectory,
6864
goal_callback=self.goal_callback,
6965
cancel_callback=self.cancel_callback,
70-
callback_group=self.callback_group
66+
callback_group=self.callback_group,
7167
)
7268

73-
self.get_logger().info(f'Trajectory Bridge started')
74-
self.get_logger().info(f' Action server: {action_name}')
75-
self.get_logger().info(f' Publishing commands to: {joint_command_topic}')
76-
self.get_logger().info(f' Subscribing to states from: {joint_state_topic}')
69+
self.get_logger().info(f"Trajectory Bridge started")
70+
self.get_logger().info(f" Action server: {action_name}")
71+
self.get_logger().info(f" Publishing commands to: {joint_command_topic}")
72+
self.get_logger().info(f" Subscribing to states from: {joint_state_topic}")
7773

7874
def joint_state_callback(self, msg):
7975
with self.joint_state_lock:
@@ -85,35 +81,37 @@ def get_current_joint_state(self):
8581

8682
def goal_callback(self, goal_request):
8783
"""Accept all trajectory goals"""
88-
self.get_logger().info('Received trajectory goal request - ACCEPTING')
84+
self.get_logger().info("Received trajectory goal request - ACCEPTING")
8985
return GoalResponse.ACCEPT
9086

9187
def cancel_callback(self, goal_handle):
9288
"""Accept all cancel requests"""
93-
self.get_logger().info('Received cancel request - ACCEPTING')
89+
self.get_logger().info("Received cancel request - ACCEPTING")
9490
return CancelResponse.ACCEPT
9591

9692
def execute_trajectory(self, goal_handle):
9793
"""Execute the trajectory received from MoveIt2"""
98-
self.get_logger().info('Received trajectory goal')
94+
self.get_logger().info("Received trajectory goal")
9995

10096
trajectory = goal_handle.request.trajectory
10197
joint_names = trajectory.joint_names
10298
points = trajectory.points
10399

104100
if len(points) == 0:
105-
self.get_logger().warn('Empty trajectory received')
101+
self.get_logger().warn("Empty trajectory received")
106102
goal_handle.succeed()
107103
result = FollowJointTrajectory.Result()
108104
result.error_code = FollowJointTrajectory.Result.SUCCESSFUL
109105
return result
110106

111-
self.get_logger().info(f'Executing trajectory with {len(points)} points for joints: {joint_names}')
107+
self.get_logger().info(
108+
f"Executing trajectory with {len(points)} points for joints: {joint_names}"
109+
)
112110

113111
# Get trajectory duration
114112
last_point = points[-1]
115113
total_duration = last_point.time_from_start.sec + last_point.time_from_start.nanosec * 1e-9
116-
self.get_logger().info(f'Trajectory duration: {total_duration:.2f} seconds')
114+
self.get_logger().info(f"Trajectory duration: {total_duration:.2f} seconds")
117115

118116
# Publish rate (Hz) - Isaac Sim needs frequent updates
119117
publish_rate = 50.0 # 50 Hz
@@ -135,7 +133,7 @@ def execute_trajectory(self, goal_handle):
135133
# Check if goal was canceled
136134
if goal_handle.is_cancel_requested:
137135
goal_handle.canceled()
138-
self.get_logger().info('Trajectory canceled')
136+
self.get_logger().info("Trajectory canceled")
139137
result = FollowJointTrajectory.Result()
140138
result.error_code = FollowJointTrajectory.Result.INVALID_GOAL
141139
return result
@@ -148,7 +146,10 @@ def execute_trajectory(self, goal_handle):
148146
break
149147

150148
# Find the surrounding trajectory points for interpolation
151-
while current_point_idx < len(points) - 1 and point_times[current_point_idx + 1] <= elapsed:
149+
while (
150+
current_point_idx < len(points) - 1
151+
and point_times[current_point_idx + 1] <= elapsed
152+
):
152153
current_point_idx += 1
153154

154155
# Get target position (interpolate if between points)
@@ -217,12 +218,12 @@ def execute_trajectory(self, goal_handle):
217218
self.joint_command_pub.publish(cmd)
218219
time.sleep(0.02)
219220

220-
self.get_logger().info('Trajectory execution completed')
221+
self.get_logger().info("Trajectory execution completed")
221222
goal_handle.succeed()
222223

223224
result = FollowJointTrajectory.Result()
224225
result.error_code = FollowJointTrajectory.Result.SUCCESSFUL
225-
self.get_logger().info('Trajectory execution completed successfully')
226+
self.get_logger().info("Trajectory execution completed successfully")
226227

227228
return result
228229

@@ -244,5 +245,5 @@ def main(args=None):
244245
rclpy.shutdown()
245246

246247

247-
if __name__ == '__main__':
248+
if __name__ == "__main__":
248249
main()

0 commit comments

Comments
 (0)