chore: use setpoint_config in mc_raptor and mc_nn_control

This commit is contained in:
Beat Küng authored and Ramon Roche committed 2026-07-03 12:33:03 -07:00
1 parent 9fb0f1e43a
commit f33b5769fc
4 files changed
+27 -37

No files matched your search

+11 -12
View File
@@ -181,17 +181,12 @@ void MulticopterNeuralNetworkControl::UnregisterNeuralFlightMode(int8 arming_che
void MulticopterNeuralNetworkControl::ConfigureNeuralFlightMode(int8 mode_id)
{
// Configure the neural flight mode with the commander
vehicle_control_mode_s config_control_setpoints{};
config_control_setpoints.timestamp = hrt_absolute_time();
config_control_setpoints.source_id = mode_id;
config_control_setpoints.flag_multicopter_position_control_enabled = false;
config_control_setpoints.flag_control_manual_enabled = _param_manual_control.get();
config_control_setpoints.flag_control_offboard_enabled = false;
config_control_setpoints.flag_control_position_enabled = false;
config_control_setpoints.flag_control_climb_rate_enabled = true;
config_control_setpoints.flag_control_allocation_enabled = false;
config_control_setpoints.flag_control_termination_enabled = true;
_config_control_setpoints_pub.publish(config_control_setpoints);
setpoint_config_s setpoint_config{};
setpoint_config.timestamp = hrt_absolute_time();
setpoint_config.source_id = mode_id;
setpoint_config.type = setpoint_config_s::TYPE_DIRECT_ACTUATORS;
setpoint_config.should_apply = true;
_setpoint_config_pub.publish(setpoint_config);
}
@@ -228,7 +223,6 @@ void MulticopterNeuralNetworkControl::CheckModeRegistration()
_arming_check_id = register_ext_component_reply.arming_check_id;
_mode_id = register_ext_component_reply.mode_id;
PX4_INFO("NeuralControl mode registration successful, arming_check_id: %d, mode_id: %d", _arming_check_id, _mode_id);
ConfigureNeuralFlightMode(_mode_id);
break;
}
}
@@ -496,7 +490,12 @@ void MulticopterNeuralNetworkControl::Run()
if (_vehicle_status_sub.updated()) {
_vehicle_status_sub.copy(&vehicle_status);
const bool prev_use_neural = _use_neural;
_use_neural = vehicle_status.nav_state == _mode_id;
if (!prev_use_neural && _use_neural) {
ConfigureNeuralFlightMode(_mode_id);
}
}
if (_parameter_update_sub.updated()) {
+2 -2
View File
@@ -76,7 +76,7 @@
#include <uORB/topics/neural_control.h>
#include <uORB/topics/register_ext_component_request.h>
#include <uORB/topics/unregister_ext_component.h>
#include <uORB/topics/vehicle_control_mode.h>
#include <uORB/topics/setpoint_config.h>
#include <uORB/topics/arming_check_reply.h>
using namespace time_literals; // For the 1_s in the subscription interval
@@ -138,7 +138,7 @@ private:
uORB::Publication<neural_control_s> _neural_control_pub{ORB_ID(neural_control)};
uORB::Publication<register_ext_component_request_s> _register_ext_component_request_pub{ORB_ID(register_ext_component_request)};
uORB::Publication<unregister_ext_component_s> _unregister_ext_component_pub{ORB_ID(unregister_ext_component)};
uORB::Publication<vehicle_control_mode_s> _config_control_setpoints_pub{ORB_ID(config_control_setpoints)};
uORB::Publication<setpoint_config_s> _setpoint_config_pub{ORB_ID(setpoint_config)};
uORB::Publication<arming_check_reply_s> _arming_check_reply_pub{ORB_ID(arming_check_reply)};
// Variables
+11 -19
View File
@@ -446,7 +446,7 @@ void Raptor::Run()
if (should_exit()) {
_vehicle_angular_velocity_sub.unregisterCallback();
if (flightmode_state >= FlightModeState::REGISTERED) {
if (flightmode_state >= FlightModeState::CONFIGURED) {
unregister_ext_component_s unregister_ext_component{};
unregister_ext_component.timestamp = hrt_absolute_time();
strncpy(unregister_ext_component.name, "RAPTOR", sizeof(unregister_ext_component.name) - 1);
@@ -467,28 +467,11 @@ void Raptor::Run()
if (register_ext_component_reply.request_id == Raptor::EXT_COMPONENT_REQUEST_ID && register_ext_component_reply.success) {
ext_component_arming_check_id = register_ext_component_reply.arming_check_id;
ext_component_mode_id = register_ext_component_reply.mode_id;
flightmode_state = FlightModeState::REGISTERED;
flightmode_state = FlightModeState::CONFIGURED;
PX4_INFO("Raptor mode registration successful, arming_check_id: %d, mode_id: %d", ext_component_arming_check_id, ext_component_mode_id);
}
}
if (flightmode_state == FlightModeState::REGISTERED) {
vehicle_control_mode_s config_control_setpoints{};
config_control_setpoints.timestamp = hrt_absolute_time();
config_control_setpoints.source_id = ext_component_mode_id;
config_control_setpoints.flag_multicopter_position_control_enabled = false;
config_control_setpoints.flag_control_manual_enabled = false;
config_control_setpoints.flag_control_offboard_enabled = false;
config_control_setpoints.flag_control_position_enabled = false;
config_control_setpoints.flag_control_climb_rate_enabled = false;
config_control_setpoints.flag_control_allocation_enabled = false;
config_control_setpoints.flag_control_termination_enabled = true;
_config_control_setpoints_pub.publish(config_control_setpoints);
flightmode_state = FlightModeState::CONFIGURED;
PX4_INFO("Raptor mode configuration sent");
}
perf_count(_loop_interval_perf);
perf_begin(_loop_perf);
@@ -538,6 +521,15 @@ void Raptor::Run()
bool next_active = timestamp_last_vehicle_status_set && _vehicle_status.nav_state == ext_component_mode_id;
if (!previous_active && next_active) {
// Activate setpoint type
setpoint_config_s setpoint_config{};
setpoint_config.timestamp = hrt_absolute_time();
setpoint_config.source_id = ext_component_mode_id;
setpoint_config.type = setpoint_config_s::TYPE_DIRECT_ACTUATORS;
setpoint_config.should_apply = true;
_setpoint_config_pub.publish(setpoint_config);
this->reset();
PX4_INFO("Resetting Inference Executor (Recurrent State)");
+3 -4
View File
@@ -27,7 +27,7 @@
#include <uORB/topics/raptor_status.h>
#include <uORB/topics/raptor_input.h>
#include <uORB/topics/tune_control.h>
#include <uORB/topics/vehicle_control_mode.h>
#include <uORB/topics/setpoint_config.h>
#include <uORB/topics/arming_check_request.h>
#include <uORB/topics/arming_check_reply.h>
#undef OK
@@ -122,8 +122,7 @@ private:
enum class FlightModeState : TI {
UNREGISTERED = 0,
REGISTERED = 1,
CONFIGURED = 2
CONFIGURED = 1
};
FlightModeState flightmode_state = FlightModeState::UNREGISTERED;
bool can_arm = false;
@@ -159,7 +158,7 @@ private:
uORB::Publication<tune_control_s> _tune_control_pub{ORB_ID(tune_control)};
uORB::Publication<register_ext_component_request_s> _register_ext_component_request_pub{ORB_ID(register_ext_component_request)};
uORB::Publication<unregister_ext_component_s> _unregister_ext_component_pub{ORB_ID(unregister_ext_component)};
uORB::Publication<vehicle_control_mode_s> _config_control_setpoints_pub{ORB_ID(config_control_setpoints)};
uORB::Publication<setpoint_config_s> _setpoint_config_pub{ORB_ID(setpoint_config)};
uORB::Publication<arming_check_reply_s> _arming_check_reply_pub{ORB_ID(arming_check_reply)};
// Performance (perf) counters
perf_counter_t _loop_perf{perf_alloc(PC_ELAPSED, MODULE_NAME": cycle")};