Skip to content

Commit f21b561

Browse files
authored
Parameterize the flight stack for MAVROS (#41)
* Start to paramaterize the flight stack * Reduce some code duplication Signed-off-by: Ryan Friedman <ryanfriedman5410+github@gmail.com> * Add default value of PX4 * Only PX4 works right now * When ArduPilot also works, the default can be removed Signed-off-by: Ryan Friedman <ryanfriedman5410+github@gmail.com> --------- Signed-off-by: Ryan Friedman <ryanfriedman5410+github@gmail.com>
1 parent c02e5a3 commit f21b561

File tree

1 file changed

+64
-22
lines changed

1 file changed

+64
-22
lines changed
Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,48 @@
11
import os
22

3+
from launch.actions import DeclareLaunchArgument
4+
from launch.substitutions import TextSubstitution
35
from ament_index_python.packages import get_package_share_directory
46
from launch import LaunchDescription
7+
from launch.conditions.launch_configuration_equals import LaunchConfigurationEquals
58
from launch_ros.actions import Node
69

710

11+
FLIGHT_STACK_PX4 = "px4"
12+
FLIGHT_STACK_ARDUPILOT = "ardupilot"
13+
FLIGHT_STACK_ARG_NAME = "flight_stack"
14+
15+
816
def generate_launch_description():
917
# package directories
1018
pkg_mavros = get_package_share_directory("mavros")
1119
pkg_terrain_navigation_ros = get_package_share_directory("terrain_navigation_ros")
1220

13-
# TODO: remove hardcoding
21+
FLIGHT_STACK_CONFIGS = {
22+
FLIGHT_STACK_PX4: {
23+
"fcu_url": "udp://127.0.0.1:14540@14557",
24+
"config_yaml": os.path.join(pkg_mavros, "launch", "px4_config.yaml"),
25+
"pluginlists_yaml": os.path.join(
26+
pkg_mavros, "launch", "px4_pluginlists.yaml"
27+
),
28+
},
29+
FLIGHT_STACK_ARDUPILOT: {
30+
"fcu_url": "udp://127.0.0.1:14551@14555",
31+
"config_yaml": os.path.join(
32+
pkg_terrain_navigation_ros, "config", "ap_config.yaml"
33+
),
34+
"pluginlists_yaml": os.path.join(
35+
pkg_terrain_navigation_ros, "config", "ap_pluginlists.yaml"
36+
),
37+
},
38+
}
1439

15-
# mavros config
16-
# ardupilot
17-
fcu_url = "udp://127.0.0.1:14551@14555"
18-
# px4
19-
fcu_url = "udp://127.0.0.1:14540@14557"
40+
flight_stack_arg = DeclareLaunchArgument(
41+
FLIGHT_STACK_ARG_NAME,
42+
default_value=FLIGHT_STACK_PX4,
43+
choices=[FLIGHT_STACK_PX4, FLIGHT_STACK_ARDUPILOT],
44+
description="Autopilot Type - See https://github.com/ROS-Aerial/aerial_robotic_landscape/blob/main/autopilots_suites.md",
45+
)
2046

2147
gcs_url = ""
2248
tgt_system = 1
@@ -25,36 +51,52 @@ def generate_launch_description():
2551
respawn_mavros = False
2652
namespace = "mavros"
2753

28-
# ardupilot
29-
config_yaml = os.path.join(pkg_terrain_navigation_ros, "config", "ap_config.yaml")
30-
pluginlists_yaml = os.path.join(
31-
pkg_terrain_navigation_ros, "config", "ap_pluginlists.yaml"
54+
condition_px4 = LaunchConfigurationEquals(
55+
FLIGHT_STACK_ARG_NAME, [TextSubstitution(text=FLIGHT_STACK_PX4)]
56+
)
57+
58+
condition_ardupilot = LaunchConfigurationEquals(
59+
FLIGHT_STACK_ARG_NAME, [TextSubstitution(text=FLIGHT_STACK_ARDUPILOT)]
3260
)
33-
# px4
34-
config_yaml = os.path.join(pkg_mavros, "launch", "px4_config.yaml")
35-
pluginlists_yaml = os.path.join(pkg_mavros, "launch", "px4_pluginlists.yaml")
3661

37-
# mavros node
38-
mavros = Node(
62+
# mavros node for PX4
63+
mavros_px4 = Node(
64+
condition=condition_px4,
3965
package="mavros",
4066
executable="mavros_node",
4167
namespace=namespace,
4268
parameters=[
43-
{"fcu_url": fcu_url},
69+
{"fcu_url": FLIGHT_STACK_CONFIGS[FLIGHT_STACK_PX4]["fcu_url"]},
4470
{"gcs_url": gcs_url},
4571
{"tgt_system": tgt_system},
4672
{"tgt_component": tgt_component},
4773
{"fcu_protocol": fcu_protocol},
48-
pluginlists_yaml,
49-
config_yaml,
74+
FLIGHT_STACK_CONFIGS[FLIGHT_STACK_PX4]["pluginlists_yaml"],
75+
FLIGHT_STACK_CONFIGS[FLIGHT_STACK_PX4]["config_yaml"],
5076
],
5177
remappings=[],
5278
respawn=respawn_mavros,
5379
output="screen",
5480
)
5581

56-
return LaunchDescription(
57-
[
58-
mavros,
59-
]
82+
# mavros node for PX4
83+
mavros_ardupilot = Node(
84+
condition=condition_ardupilot,
85+
package="mavros",
86+
executable="mavros_node",
87+
namespace=namespace,
88+
parameters=[
89+
{"fcu_url": FLIGHT_STACK_CONFIGS[FLIGHT_STACK_ARDUPILOT]["fcu_url"]},
90+
{"gcs_url": gcs_url},
91+
{"tgt_system": tgt_system},
92+
{"tgt_component": tgt_component},
93+
{"fcu_protocol": fcu_protocol},
94+
FLIGHT_STACK_CONFIGS[FLIGHT_STACK_ARDUPILOT]["pluginlists_yaml"],
95+
FLIGHT_STACK_CONFIGS[FLIGHT_STACK_ARDUPILOT]["config_yaml"],
96+
],
97+
remappings=[],
98+
respawn=respawn_mavros,
99+
output="screen",
60100
)
101+
102+
return LaunchDescription([mavros_px4, mavros_ardupilot, flight_stack_arg])

0 commit comments

Comments
 (0)