Skip to content

Commit 79cd4f2

Browse files
author
AndyZe
authored
Hardware interface framework (#3)
* Updating ur_robot_driver include guards and namespaces * Compile the ros_control plugin, inherit from components::SystemInterface * Do away with intermediate SystemInterface class * Implement configure() * Add controller_manager launch file * Cleanup and clang format
1 parent 5f6fd85 commit 79cd4f2

File tree

12 files changed

+193
-213
lines changed

12 files changed

+193
-213
lines changed

ur_robot_driver/CMakeLists.txt

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,59 +12,72 @@ if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
1212
endif()
1313

1414
find_package(ament_cmake REQUIRED)
15+
find_package(hardware_interface REQUIRED)
16+
find_package(pluginlib REQUIRED)
17+
find_package(rclcpp REQUIRED)
1518
find_package(ur_client_library REQUIRED)
1619
find_package(ur_dashboard_msgs REQUIRED)
1720

1821
include_directories(
1922
include
20-
${Boost_INCLUDE_DIRS}
2123
)
2224

2325
set(THIS_PACKAGE_INCLUDE_DEPENDS
26+
hardware_interface
27+
pluginlib
28+
rclcpp
29+
ur_client_library
2430
ur_dashboard_msgs
2531
)
2632

2733
add_library(ur_robot_driver_plugin
34+
SHARED
2835
src/dashboard_client_ros.cpp
2936
src/hardware_interface.cpp
3037
)
31-
target_link_libraries(ur_robot_driver_plugin ur_client_library::urcl)
32-
ament_target_dependencies(ur_robot_driver_plugin ${${PROJECT_NAME}_EXPORTED_TARGETS} ${THIS_PACKAGE_INCLUDE_DEPENDS})
33-
34-
add_executable(ur_robot_driver_node
35-
src/dashboard_client_ros.cpp
36-
src/hardware_interface.cpp
37-
src/hardware_interface_node.cpp
38-
)
39-
target_link_libraries(ur_robot_driver_node ${catkin_LIBRARIES} ur_client_library::urcl)
40-
ament_target_dependencies(ur_robot_driver_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${THIS_PACKAGE_INCLUDE_DEPENDS})
41-
42-
add_executable(dashboard_client
43-
src/dashboard_client_ros.cpp
44-
src/dashboard_client_node.cpp
38+
target_link_libraries(
39+
ur_robot_driver_plugin
40+
ur_client_library::urcl
4541
)
46-
target_link_libraries(dashboard_client ${catkin_LIBRARIES} ur_client_library::urcl)
47-
ament_target_dependencies(dashboard_client ${${PROJECT_NAME}_EXPORTED_TARGETS} ${THIS_PACKAGE_INCLUDE_DEPENDS})
48-
49-
add_executable(robot_state_helper
50-
src/robot_state_helper.cpp
51-
src/robot_state_helper_node.cpp
42+
target_include_directories(
43+
ur_robot_driver_plugin
44+
PRIVATE
45+
include
5246
)
53-
target_link_libraries(robot_state_helper ${catkin_LIBRARIES} ur_client_library::urcl)
54-
ament_target_dependencies(robot_state_helper ${${PROJECT_NAME}_EXPORTED_TARGETS} ${THIS_PACKAGE_INCLUDE_DEPENDS})
55-
56-
if(CATKIN_ENABLE_TESTING)
57-
find_package(rostest REQUIRED)
58-
59-
add_rostest(test/driver.test)
60-
endif()
61-
62-
63-
install(TARGETS ur_robot_driver_plugin ur_robot_driver_node robot_state_helper dashboard_client
64-
ARCHIVE DESTINATION lib}
65-
LIBRARY DESTINATION lib}
66-
RUNTIME DESTINATION bin}
47+
ament_target_dependencies(
48+
ur_robot_driver_plugin
49+
${${PROJECT_NAME}_EXPORTED_TARGETS}
50+
${THIS_PACKAGE_INCLUDE_DEPENDS}
6751
)
52+
pluginlib_export_plugin_description_file(hardware_interface hardware_interface_plugin.xml)
53+
54+
# add_executable(ur_robot_driver_node
55+
# src/dashboard_client_ros.cpp
56+
# src/hardware_interface.cpp
57+
# src/hardware_interface_node.cpp
58+
# )
59+
# target_link_libraries(ur_robot_driver_node ${catkin_LIBRARIES} ur_client_library::urcl)
60+
# ament_target_dependencies(ur_robot_driver_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${THIS_PACKAGE_INCLUDE_DEPENDS})
61+
62+
# add_executable(dashboard_client
63+
# src/dashboard_client_ros.cpp
64+
# src/dashboard_client_node.cpp
65+
# )
66+
# target_link_libraries(dashboard_client ${catkin_LIBRARIES} ur_client_library::urcl)
67+
# ament_target_dependencies(dashboard_client ${${PROJECT_NAME}_EXPORTED_TARGETS} ${THIS_PACKAGE_INCLUDE_DEPENDS})
68+
69+
# add_executable(robot_state_helper
70+
# src/robot_state_helper.cpp
71+
# src/robot_state_helper_node.cpp
72+
# )
73+
# target_link_libraries(robot_state_helper ${catkin_LIBRARIES} ur_client_library::urcl)
74+
# ament_target_dependencies(robot_state_helper ${${PROJECT_NAME}_EXPORTED_TARGETS} ${THIS_PACKAGE_INCLUDE_DEPENDS})
75+
76+
# install(TARGETS ur_robot_driver_plugin ur_robot_driver_node robot_state_helper dashboard_client
77+
# ARCHIVE DESTINATION lib}
78+
# LIBRARY DESTINATION lib}
79+
# RUNTIME DESTINATION bin}
80+
# )
6881

6982
install(PROGRAMS scripts/tool_communication
7083
DESTINATION bin
@@ -79,10 +92,6 @@ install(DIRECTORY include/
7992
DESTINATION include
8093
)
8194

82-
install(FILES hardware_interface_plugin.xml
83-
DESTINATION share/${PROJECT_NAME}
84-
)
85-
8695
ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS})
8796

