Skip to content

Commit 7fd04fb

Browse files
authored
Merge pull request #24 from aerostack2/swarm_support
[as2_platform_pixhawk] Add fmu prefix and target_system_id parameters
2 parents 3312310 + e351d2d commit 7fd04fb

File tree

6 files changed

+34
-17
lines changed

6 files changed

+34
-17
lines changed

config/platform_config_file.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
info_freq: 10.0 # Hz of platform info publish
55
max_thrust: 15.0 # Max thrust to send to platform (N)
66
min_thrust: 0.15 # Min thrust to send to platform (N)
7-
external_odom: false # Flag to use external odometry source
7+
external_odom: false # Flag to use external odometry source
8+
fmu_prefix: '' # Prefix for FMU topics
9+
target_system_id: 1 # Target system ID for mavros

include/as2_platform_pixhawk/pixhawk_platform.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ class PixhawkPlatform : public as2::AerialPlatform
165165
bool external_odom_ = true;
166166
std::string base_link_frame_id_;
167167
std::string odom_frame_id_;
168+
int target_system_id_ = 1;
168169

169170
Eigen::Quaterniond q_ned_to_enu_;
170171
Eigen::Quaterniond q_enu_to_ned_;

launch/pixhawk_launch.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ def generate_launch_description():
7171
{
7272
'control_modes_file': LaunchConfiguration('control_modes_file'),
7373
},
74-
LaunchConfiguration('platform_config_file'),
7574
LaunchConfigurationFromConfigFile(
7675
'platform_config_file',
7776
default_file=platform_config_file),

src/pixhawk_platform.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,21 @@ PixhawkPlatform::PixhawkPlatform(const rclcpp::NodeOptions & options)
5959
this->declare_parameter<bool>("external_odom");
6060
external_odom_ = this->get_parameter("external_odom").as_bool();
6161

62+
std::string fmu_prefix = "";
63+
this->declare_parameter<std::string>("fmu_prefix");
64+
fmu_prefix = this->get_parameter("fmu_prefix").as_string();
65+
66+
target_system_id_ = 1;
67+
this->declare_parameter<int>("target_system_id");
68+
target_system_id_ = this->get_parameter("target_system_id").as_int();
69+
6270
RCLCPP_INFO(this->get_logger(), "Max thrust: %f", max_thrust_);
6371
RCLCPP_INFO(this->get_logger(), "Min thrust: %f", min_thrust_);
6472
RCLCPP_INFO(
6573
this->get_logger(), "Simulation mode: %s",
6674
this->get_parameter("use_sim_time").as_bool() ? "true" : "false");
6775
RCLCPP_INFO(this->get_logger(), "External odometry mode: %s", external_odom_ ? "true" : "false");
76+
RCLCPP_INFO(this->get_logger(), "FMU prefix: %s", fmu_prefix.c_str());
6877

6978
as2::frame::eulerToQuaternion(M_PI, 0.0, M_PI_2, q_ned_to_enu_);
7079
q_enu_to_ned_ = q_ned_to_enu_;
@@ -73,29 +82,29 @@ PixhawkPlatform::PixhawkPlatform(const rclcpp::NodeOptions & options)
7382

7483
// declare PX4 subscribers
7584
px4_imu_sub_ = this->create_subscription<px4_msgs::msg::SensorCombined>(
76-
"/fmu/out/sensor_combined", rclcpp::SensorDataQoS(),
85+
fmu_prefix + "/fmu/out/sensor_combined", rclcpp::SensorDataQoS(),
7786
std::bind(&PixhawkPlatform::px4imuCallback, this, std::placeholders::_1));
7887

7988
// px4_timesync_sub_ = this->create_subscription<px4_msgs::msg::TimesyncStatus>(
80-
// "/fmu/out/timesync_status", rclcpp::SensorDataQoS(),
89+
// fmu_prefix + "/fmu/out/timesync_status", rclcpp::SensorDataQoS(),
8190
// [this](const px4_msgs::msg::TimesyncStatus::UniquePtr msg) {
8291
// timestamp_.store(msg->timestamp);
8392
// });
8493

8594
px4_vehicle_control_mode_sub_ = this->create_subscription<px4_msgs::msg::VehicleControlMode>(
86-
"/fmu/out/vehicle_control_mode", rclcpp::SensorDataQoS(),
95+
fmu_prefix + "/fmu/out/vehicle_control_mode", rclcpp::SensorDataQoS(),
8796
std::bind(&PixhawkPlatform::px4VehicleControlModeCallback, this, std::placeholders::_1));
8897

8998
px4_gps_sub_ = this->create_subscription<px4_msgs::msg::SensorGps>(
90-
"/fmu/out/vehicle_gps_position", rclcpp::SensorDataQoS(),
99+
fmu_prefix + "/fmu/out/vehicle_gps_position", rclcpp::SensorDataQoS(),
91100
std::bind(&PixhawkPlatform::px4GpsCallback, this, std::placeholders::_1));
92101

