Skip to content

Commit

Permalink
Add correction to rrbot launch using arguments and reuse the main fil…
Browse files Browse the repository at this point in the history
…e for starting examples.
  • Loading branch information
destogl committed Apr 17, 2021
1 parent 9f09c40 commit 7fd0229
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<!--
Copied and modified from ROS1 example:
Copied and modified from ROS1 example -
https://github.com/ros-simulation/gazebo_ros_demos/blob/kinetic-devel/rrbot_description/urdf/rrbot.gazebo
-->
<robot xmlns:xacro="http://ros.org/wiki/xacro">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<!--
Copied from ROS1 example:
Copied from ROS1 example -
https://github.com/ros-simulation/gazebo_ros_demos/blob/kinetic-devel/rrbot_description/urdf/materials.xacro
-->
<robot>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">

<xacro:macro name="rrbot_system_position_only" params="name prefix slowdown:=2.0">
<xacro:macro name="rrbot_system_position_only" params="name prefix use_fake_hardware:=^|true fake_sensor_commands:=^|false slowdown:=2.0">

<ros2_control name="${name}" type="system">
<hardware>
<plugin>ros2_control_demo_hardware/RRBotSystemPositionOnlyHardware</plugin>
<param name="example_param_hw_start_duration_sec">2.0</param>
<param name="example_param_hw_stop_duration_sec">3.0</param>
<param name="example_param_hw_slowdown">${slowdown}</param>
<xacro:if value="${use_fake_hardware}">
<plugin>fake_components/GenericSystem</plugin>
<param name="fake_sensor_commands">${fake_sensor_commands}</param>
<param name="state_following_offset">0.0</param>
</xacro:if>
<xacro:unless value="${use_fake_hardware}">
<plugin>ros2_control_demo_hardware/RRBotSystemPositionOnlyHardware</plugin>
<param name="example_param_hw_start_duration_sec">2.0</param>
<param name="example_param_hw_stop_duration_sec">3.0</param>
<param name="example_param_hw_slowdown">${slowdown}</param>
</xacro:unless>
</hardware>
<joint name="joint1">
<command_interface name="position">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<?xml version="1.0"?>
<!-- Revolute-Revolute Manipulator -->
<!--
Copied and modified from ROS1 example:
Copied and modified from ROS1 example -
https://github.com/ros-simulation/gazebo_ros_demos/blob/kinetic-devel/rrbot_description/urdf/rrbot.xacro
-->
<robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="2dof_robot">

<!-- Enable setting arguments from the launch file -->
<xacro:arg name="use_fake_hardware" default="true" />
<xacro:arg name="fake_sensor_commands" default="false" />
<xacro:arg name="prefix" default="" />
<xacro:arg name="slowdown" default="2.0" />

<!-- Import RRBot macro -->
Expand All @@ -27,12 +30,16 @@ https://github.com/ros-simulation/gazebo_ros_demos/blob/kinetic-devel/rrbot_desc
<static>true</static>
</gazebo>

<xacro:rrbot parent="world" prefix="">
<xacro:rrbot parent="world" prefix="$(arg prefix)">
<origin xyz="0 0 0" rpy="0 0 0" />
</xacro:rrbot>

<xacro:rrbot_gazebo prefix="" />
<xacro:rrbot_gazebo prefix="$(arg prefix)" />

<xacro:rrbot_system_position_only name="RRBotSystemPositionOnly" prefix="" slowdown="$(arg slowdown)" />
<xacro:rrbot_system_position_only
name="RRBotSystemPositionOnly" prefix="$(arg prefix)"
use_fake_hardware="$(arg use_fake_hardware)"
fake_sensor_commands="$(arg fake_sensor_commands)"
slowdown="$(arg slowdown)" />

</robot>
135 changes: 135 additions & 0 deletions ros2_control_demo_robot/launch/rrbot.launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Copyright 2021 Stogl Robotics Consulting UG (haftungsbeschränkt)
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, ExecuteProcess
from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution

from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare


def generate_launch_description():
# Declare arguments
declared_arguments = []
declared_arguments.append(DeclareLaunchArgument(
'controllers_package', default_value='ros2_control_demo_robot',
description='Package with the controller\'s configuration in "config" folder. \
Usually the argument is not set, it enables use of a custom setup.'))
declared_arguments.append(DeclareLaunchArgument(
'controllers_file', default_value='rrbot_controllers.yaml',
description='YAML file with the controllers configuration.'))
declared_arguments.append(DeclareLaunchArgument(
'description_package', default_value='ros2_control_demo_robot',
description='Description package with robot URDF/xacro files. Usually the argument \
is not set, it enables use of a custom description.'))
declared_arguments.append(DeclareLaunchArgument(
'description_file', default_value='',
description='URDF/XACRO description file with the robot.'))
declared_arguments.append(DeclareLaunchArgument(
'prefix', default_value='""', description='Prefix of the joint names, useful for \
multi-robot setup. If changed than also joint names in the controllers\' configuration \
have to be updated.'))
declared_arguments.append(DeclareLaunchArgument(
'use_fake_hardware', default_value='true',
description='Start robot with fake hardware mirroring command to its states.'))
declared_arguments.append(DeclareLaunchArgument(
'fake_sensor_commands', default_value='false',
description='Enable fake command interfaces for sensors used for simple simulations. \
Used only if \'use_fake_hardware\' parameter is true.'))
declared_arguments.append(DeclareLaunchArgument(
'slowdown', default_value='3.0', description='Slowdown factor of the RRbot.'))
declared_arguments.append(DeclareLaunchArgument(
'robot_controller', default_value='forward_position_controller',
description='Robot controller to start.'))