8897
ament_package()
Lines changed: 18 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,19 @@
1-
# Settings for ros_control control loop
2-
hardware_control_loop:
3-
loop_hz: &loop_hz 125
41

5-
# Settings for ros_control hardware interface
6-
ur_hardware_interface:
7-
joints: &robot_joints
8-
- shoulder_pan_joint
9-
- shoulder_lift_joint
10-
- elbow_joint
11-
- wrist_1_joint
12-
- wrist_2_joint
13-
- wrist_3_joint
14-
15-
# Publish all joint states ----------------------------------
16-
joint_state_controller:
17-
type: joint_state_controller/JointStateController
18-
publish_rate: *loop_hz
19-
20-
# Publish wrench ----------------------------------
21-
force_torque_sensor_controller:
22-
type: force_torque_sensor_controller/ForceTorqueSensorController
23-
publish_rate: *loop_hz
24-
25-
# Publish speed_scaling factor
26-
speed_scaling_state_controller:
27-
type: ur_controllers/SpeedScalingStateController
28-
publish_rate: *loop_hz
29-
30-
# Joint Trajectory Controller - position based -------------------------------
31-
# For detailed explanations of parameter see http://wiki.ros.org/joint_trajectory_controller
32-
scaled_pos_joint_traj_controller:
33-
type: position_controllers/ScaledJointTrajectoryController
34-
joints: *robot_joints
35-
constraints:
36-
goal_time: 0.6
37-
stopped_velocity_tolerance: 0.05
38-
shoulder_pan_joint: {trajectory: 0.2, goal: 0.1}
39-
shoulder_lift_joint: {trajectory: 0.2, goal: 0.1}
40-
elbow_joint: {trajectory: 0.2, goal: 0.1}
41-
wrist_1_joint: {trajectory: 0.2, goal: 0.1}
42-
wrist_2_joint: {trajectory: 0.2, goal: 0.1}
43-
wrist_3_joint: {trajectory: 0.2, goal: 0.1}
44-
stop_trajectory_duration: 0.5
45-
state_publish_rate: *loop_hz
46-
action_monitor_rate: 20
47-
48-
pos_joint_traj_controller:
49-
type: position_controllers/JointTrajectoryController
50-
joints: *robot_joints
51-
constraints:
52-
goal_time: 0.6
53-
stopped_velocity_tolerance: 0.05
54-
shoulder_pan_joint: {trajectory: 0.2, goal: 0.1}
55-
shoulder_lift_joint: {trajectory: 0.2, goal: 0.1}
56-
elbow_joint: {trajectory: 0.2, goal: 0.1}
57-
wrist_1_joint: {trajectory: 0.2, goal: 0.1}
58-
wrist_2_joint: {trajectory: 0.2, goal: 0.1}
59-
wrist_3_joint: {trajectory: 0.2, goal: 0.1}
60-
stop_trajectory_duration: 0.5
61-
state_publish_rate: *loop_hz
62-
action_monitor_rate: 20
63-
64-
scaled_vel_joint_traj_controller:
65-
type: velocity_controllers/ScaledJointTrajectoryController
66-
joints: *robot_joints
67-
constraints:
68-
goal_time: 0.6
69-
stopped_velocity_tolerance: 0.05
70-
shoulder_pan_joint: {trajectory: 0.1, goal: 0.1}
71-
shoulder_lift_joint: {trajectory: 0.1, goal: 0.1}
72-
elbow_joint: {trajectory: 0.1, goal: 0.1}
73-
wrist_1_joint: {trajectory: 0.1, goal: 0.1}
74-
wrist_2_joint: {trajectory: 0.1, goal: 0.1}
75-
wrist_3_joint: {trajectory: 0.1, goal: 0.1}
76-
gains:
77-
#!!These values have not been optimized!!
78-
shoulder_pan_joint: {p: 5.0, i: 0.05, d: 0.1, i_clamp: 1}
79-
shoulder_lift_joint: {p: 5.0, i: 0.05, d: 0.1, i_clamp: 1}
80-
elbow_joint: {p: 5.0, i: 0.05, d: 0.1, i_clamp: 1}
81-
wrist_1_joint: {p: 5.0, i: 0.05, d: 0.1, i_clamp: 1}
82-
wrist_2_joint: {p: 5.0, i: 0.05, d: 0.1, i_clamp: 1}
83-
wrist_3_joint: {p: 5.0, i: 0.05, d: 0.1, i_clamp: 1}
84-
# Use a feedforward term to reduce the size of PID gains
85-
velocity_ff:
86-
shoulder_pan_joint: 1.0
87-
shoulder_lift_joint: 1.0
88-
elbow_joint: 1.0
89-
wrist_1_joint: 1.0
90-
wrist_2_joint: 1.0
91-
wrist_3_joint: 1.0
92-
stop_trajectory_duration: 0.5
93-
state_publish_rate: *loop_hz
94-
action_monitor_rate: 20
95-
96-
vel_joint_traj_controller:
97-
type: velocity_controllers/JointTrajectoryController
98-
joints: *robot_joints
99-
constraints:
100-
goal_time: 0.6
101-
stopped_velocity_tolerance: 0.05
102-
shoulder_pan_joint: {trajectory: 0.1, goal: 0.1}
103-
shoulder_lift_joint: {trajectory: 0.1, goal: 0.1}
104-
elbow_joint: {trajectory: 0.1, goal: 0.1}
105-
wrist_1_joint: {trajectory: 0.1, goal: 0.1}
106-
wrist_2_joint: {trajectory: 0.1, goal: 0.1}
107-
wrist_3_joint: {trajectory: 0.1, goal: 0.1}
108-
gains:
109-
#!!These values have not been optimized!!
110-
shoulder_pan_joint: {p: 5.0, i: 0.05, d: 0.1, i_clamp: 1}
111-
shoulder_lift_joint: {p: 5.0, i: 0.05, d: 0.1, i_clamp: 1}
112-
elbow_joint: {p: 5.0, i: 0.05, d: 0.1, i_clamp: 1}
113-
wrist_1_joint: {p: 5.0, i: 0.05, d: 0.1, i_clamp: 1}
114-
wrist_2_joint: {p: 5.0, i: 0.05, d: 0.1, i_clamp: 1}
115-
wrist_3_joint: {p: 5.0, i: 0.05, d: 0.1, i_clamp: 1}
116-
# Use a feedforward term to reduce the size of PID gains
117-
velocity_ff:
118-
shoulder_pan_joint: 1.0
119-
shoulder_lift_joint: 1.0
120-
elbow_joint: 1.0
121-
wrist_1_joint: 1.0
122-
wrist_2_joint: 1.0
123-
wrist_3_joint: 1.0
124-
stop_trajectory_duration: 0.5
125-
state_publish_rate: *loop_hz
126-
action_monitor_rate: 20
127-
128-
# Pass an array of joint velocities directly to the joints
129-
joint_group_vel_controller:
130-
type: velocity_controllers/JointGroupVelocityController
131-
joints: *robot_joints
132-
133-
robot_status_controller:
134-
type: industrial_robot_status_controller/IndustrialRobotStatusController
135-
handle_name: industrial_robot_status_handle
136-
publish_rate: 10
2+
control_manager:
3+
ros__parameters:
4+
controllers:
5+
- joint_trajectory_controller_position
6+
7+
joint_trajectory_controller_position:
8+
type: joint_trajectory_controller/JointTrajectoryController
9+
10+
forward_command_controller_position:
11+
ros__parameters:
12+
joints:
13+
- joint_1
14+
- joint_2
15+
- joint_3
16+
- joint_4
17+
- joint_5
18+
- joint_6
19+
interface_name: position
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
<library path="lib/libur_robot_driver_plugin">
2-
<class name="ur_driver/HardwareInterface" type="ur_driver::HardwareInterface" base_class_type="hardware_interface::RobotHW">
1+
<library path="ur_robot_driver_plugin">
2+
<class name="ur_robot_driver/URHardwareInterface"
3+
type="ur_robot_driver::URHardwareInterface"
4+
base_class_type="hardware_interface::RobotHardwareInterface">
35
<description>
4-
Universal Robots ROS Driver as plugin
6+
ROS2 Control System Driver for the Universal Robots series.
57
</description>
68
</class>
7-
</library>
9+
</library>