93102
px4_battery_sub_ = this->create_subscription<px4_msgs::msg::BatteryStatus>(
94-
"/fmu/out/battery_status", rclcpp::SensorDataQoS(),
103+
fmu_prefix + "/fmu/out/battery_status", rclcpp::SensorDataQoS(),
95104
std::bind(&PixhawkPlatform::px4BatteryCallback, this, std::placeholders::_1));
96105

97106
px4_odometry_sub_ = this->create_subscription<px4_msgs::msg::VehicleOdometry>(
98-
"/fmu/out/vehicle_odometry", rclcpp::SensorDataQoS(),
107+
fmu_prefix + "/fmu/out/vehicle_odometry", rclcpp::SensorDataQoS(),
99108
std::bind(&PixhawkPlatform::px4odometryCallback, this, std::placeholders::_1));
100109
tf_handler_ = std::make_shared<as2::tf::TfHandler>(this);
101110

@@ -112,21 +121,21 @@ PixhawkPlatform::PixhawkPlatform(const rclcpp::NodeOptions & options)
112121

113122
// declare PX4 publishers
114123
px4_offboard_control_mode_pub_ = this->create_publisher<px4_msgs::msg::OffboardControlMode>(
115-
"/fmu/in/offboard_control_mode", rclcpp::SensorDataQoS());
124+
fmu_prefix + "/fmu/in/offboard_control_mode", rclcpp::SensorDataQoS());
116125
px4_trajectory_setpoint_pub_ = this->create_publisher<px4_msgs::msg::TrajectorySetpoint>(
117-
"/fmu/in/trajectory_setpoint", rclcpp::SensorDataQoS());
126+
fmu_prefix + "/fmu/in/trajectory_setpoint", rclcpp::SensorDataQoS());
118127
px4_vehicle_attitude_setpoint_pub_ =
119128
this->create_publisher<px4_msgs::msg::VehicleAttitudeSetpoint>(
120-
"/fmu/in/vehicle_attitude_setpoint", rclcpp::SensorDataQoS());
129+
fmu_prefix + "/fmu/in/vehicle_attitude_setpoint", rclcpp::SensorDataQoS());
121130
px4_vehicle_rates_setpoint_pub_ = this->create_publisher<px4_msgs::msg::VehicleRatesSetpoint>(
122-
"/fmu/in/vehicle_rates_setpoint", rclcpp::SensorDataQoS());
131+
fmu_prefix + "/fmu/in/vehicle_rates_setpoint", rclcpp::SensorDataQoS());
123132
px4_vehicle_command_pub_ = this->create_publisher<px4_msgs::msg::VehicleCommand>(
124-
"/fmu/in/vehicle_command", rclcpp::SensorDataQoS());
133+
fmu_prefix + "/fmu/in/vehicle_command", rclcpp::SensorDataQoS());
125134
px4_visual_odometry_pub_ = this->create_publisher<px4_msgs::msg::VehicleOdometry>(
126-
"/fmu/in/vehicle_visual_odometry", rclcpp::SensorDataQoS());
135+
fmu_prefix + "/fmu/in/vehicle_visual_odometry", rclcpp::SensorDataQoS());
127136

128137
px4_manual_control_switches_pub_ = this->create_publisher<px4_msgs::msg::ManualControlSwitches>(
129-
"fmu/in/manual_control_switches", rclcpp::SensorDataQoS());
138+
fmu_prefix + "/fmu/in/manual_control_switches", rclcpp::SensorDataQoS());
130139
}
131140

132141
void PixhawkPlatform::configureSensors()
@@ -541,7 +550,7 @@ void PixhawkPlatform::PX4publishVehicleCommand(uint16_t command, float param1, f
541550
msg.param1 = param1;
542551
msg.param2 = param2;
543552
msg.command = command;
544-
msg.target_system = 1;
553+
msg.target_system = target_system_id_;
545554
msg.target_component = 1;
546555
msg.source_system = 1;
547556
msg.source_component = 1;

tests/pixhawk_platform_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ std::shared_ptr<PixhawkPlatform> get_node(
6262
"-p",
6363
"namespace:=" + name_space,
6464
"-p",
65+
"use_sim_time:=true",
66+
"-p",
67+
"fmu_prefix:=/drone",
68+
"-p",
69+
"target_system_id:=2",
70+
"-p",
6571
"control_modes_file:=" + control_modes_config_file,
6672
"--params-file",
6773
platform_config_file,

tests/px4_odom_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#include <iostream>
4242
#include <px4_msgs/msg/vehicle_odometry.hpp>
4343
#include "rclcpp/rclcpp.hpp"
44-
#include "tf2_geometry_msgs/tf2_geometry_msgs.h"
44+
#include "tf2_geometry_msgs/tf2_geometry_msgs.hpp"
4545

4646
void convert(tf2::Quaternion q_ned)
4747
{

0 commit comments

Comments
 (0)