# Initialize Arguments
controllers_package = LaunchConfiguration('controllers_package')
controllers_file = LaunchConfiguration('controllers_file')
description_package = LaunchConfiguration('description_package')
description_file = LaunchConfiguration('description_file')
prefix = LaunchConfiguration('prefix')
use_fake_hardware = LaunchConfiguration('use_fake_hardware')
fake_sensor_commands = LaunchConfiguration('fake_sensor_commands')
slowdown = LaunchConfiguration('slowdown')
robot_controller = LaunchConfiguration('robot_controller')

# Get URDF via xacro
robot_description_content = Command([
PathJoinSubstitution([FindExecutable(name='xacro')]),
' ',
PathJoinSubstitution([FindPackageShare(description_package),
'description', description_file]),
' ',
'prefix:=', prefix, ' ',
'use_fake_hardware:=', use_fake_hardware, ' ',
'fake_sensor_commands:=', fake_sensor_commands, ' ',
'slowdown:=', slowdown,
])

robot_description = {'robot_description': robot_description_content}

robot_controllers = PathJoinSubstitution([
FindPackageShare(controllers_package),
'config',
controllers_file,
])
rviz_config_file = PathJoinSubstitution([
FindPackageShare(description_package),
'rviz',
'rrbot.rviz'
])

control_node = Node(
package='controller_manager',
executable='ros2_control_node',
parameters=[robot_description, robot_controllers],
output={
'stdout': 'screen',
'stderr': 'screen',
},
)
robot_state_pub_node = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
output='both',
parameters=[robot_description]
)
rviz_node = Node(
package='rviz2',
executable='rviz2',
name='rviz2',
output='log',
arguments=['-d', rviz_config_file],
)

joint_state_controller_spawner = Node(
package='controller_manager',
executable='spawner.py',
arguments=['joint_state_controller', '--controller-manager', '/controller_manager'])

robot_controller_spawner = Node(
package='controller_manager',
executable='spawner.py',
arguments=[robot_controller, '-c', '/controller_manager'])

return LaunchDescription(
declared_arguments +
[
control_node,
robot_state_pub_node,
rviz_node,
joint_state_controller_spawner,
robot_controller_spawner,
])
104 changes: 46 additions & 58 deletions ros2_control_demo_robot/launch/rrbot_system_position_only.launch.py
Original file line number Diff line number Diff line change
@@ -1,74 +1,62 @@
# Copyright 2021 Stogl Robotics Consulting UG (haftungsbeschränkt)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch_ros.actions import Node

import xacro
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration, ThisLaunchFileDir


def generate_launch_description():

# Get URDF via xacro
robot_description_path = os.path.join(
get_package_share_directory('ros2_control_demo_robot'),
'description',
'rrbot_system_position_only.urdf.xacro')
robot_description_config = xacro.process_file(robot_description_path,
mappings={'slowdown': '3.0'})
robot_description = {'robot_description': robot_description_config.toxml()}

rrbot_forward_controller = os.path.join(
get_package_share_directory('ros2_control_demo_robot'),
'config',
'rrbot_controllers.yaml'
)
rviz_config_file = os.path.join(
get_package_share_directory('ros2_control_demo_robot'),
'rviz',
'rrbot.rviz'
)

control_node = Node(
package='controller_manager',
executable='ros2_control_node',
parameters=[robot_description, rrbot_forward_controller],
output={
'stdout': 'screen',
'stderr': 'screen',
},
)
robot_state_publisher_node = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
output='both',
parameters=[robot_description]
)
rviz_node = Node(
package='rviz2',
executable='rviz2',
name='rviz2',
output='log',
arguments=['-d', rviz_config_file],
)

return LaunchDescription([
control_node,
robot_state_publisher_node,
rviz_node,
])
# Declare arguments
declared_arguments = []
declared_arguments.append(DeclareLaunchArgument(
'prefix', default_value='""', description='Prefix of the joint names, useful for \
multi-robot setup. If changed than also joint names in the controllers\' configuration \
have to be updated.'))
declared_arguments.append(DeclareLaunchArgument(
'use_fake_hardware', default_value='true',
description='Start robot with fake hardware mirroring command to its states.'))
declared_arguments.append(DeclareLaunchArgument(
'fake_sensor_commands', default_value='false',
description='Enable fake command interfaces for sensors used for simple simulations. \
Used only if \'use_fake_hardware\' parameter is true.'))
declared_arguments.append(DeclareLaunchArgument(
'slowdown', default_value='3.0', description='Slowdown factor of the RRbot.'))
declared_arguments.append(DeclareLaunchArgument(
'robot_controller', default_value='forward_position_controller',
description='Robot controller to start.'))

# Initialize Arguments
prefix = LaunchConfiguration('prefix')
use_fake_hardware = LaunchConfiguration('use_fake_hardware')
fake_sensor_commands = LaunchConfiguration('fake_sensor_commands')
slowdown = LaunchConfiguration('slowdown')
robot_controller = LaunchConfiguration('robot_controller')

base_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource([ThisLaunchFileDir(), '/rrbot.launch.py']),
launch_arguments={'description_file': 'rrbot_system_position_only.urdf.xacro',
'prefix': prefix,
'use_fake_hardware': use_fake_hardware,
'fake_sensor_commands': fake_sensor_commands,
'slowdown': slowdown,
'robot_controller': robot_controller,
}.items())

return LaunchDescription(
declared_arguments +
[
base_launch,
])

0 comments on commit 7fd0229

Please sign in to comment.