-
Notifications
You must be signed in to change notification settings - Fork 28
/
gazebo_launch.py
157 lines (133 loc) · 5.52 KB
/
gazebo_launch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# Launches the lidarbot in Gazebo to be controlled using a joystick. There are a number of launch arguments that can be toggled.
# Such as using the gazebo_ros package or the ros2_control package, using Gazebo's sim time or not.
#
# File adapted from https://automaticaddison.com
import os
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
from launch.conditions import IfCondition
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare
def generate_launch_description():
# Set the path to different files and folders
pkg_path = FindPackageShare(package="lidarbot_gazebo").find("lidarbot_gazebo")
pkg_description = FindPackageShare(package="lidarbot_description").find(
"lidarbot_description"
)
pkg_teleop = FindPackageShare(package="lidarbot_teleop").find("lidarbot_teleop")
pkg_gazebo_ros = FindPackageShare(package="gazebo_ros").find("gazebo_ros")
pkg_navigation = FindPackageShare(package="lidarbot_navigation").find(
"lidarbot_navigation"
)
gazebo_params_file = os.path.join(pkg_path, "config/gazebo_params.yaml")
twist_mux_params_file = os.path.join(pkg_teleop, "config/twist_mux.yaml")
ekf_params_file = os.path.join(pkg_navigation, "config/ekf.yaml")
world_filename = "obstacles.world"
world_path = os.path.join(pkg_path, "worlds", world_filename)
# Launch configuration variables specific to simulation
use_sim_time = LaunchConfiguration("use_sim_time")
use_ros2_control = LaunchConfiguration("use_ros2_control")
world = LaunchConfiguration("world")
use_robot_localization = LaunchConfiguration("use_robot_localization")
# Declare the launch arguments
declare_use_sim_time_cmd = DeclareLaunchArgument(
name="use_sim_time",
default_value="True",
description="Use simulation (Gazebo) clock if true",
)
declare_use_ros2_control_cmd = DeclareLaunchArgument(
name="use_ros2_control",
default_value="True",
description="Use ros2_control if true",
)
declare_world_cmd = DeclareLaunchArgument(
name="world",
default_value=world_path,
description="Full path to the world model to load",
)
declare_use_robot_localization_cmd = DeclareLaunchArgument(
name="use_robot_localization",
default_value="True",
description="Use robot_localization package if true",
)
# Start robot state publisher
start_robot_state_publisher_cmd = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
[os.path.join(pkg_description, "launch", "robot_state_publisher_launch.py")]
),
launch_arguments={
"use_sim_time": use_sim_time,
"use_ros2_control": use_ros2_control,
}.items(),
)
# Launch Gazebo
start_gazebo_cmd = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
[os.path.join(pkg_gazebo_ros, "launch", "gazebo.launch.py")]
),
launch_arguments={
"world": world,
"extra_gazebo_args": "--ros-args --params-file " + gazebo_params_file,
}.items(),
)
# Spawn robot in Gazebo
start_spawner_cmd = Node(
package="gazebo_ros",
executable="spawn_entity.py",
output="screen",
arguments=["-topic", "robot_description", "-entity", "lidarbot"],
)
# Spawn diff_controller
start_diff_controller_cmd = Node(
condition=IfCondition(use_ros2_control),
package="controller_manager",
executable="spawner",
arguments=["diff_controller", "--controller-manager", "/controller_manager"],
)
# Spawn joint_state_broadcaser
start_joint_broadcaster_cmd = Node(
condition=IfCondition(use_ros2_control),
package="controller_manager",
executable="spawner",
arguments=["joint_broadcaster", "--controller-manager", "/controller_manager"],
)
# Start robot localization using an Extended Kalman Filter
start_robot_localization_cmd = Node(
condition=IfCondition(use_robot_localization),
package="robot_localization",
executable="ekf_node",
parameters=[ekf_params_file],
remappings=[("/odometry/filtered", "/odom")],
)
# Start joystick node for use with ros2_control
start_joystick_cmd = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
[os.path.join(pkg_teleop, "launch", "joystick_launch.py")]
)
)
# Start twist mux
start_twist_mux_cmd = Node(
package="twist_mux",
executable="twist_mux",
parameters=[twist_mux_params_file, {"use_sim_time": True}],
remappings=[("/cmd_vel_out", "/diff_controller/cmd_vel_unstamped")],
)
# Create the launch description and populate
ld = LaunchDescription()
# Declare the launch options
ld.add_action(declare_use_sim_time_cmd)
ld.add_action(declare_use_ros2_control_cmd)
ld.add_action(declare_world_cmd)
ld.add_action(declare_use_robot_localization_cmd)
# Add any actions
ld.add_action(start_robot_state_publisher_cmd)
ld.add_action(start_gazebo_cmd)
ld.add_action(start_spawner_cmd)
ld.add_action(start_diff_controller_cmd)
ld.add_action(start_joint_broadcaster_cmd)
ld.add_action(start_robot_localization_cmd)
ld.add_action(start_joystick_cmd)
ld.add_action(start_twist_mux_cmd)
return ld