|
33 | 33 | from rclpy.node import Node |
34 | 34 | from controller_manager_msgs.srv import SwitchController |
35 | 35 | from builtin_interfaces.msg import Duration |
| 36 | +from geometry_msgs.msg import Twist |
36 | 37 | from std_msgs.msg import Header |
37 | 38 | from std_srvs.srv import Trigger |
38 | 39 |
|
|
42 | 43 | Pose, |
43 | 44 | PoseStamped, |
44 | 45 | Wrench, |
45 | | - WrenchStamped, |
46 | 46 | Vector3, |
47 | 47 | ) |
48 | 48 |
|
|
55 | 55 | node = Node("robot_driver_test") |
56 | 56 | robot = Robot(node) |
57 | 57 |
|
58 | | - # Activate force mode controller |
| 58 | + # Add force mode service to service interfaces and re-init robot |
| 59 | + robot.service_interfaces.update({"/force_mode_controller/start_force_mode": SetForceMode}) |
| 60 | + robot.service_interfaces.update({"/force_mode_controller/stop_force_mode": Trigger}) |
| 61 | + robot.init_robot() |
| 62 | + time.sleep(0.5) |
| 63 | + # Press play on the robot |
| 64 | + robot.call_service("/dashboard_client/play", Trigger.Request()) |
| 65 | + |
| 66 | + time.sleep(0.5) |
| 67 | + # Start controllers |
59 | 68 | robot.call_service( |
60 | 69 | "/controller_manager/switch_controller", |
61 | 70 | SwitchController.Request( |
62 | | - activate_controllers=["force_mode_controller", "scaled_joint_trajectory_controller"], |
| 71 | + deactivate_controllers=["scaled_joint_trajectory_controller"], |
| 72 | + activate_controllers=["passthrough_trajectory_controller", "force_mode_controller"], |
63 | 73 | strictness=SwitchController.Request.BEST_EFFORT, |
64 | 74 | ), |
65 | 75 | ) |
66 | 76 |
|
67 | | - # Add force mode service to service interfaces and re-init robot |
68 | | - robot.service_interfaces.update({"/force_mode_controller/start_force_mode": SetForceMode}) |
69 | | - robot.init_robot() |
70 | | - time.sleep(2) |
71 | | - # Press play on the robot |
72 | | - robot.call_service("/dashboard_client/play", Trigger.Request()) |
73 | | - |
74 | 77 | # Move robot in to position |
75 | 78 | robot.send_trajectory( |
76 | 79 | waypts=[[-1.5707, -1.5707, -1.5707, -1.5707, 1.5707, 0]], |
77 | | - time_vec=[Duration(sec=6, nanosec=0)], |
| 80 | + time_vec=[Duration(sec=5, nanosec=0)], |
| 81 | + action_client=robot.passthrough_trajectory_action_client, |
78 | 82 | ) |
79 | 83 |
|
80 | 84 | # Finished moving |
81 | | - |
82 | 85 | # Create task frame for force mode |
83 | 86 | point = Point(x=0.0, y=0.0, z=0.0) |
84 | | - orientation = Quaternion(x=0.0, y=0.0, z=0.0, w=0.0) |
| 87 | + orientation = Quaternion(x=0.0, y=0.0, z=0.0, w=1.0) |
85 | 88 | task_frame_pose = Pose() |
86 | 89 | task_frame_pose.position = point |
87 | 90 | task_frame_pose.orientation = orientation |
|
96 | 99 | compliance = [False, False, True, False, False, False] |
97 | 100 |
|
98 | 101 | # Create Wrench message for force mode |
99 | | - wrench_vec = Wrench(force=Vector3(x=0.0, y=0.0, z=-10.0), torque=Vector3(x=0.0, y=0.0, z=0.0)) |
100 | | - wrench_stamp = WrenchStamped(header=header, wrench=wrench_vec) |
| 102 | + wrench_vec = Wrench(force=Vector3(x=0.0, y=0.0, z=-20.0), torque=Vector3(x=0.0, y=0.0, z=0.0)) |
101 | 103 | # Specify interpretation of task frame (no transform) |
102 | 104 | type_spec = SetForceMode.Request.NO_TRANSFORM |
103 | 105 |
|
104 | 106 | # Specify max speeds and deviations of force mode |
105 | | - limits = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0] |
| 107 | + speed_limits = Twist() |
| 108 | + speed_limits.linear = Vector3(x=0.0, y=0.0, z=1.0) |
| 109 | + speed_limits.angular = Vector3(x=0.0, y=0.0, z=1.0) |
| 110 | + deviation_limits = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0] |
106 | 111 |
|
107 | 112 | # specify damping and gain scaling |
108 | | - damping_factor = 0.025 |
109 | | - gain_scale = 0.5 |
| 113 | + damping_factor = 0.1 |
| 114 | + gain_scale = 0.8 |
110 | 115 |
|
111 | 116 | req = SetForceMode.Request() |
112 | 117 | req.task_frame = frame_stamp |
|
116 | 121 | req.selection_vector_rx = compliance[3] |
117 | 122 | req.selection_vector_ry = compliance[4] |
118 | 123 | req.selection_vector_rz = compliance[5] |
119 | | - req.wrench = wrench_stamp |
| 124 | + req.wrench = wrench_vec |
120 | 125 | req.type = type_spec |
121 | | - req.limits = limits |
| 126 | + req.speed_limits = speed_limits |
| 127 | + req.deviation_limits = deviation_limits |
122 | 128 | req.damping_factor = damping_factor |
123 | 129 | req.gain_scaling = gain_scale |
124 | 130 |
|
125 | 131 | # Send request to controller |
| 132 | + node.get_logger().info(f"Starting force mode with {req}") |
126 | 133 | robot.call_service("/force_mode_controller/start_force_mode", req) |
127 | | - |
128 | | - time.sleep(15) |
129 | | - # Deactivate force mode controller |
130 | | - robot.call_service( |
131 | | - "/controller_manager/switch_controller", |
132 | | - SwitchController.Request( |
133 | | - deactivate_controllers=["force_mode_controller"], |
134 | | - strictness=SwitchController.Request.BEST_EFFORT, |
135 | | - ), |
| 134 | + robot.send_trajectory( |
| 135 | + waypts=[[1.5707, -1.5707, -1.5707, -1.5707, 1.5707, 0]], |
| 136 | + time_vec=[Duration(sec=5, nanosec=0)], |
| 137 | + action_client=robot.passthrough_trajectory_action_client, |
136 | 138 | ) |
| 139 | + |
| 140 | + time.sleep(3) |
| 141 | + node.get_logger().info("Deactivating force mode controller.") |
| 142 | + robot.call_service("/force_mode_controller/stop_force_mode", Trigger.Request()) |
0 commit comments