feat: let Gazebo spawn MKMini
This commit is contained in:
@@ -5,7 +5,7 @@ import xml.etree.ElementTree as ET
|
||||
|
||||
from ament_index_python.packages import get_package_share_directory
|
||||
from launch import LaunchDescription
|
||||
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, OpaqueFunction
|
||||
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription, OpaqueFunction, SetEnvironmentVariable
|
||||
from launch.conditions import IfCondition
|
||||
from launch.launch_description_sources import PythonLaunchDescriptionSource
|
||||
from launch.substitutions import LaunchConfiguration
|
||||
@@ -233,6 +233,7 @@ def launch_gazebo(context):
|
||||
gazebo_ros_dir = get_package_share_directory('gazebo_ros')
|
||||
world = LaunchConfiguration('world').perform(context)
|
||||
render_mode = LaunchConfiguration('render_mode').perform(context).strip().lower()
|
||||
platform = LaunchConfiguration('platform').perform(context).strip().lower()
|
||||
|
||||
if render_mode not in {'flat', 'full'}:
|
||||
raise RuntimeError('render_mode must be either flat or full')
|
||||
@@ -247,7 +248,47 @@ def launch_gazebo(context):
|
||||
'worlds',
|
||||
world,
|
||||
)
|
||||
|
||||
if platform in {'turtlebot3', 'turtlebot3_burger', 'burger'}:
|
||||
entity_name = 'turtlebot3_burger_3d_lidar'
|
||||
model_path = os.path.join(gazebo_dir, 'models', 'turtlebot3_burger', 'model.sdf')
|
||||
model_directory = os.path.join(gazebo_dir, 'models')
|
||||
static_transforms = [
|
||||
Node(
|
||||
package='tf2_ros',
|
||||
executable='static_transform_publisher',
|
||||
name='turtlebot3_base_link_tf',
|
||||
arguments=[
|
||||
'--x', '0', '--y', '0', '--z', '0.01',
|
||||
'--roll', '0', '--pitch', '0', '--yaw', '0',
|
||||
'--frame-id', 'base_footprint', '--child-frame-id', 'base_link',
|
||||
],
|
||||
),
|
||||
Node(
|
||||
package='tf2_ros',
|
||||
executable='static_transform_publisher',
|
||||
name='turtlebot3_laser_tf',
|
||||
arguments=[
|
||||
'--x', '-0.032', '--y', '0', '--z', '0.171',
|
||||
'--roll', '0', '--pitch', '0', '--yaw', '0',
|
||||
'--frame-id', 'base_link', '--child-frame-id', 'base_scan',
|
||||
],
|
||||
),
|
||||
]
|
||||
elif platform in {'mkmini', 'mk-mini'}:
|
||||
entity_name = 'mkmini_gazebo'
|
||||
model_directory = os.path.join(simulator_dir, 'models')
|
||||
model_path = os.path.join(model_directory, 'mkmini_gazebo', 'model.sdf')
|
||||
static_transforms = []
|
||||
else:
|
||||
raise RuntimeError('platform must be turtlebot3 or mkmini')
|
||||
|
||||
existing_model_path = os.environ.get('GAZEBO_MODEL_PATH', '')
|
||||
return [
|
||||
SetEnvironmentVariable(
|
||||
name='GAZEBO_MODEL_PATH',
|
||||
value=os.pathsep.join(part for part in (model_directory, existing_model_path) if part),
|
||||
),
|
||||
IncludeLaunchDescription(
|
||||
PythonLaunchDescriptionSource(os.path.join(gazebo_ros_dir, 'launch', 'gzserver.launch.py')),
|
||||
launch_arguments={
|
||||
@@ -259,14 +300,15 @@ def launch_gazebo(context):
|
||||
package='gazebo_ros',
|
||||
executable='spawn_entity.py',
|
||||
arguments=[
|
||||
'-entity', 'turtlebot3_burger_3d_lidar',
|
||||
'-file', os.path.join(gazebo_dir, 'models', 'turtlebot3_burger', 'model.sdf'),
|
||||
'-entity', entity_name,
|
||||
'-file', model_path,
|
||||
'-x', LaunchConfiguration('x_pose').perform(context),
|
||||
'-y', LaunchConfiguration('y_pose').perform(context),
|
||||
'-z', '0.01',
|
||||
],
|
||||
output='screen',
|
||||
),
|
||||
*static_transforms,
|
||||
]
|
||||
|
||||
|
||||
@@ -276,29 +318,10 @@ def generate_launch_description():
|
||||
DeclareLaunchArgument('gui', default_value='false'),
|
||||
DeclareLaunchArgument('world', default_value='turtlebot3_world.world'),
|
||||
DeclareLaunchArgument('render_mode', default_value='flat'),
|
||||
DeclareLaunchArgument('platform', default_value='turtlebot3'),
|
||||
DeclareLaunchArgument('x_pose', default_value='-2.0'),
|
||||
DeclareLaunchArgument('y_pose', default_value='-0.5'),
|
||||
OpaqueFunction(function=launch_gazebo),
|
||||
Node(
|
||||
package='tf2_ros',
|
||||
executable='static_transform_publisher',
|
||||
name='turtlebot3_base_link_tf',
|
||||
arguments=[
|
||||
'--x', '0', '--y', '0', '--z', '0.01',
|
||||
'--roll', '0', '--pitch', '0', '--yaw', '0',
|
||||
'--frame-id', 'base_footprint', '--child-frame-id', 'base_link',
|
||||
],
|
||||
),
|
||||
Node(
|
||||
package='tf2_ros',
|
||||
executable='static_transform_publisher',
|
||||
name='turtlebot3_laser_tf',
|
||||
arguments=[
|
||||
'--x', '-0.032', '--y', '0', '--z', '0.171',
|
||||
'--roll', '0', '--pitch', '0', '--yaw', '0',
|
||||
'--frame-id', 'base_link', '--child-frame-id', 'base_scan',
|
||||
],
|
||||
),
|
||||
IncludeLaunchDescription(
|
||||
PythonLaunchDescriptionSource(os.path.join(gazebo_ros_dir, 'launch', 'gzclient.launch.py')),
|
||||
condition=IfCondition(LaunchConfiguration('gui')),
|
||||
|
||||
Reference in New Issue
Block a user