hello-robot / stretch_ros2

ROS 2 packages for the Stretch mobile manipulators from Hello Robot Inc.
https://docs.hello-robot.com/0.2/stretch-tutorials/ros2/
49 stars 19 forks source link

Trajectory Components with ToolNone #117

Open Artificys opened 1 month ago

Artificys commented 1 month ago

So, as far as I can tell, JointTrajectoryAction will always throw an error if there is no tool on the Stretch. When trying to execute the callback, on line 285 it'll clear each joint's trajectory manager. However, when it gets to the GripperComponent, since there is no 'device' named 'stretch_gripper' on the robot, it returns a NoneType with no trajectory_manager and will fail the trajectory.

I don't have the error anymore because I fixed it, but if needed I can undo it and get the error again.

My fix for it was to add another check in the trajectory_components.py:

def get_trajectory_components(robot):
    robot_status = robot.get_status()
    if 'wrist_pitch' in robot_status['end_of_arm']:
        return {component.name: component for component in [HeadPanComponent(robot),
                                                            HeadTiltComponent(robot),
                                                            WristYawComponent(robot),
                                                            WristPitchComponent(robot),
                                                            WristRollComponent(robot),
                                                            GripperComponent(robot),
                                                            ArmComponent(robot),
                                                            LiftComponent(robot),
                                                            BaseComponent(robot),
                                                            ]}
    elif 'stretch_gripper' in robot_status['end_of_arm']:
        return {component.name: component for component in [HeadPanComponent(robot),
                                                            HeadTiltComponent(robot),
                                                            WristYawComponent(robot),
                                                            GripperComponent(robot),
                                                            ArmComponent(robot),
                                                            LiftComponent(robot),
                                                            BaseComponent(robot),
                                                            ]}
    else:
        return {component.name: component for component in [HeadPanComponent(robot),
                                                            HeadTiltComponent(robot),
                                                            WristYawComponent(robot),
                                                            ArmComponent(robot),
                                                            LiftComponent(robot),
                                                            BaseComponent(robot),
                                                            ]}

Not sure if this is the correct way of doing this, but for now this fixes the error and lets the trajectory continue.

Artificys commented 1 month ago

This was also found while following the Align To Aruco example - which I know isn't in the new V0.3 docs, but the tutorial code is still there. Not sure if that matters, but worth noting.