Skip to content

Commit 2578755

Browse files
author
Felix Exner
committed
Add mock components ros2_control example
1 parent 65b7f31 commit 2578755

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,11 @@ parameters file.
8181
As mentioned above, see the `urdf/ur.urdf.xacro` file as an example to integrate a UR robot into
8282
your scene description. Basically, you could create a copy of that file and extend it with the
8383
modifications from your specific scene.
84+
85+
### Using description with ros2_control
86+
The description itself does not contain a `ros2_control` tag. However, the package provides a couple
87+
of helper files to create your own `ros2_control` tag describing the robot's joint control
88+
mechanisms. See the [`urdf/ur_mocked.urdf.xacro`](urdf/ur_mocked.urdf.xacro)
89+
file as an example using [mock
90+
hardware](https://control.ros.org/master/doc/ros2_control/hardware_interface/doc/mock_components_userdoc.html)
91+
to control the robot.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0"?>
2+
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">
3+
4+
<xacro:include filename="$(find ur_description)/urdf/inc/ur_joint_control.xacro" />
5+
<xacro:include filename="$(find ur_description)/urdf/inc/ur_sensors.xacro" />
6+
7+
<xacro:macro name="ur_ros2_control" params="
8+
name
9+
tf_prefix
10+
mock_sensor_commands:=false
11+
initial_positions:=${dict(shoulder_pan_joint=0.0,shoulder_lift_joint=-1.57,elbow_joint=0.0,wrist_1_joint=-1.57,wrist_2_joint=0.0,wrist_3_joint=0.0)}
12+
">
13+
14+
<ros2_control name="${name}" type="system">
15+
<hardware>
16+
<plugin>mock_components/GenericSystem</plugin>
17+
<param name="mock_sensor_commands">${mock_sensor_commands}</param>
18+
<param name="state_following_offset">0.0</param>
19+
</hardware>
20+
<xacro:ur_joint_control_description
21+
tf_prefix="${tf_prefix}"
22+
initial_positions="${initial_positions}"
23+
/>
24+
25+
<xacro:ur_sensors
26+
tf_prefix="${tf_prefix}"
27+
/>
28+
</ros2_control>
29+
</xacro:macro>
30+
</robot>

urdf/ur_mocked.urdf.xacro

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0"?>
2+
<robot xmlns:xacro="http://wiki.ros.org/xacro" name="$(arg name)">
3+
<!-- robot name parameter -->
4+
<xacro:arg name="name" default="ur"/>
5+
<!-- import main macro -->
6+
<xacro:include filename="$(find ur_description)/urdf/ur_macro.xacro"/>
7+
<xacro:include filename="$(find ur_description)/urdf/ros2_control_mock_hardware.xacro" />
8+
9+
<!-- possible 'ur_type' values: ur3, ur3e, ur5, ur5e, ur10, ur10e, ur16e, ur20 -->
10+
<!-- the default value should raise an error in case this was called without defining the type -->
11+
<xacro:arg name="ur_type" default="ur5x"/>
12+
13+
<!-- parameters -->
14+
<xacro:arg name="tf_prefix" default="" />
15+
<xacro:arg name="joint_limit_params" default="$(find ur_description)/config/$(arg ur_type)/joint_limits.yaml"/>
16+
<xacro:arg name="kinematics_params" default="$(find ur_description)/config/$(arg ur_type)/default_kinematics.yaml"/>
17+
<xacro:arg name="physical_params" default="$(find ur_description)/config/$(arg ur_type)/physical_parameters.yaml"/>
18+
<xacro:arg name="visual_params" default="$(find ur_description)/config/$(arg ur_type)/visual_parameters.yaml"/>
19+
<xacro:arg name="transmission_hw_interface" default=""/>
20+
<xacro:arg name="safety_limits" default="false"/>
21+
<xacro:arg name="safety_pos_margin" default="0.15"/>
22+
<xacro:arg name="safety_k_position" default="20"/>
23+
<xacro:arg name="mock_sensor_commands" default="false" />
24+
25+
<!--When using gazebo simulations absolute paths are necessary.-->
26+
<xacro:arg name="force_abs_paths" default="false" />
27+
28+
<!-- initial position for simulations (Mock Hardware, Gazebo, Ignition) -->
29+
<xacro:arg name="initial_positions_file" default="$(find ur_description)/config/initial_positions.yaml"/>
30+
31+
<!-- convert to property to use substitution in function -->
32+
<xacro:property name="initial_positions_file" default="$(arg initial_positions_file)"/>
33+
34+
<!-- create link fixed to the "world" -->
35+
<link name="world" />
36+
37+
<!-- arm -->
38+
<xacro:ur_robot
39+
name="$(arg name)"
40+
tf_prefix="$(arg tf_prefix)"
41+
parent="world"
42+
joint_limits_parameters_file="$(arg joint_limit_params)"
43+
kinematics_parameters_file="$(arg kinematics_params)"
44+
physical_parameters_file="$(arg physical_params)"
45+
visual_parameters_file="$(arg visual_params)"
46+
safety_limits="$(arg safety_limits)"
47+
safety_pos_margin="$(arg safety_pos_margin)"
48+
safety_k_position="$(arg safety_k_position)"
49+
force_abs_paths="$(arg force_abs_paths)"
50+
>
51+
<origin xyz="0 0 0" rpy="0 0 0" /> <!-- position robot in the world -->
52+
</xacro:ur_robot>
53+
54+
<!-- ros2 control instance -->
55+
<xacro:ur_ros2_control
56+
name="$(arg name)"
57+
tf_prefix="$(arg tf_prefix)"
58+
mock_sensor_commands="$(arg mock_sensor_commands)"
59+
initial_positions="${xacro.load_yaml(initial_positions_file)}"
60+
/>
61+
</robot>

0 commit comments

Comments
 (0)