Skip to content

Commit b52e926

Browse files
committed
Moved example move, updated cmake
1 parent 96739b2 commit b52e926

File tree

4 files changed

+32
-47
lines changed

4 files changed

+32
-47
lines changed

ur_robot_driver/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,13 @@ ament_python_install_package(${PROJECT_NAME})
159159
install(PROGRAMS
160160
scripts/tool_communication.py
161161
scripts/wait_for_robot_description
162-
scripts/example_move.py
163162
scripts/start_ursim.sh
163+
DESTINATION lib/${PROJECT_NAME}
164+
)
165+
166+
# Install examples
167+
install(PROGRAMS
168+
examples/example_move.py
164169
examples/force_mode.py
165170
examples/robot_class.py
166171
examples/passthrough.py
File renamed without changes.

ur_robot_driver/examples/passthrough.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@
4646
[-0.5, -2.0, -0.5, -2.0, -0.4, -1.0],
4747
[-1, -2.5998, -1.004, -2.676, -0.992, -1.5406],
4848
]
49+
time_vec = [
50+
Duration(sec=2, nanosec=0),
51+
Duration(sec=6, nanosec=0),
52+
Duration(sec=10, nanosec=0),
53+
Duration(sec=14, nanosec=0),
54+
Duration(sec=18, nanosec=0),
55+
]
56+
4957
# Velocities and accelerations can be omitted
5058
vels = [
5159
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
@@ -61,35 +69,10 @@
6169
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
6270
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
6371
]
64-
bad_vels = [
65-
[0.1, 0.1, 0.1, 0.1, 0.1],
66-
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
67-
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
68-
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
69-
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
70-
]
71-
bad_accels = [
72-
[0.1, 0.1, 0.1, 0.1, 0.1],
73-
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
74-
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
75-
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
76-
[0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
77-
]
78-
time_vec = [
79-
Duration(sec=2, nanosec=0),
80-
Duration(sec=6, nanosec=0),
81-
Duration(sec=10, nanosec=0),
82-
Duration(sec=14, nanosec=0),
83-
Duration(sec=18, nanosec=0),
84-
]
8572

8673
# Execute trajectory on robot, make sure that the robot is booted and the control script is running
8774
robot.play()
8875
# Trajectory using positions, velocities and accelerations
8976
robot.passthrough_trajectory(waypts, time_vec, vels, accels)
9077
# Trajectory using only positions
9178
robot.passthrough_trajectory(waypts, time_vec)
92-
93-
robot.passthrough_trajectory(waypts, time_vec, bad_vels, accels)
94-
95-
robot.passthrough_trajectory(waypts, time_vec, vels, bad_accels)

ur_robot_driver/examples/robot_class.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
from rclpy.node import Node
3636
from trajectory_msgs.msg import JointTrajectory as JTmsg, JointTrajectoryPoint
3737
from ur_msgs.srv import SetIO, SetForceMode
38-
from ur_msgs.action import TrajectoryUntil, ToolContact
3938
from controller_manager_msgs.srv import (
4039
UnloadController,
4140
LoadController,
@@ -51,6 +50,8 @@
5150
TIMEOUT_WAIT_SERVICE_INITIAL = 60
5251
TIMEOUT_WAIT_ACTION = 10
5352

53+
MOTION_CONTROLLERS = ["passthrough_trajectory_controller", "scaled_joint_trajectory_controller"]
54+
5455
ROBOT_JOINTS = [
5556
"shoulder_pan_joint",
5657
"shoulder_lift_joint",
@@ -148,7 +149,7 @@ def set_io(self, pin, value):
148149

149150
self.call_service(Services.Set_IO, set_io_req)
150151

151-
def follow_trajectory(self, waypts, time_vec):
152+
def follow_trajectory(self, waypts: list[list[float]], time_vec: list[float]):
152153
# No other motion controllers can be active at the same time as the scaled joint controller
153154
self.switch_controllers(
154155
["scaled_joint_trajectory_controller"],
@@ -185,10 +186,10 @@ def follow_trajectory(self, waypts, time_vec):
185186

186187
def passthrough_trajectory(
187188
self,
188-
waypts: list[float],
189+
waypts: list[list[float]],
189190
time_vec: list[float],
190-
vels: list[float] = [],
191-
accels: list[float] = [],
191+
vels: list[list[float]] = [],
192+
accels: list[list[float]] = [],
192193
goal_time_tolerance=Duration(sec=1),
193194
):
194195
# The scaled joint controller can't be active at the same time as the passthrough controller
@@ -219,9 +220,7 @@ def passthrough_trajectory(
219220
raise Exception("trajectory was not accepted")
220221

221222
# Verify execution
222-
result = self.get_result(
223-
Actions.PASSTHROUGH_TRAJECTORY, goal_response
224-
)
223+
result = self.get_result(Actions.PASSTHROUGH_TRAJECTORY, goal_response)
225224
return result
226225

227226
def call_service(self, Service: Services, request):
@@ -255,7 +254,7 @@ def load_controller(self, controller_name: str):
255254
# Find loaded controllers
256255
for controller in list_response.controller:
257256
names.append(controller.name)
258-
# Check whether the passthrough controller is already loaded
257+
# Check whether the controller is already loaded
259258
try:
260259
names.index(controller_name)
261260
except ValueError:
@@ -264,9 +263,7 @@ def load_controller(self, controller_name: str):
264263
self.call_service(Services.Load_Controller, load_request)
265264
configure_request = ConfigureController.Request(name=controller_name)
266265
self.call_service(Services.Configure_Controller, configure_request)
267-
list_response = robot.call_service(
268-
Services.List_Controllers, ListControllers.Request()
269-
)
266+
list_response = self.call_service(Services.List_Controllers, ListControllers.Request())
270267
names.clear()
271268
# Update the list of controller names.
272269
for controller in list_response.controller:
@@ -286,10 +283,10 @@ def switch_controllers(self, active: list[str] = [], inactive: list[str] = []) -
286283
switch_request.activate_asap = False
287284
switch_request.timeout = Duration(sec=2, nanosec=0)
288285
return self.call_service(Services.Switch_Controller, switch_request)
289-
286+
290287
def start_force_mode(self, req: SetForceMode.Request):
291288
return self.call_service(Services.start_force_mode, req)
292-
289+
293290
def stop_force_mode(self):
294291
return self.call_service(Services.stop_force_mode, Trigger.Request())
295292

@@ -299,15 +296,15 @@ def stop_force_mode(self):
299296
node = Node("robot_driver_test")
300297
print("Available actions:")
301298
for action in Actions:
302-
print(action.name)
303-
print(action.value.name)
304-
print(action.value.action_type)
299+
print("Action Enum name: ", action.name)
300+
print("Action Ros name: ", action.value.name)
301+
print("Action Ros type: ", action.value.action_type)
305302
print("Available services:")
306303
for service in Services:
307-
print(service.name)
308-
print(service.value.name)
309-
print(service.value.service_type)
310-
304+
print("Service Enum name: ", service.name)
305+
print("Service Ros name: ", service.value.name)
306+
print("Service Ros type: ", service.value.service_type)
307+
311308
# robot = Robot(node)
312309
# robot.switch_controllers(
313310
# ["passthrough_trajectory_controller"], ["scaled_joint_trajectory_controller"]

0 commit comments

Comments
 (0)