1
1
import os
2
2
3
+ from launch .actions import DeclareLaunchArgument
4
+ from launch .substitutions import TextSubstitution
3
5
from ament_index_python .packages import get_package_share_directory
4
6
from launch import LaunchDescription
7
+ from launch .conditions .launch_configuration_equals import LaunchConfigurationEquals
5
8
from launch_ros .actions import Node
6
9
7
10
11
+ FLIGHT_STACK_PX4 = "px4"
12
+ FLIGHT_STACK_ARDUPILOT = "ardupilot"
13
+ FLIGHT_STACK_ARG_NAME = "flight_stack"
14
+
15
+
8
16
def generate_launch_description ():
9
17
# package directories
10
18
pkg_mavros = get_package_share_directory ("mavros" )
11
19
pkg_terrain_navigation_ros = get_package_share_directory ("terrain_navigation_ros" )
12
20
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
+ }
14
39
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
+ )
20
46
21
47
gcs_url = ""
22
48
tgt_system = 1
@@ -25,36 +51,52 @@ def generate_launch_description():
25
51
respawn_mavros = False
26
52
namespace = "mavros"
27
53
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 )]
32
60
)
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" )
36
61
37
- # mavros node
38
- mavros = Node (
62
+ # mavros node for PX4
63
+ mavros_px4 = Node (
64
+ condition = condition_px4 ,
39
65
package = "mavros" ,
40
66
executable = "mavros_node" ,
41
67
namespace = namespace ,
42
68
parameters = [
43
- {"fcu_url" : fcu_url },
69
+ {"fcu_url" : FLIGHT_STACK_CONFIGS [ FLIGHT_STACK_PX4 ][ " fcu_url" ] },
44
70
{"gcs_url" : gcs_url },
45
71
{"tgt_system" : tgt_system },
46
72
{"tgt_component" : tgt_component },
47
73
{"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" ] ,
50
76
],
51
77
remappings = [],
52
78
respawn = respawn_mavros ,
53
79
output = "screen" ,
54
80
)
55
81
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" ,
60
100
)
101
+
102
+ return LaunchDescription ([mavros_px4 , mavros_ardupilot , flight_stack_arg ])
0 commit comments