|
| 1 | +"""Example script for using crisp_py with a UR robot. This example assumes you have the `ur_robot_driver` ROS package running and properly configured to control your UR robot.""" |
| 2 | +import time |
| 3 | +import numpy as np |
| 4 | + |
| 5 | +from crisp_py.robot import make_robot |
| 6 | +from crisp_py.utils.geometry import Pose |
| 7 | + |
| 8 | +robot = make_robot("ur") |
| 9 | +robot.wait_until_ready() |
| 10 | + |
| 11 | +#%% |
| 12 | + |
| 13 | +print(f"Starting pose: {robot.end_effector_pose}") |
| 14 | +print(f"Starting joint values: {robot.joint_values}") |
| 15 | + |
| 16 | +#%% |
| 17 | + |
| 18 | +print("Going to home position...") |
| 19 | +robot.home() # This requires the joint_trajectory_controller to be active |
| 20 | +homing_pose = robot.end_effector_pose.copy() |
| 21 | + |
| 22 | +print(f"Homing pose: {homing_pose}") |
| 23 | + |
| 24 | +#%% |
| 25 | + |
| 26 | +print("Switching to Cartesian Impedance Controller...") |
| 27 | +print("This will unload other controllers if necessary.") |
| 28 | + |
| 29 | +# Change parameters now if needed |
| 30 | +# robot.cartesian_controller_parameters_client.set_parameters([ |
| 31 | +# ("task.k_pos_x", 600.0), |
| 32 | +# ... |
| 33 | +# ]) |
| 34 | +robot.controller_switcher_client.switch_controller("cartesian_impedance_controller") |
| 35 | + |
| 36 | +#%% |
| 37 | + |
| 38 | +input("Press Enter to move to a new target pose... WARNING: ONLY USE FOR UR16, CHECK THE POSITION BEFORE PRESSING! (or change the position in the code)") |
| 39 | +# WARNING: the folowing position has been chosen for the UR16! |
| 40 | +target_position = np.array([0.0, 0.24, 0.75]) |
| 41 | +target_orientation = robot.end_effector_pose.orientation # Keep the same orientation |
| 42 | + |
| 43 | +new_target_pose = Pose(position=target_position, orientation=target_orientation) |
| 44 | +robot.move_to(pose=new_target_pose, speed=0.3) |
| 45 | + |
| 46 | +# This would publish this target directly to the controller, without any interpolation. Use with care! |
| 47 | +# robot.set_target(pose=new_target_pose) |
| 48 | + |
| 49 | +# %% |
| 50 | + |
| 51 | +print(f"Shutting down connection in 4 seconds... (robot will stay in place).") |
| 52 | +time.sleep(4.0) |
| 53 | + |
| 54 | +robot.shutdown() |
0 commit comments