ur_robot_driver/include/ur_robot_driver/dashboard_client_ros.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
*/
2626
//----------------------------------------------------------------------
2727

28-
#ifndef UR_ROBOT_DRIVER_ROS_DASHBOARD_CLIENT_H_INCLUDED
29-
#define UR_ROBOT_DRIVER_ROS_DASHBOARD_CLIENT_H_INCLUDED
28+
#pragma once
3029

3130
#include <regex>
3231

@@ -44,7 +43,7 @@
4443
#include <ur_dashboard_msgs/srv/popup.hpp>
4544
#include <ur_dashboard_msgs/srv/raw_request.hpp>
4645

47-
namespace ur_driver
46+
namespace ur_robot_driver
4847
{
4948
/*!
5049
* \brief ROS wrapper for UR's dashboard server access. Many (not necessarily all) dashboard
@@ -53,5 +52,4 @@ namespace ur_driver
5352
class DashboardClientROS
5453
{
5554
};
56-
} // namespace ur_driver
57-
#endif // ifndef UR_ROBOT_DRIVER_ROS_DASHBOARD_CLIENT_H_INCLUDED
55+
} // namespace ur_robot_driver

ur_robot_driver/include/ur_robot_driver/hardware_interface.h

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,58 @@
2424
*
2525
*/
2626
//----------------------------------------------------------------------
27-
#ifndef UR_DRIVER_HARDWARE_INTERFACE_H_INCLUDED
28-
#define UR_DRIVER_HARDWARE_INTERFACE_H_INCLUDED
27+
#pragma once
2928

30-
namespace ur_driver
29+
// System
30+
#include <memory>
31+
#include <vector>
32+
33+
// ros2_control hardware_interface
34+
#include "hardware_interface/hardware_info.hpp"
35+
#include "hardware_interface/components/actuator.hpp"
36+
#include "hardware_interface/components/sensor.hpp"
37+
#include "hardware_interface/components/system_interface.hpp"
38+
#include "hardware_interface/types/hardware_interface_return_values.hpp"
39+
#include "hardware_interface/types/hardware_interface_status_values.hpp"
40+
#include "hardware_interface/visibility_control.h"
41+
42+
// ROS
43+
#include "rclcpp/macros.hpp"
44+
45+
using hardware_interface::HardwareInfo;
46+
using hardware_interface::return_type;
47+
using hardware_interface::status;
48+
using hardware_interface::components::Actuator;
49+
using hardware_interface::components::Sensor;
50+
51+
namespace ur_robot_driver
3152
{
3253
/*!
3354
* \brief The HardwareInterface class handles the interface between the ROS system and the main
3455
* driver. It contains the read and write methods of the main control loop and registers various ROS
3556
* topics and services.
3657
*/
37-
class HardwareInterface
58+
class URHardwareInterface : public hardware_interface::components::SystemInterface
3859
{
39-
};
60+
public:
61+
RCLCPP_SHARED_PTR_DEFINITIONS(URHardwareInterface);
4062

41-
} // namespace ur_driver
63+
hardware_interface::return_type configure(const HardwareInfo& system_info) final;
64+
65+
status get_status() const final
66+
{
67+
return status_;
68+
}
69+
70+
return_type start() final;
71+
return_type stop() final;
72+
return_type read() final;
73+
return_type write() final;
74+
75+
protected:
76+
HardwareInfo info_;
77+
status status_;
78+
std::vector<double> joint_angle_commands_, current_joint_angles_;
79+
};
4280

43-
#endif // ifndef UR_DRIVER_HARDWARE_INTERFACE_H_INCLUDED
81+
} // namespace ur_robot_driver

0 commit comments

Comments
 (0)