-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add correction to rrbot launch using arguments and reuse the main fil…
…e for starting examples.
- Loading branch information
Showing
6 changed files
with
206 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
ros2_control_demo_robot/description/rrbot/rrbot.materials.xacro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 12 additions & 5 deletions
17
ros2_control_demo_robot/description/rrbot/rrbot_system_position_only.ros2_control.xacro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
104
ros2_control_demo_robot/launch/rrbot_system_position_only.launch.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
]) |