@@ -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
132141void 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 ;
0 commit comments