diff --git a/src/modules/control_allocator/ControlAllocator.cpp b/src/modules/control_allocator/ControlAllocator.cpp index a90a0da4d7..dbff6c1179 100644 --- a/src/modules/control_allocator/ControlAllocator.cpp +++ b/src/modules/control_allocator/ControlAllocator.cpp @@ -54,7 +54,9 @@ ControlAllocator::ControlAllocator() : ScheduledWorkItem(MODULE_NAME, px4::wq_configurations::rate_ctrl), _loop_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": cycle")) { - _control_allocator_status_pub.advertise(); + _control_allocator_status_pub[0].advertise(); + _control_allocator_status_pub[1].advertise(); + _actuator_motors_pub.advertise(); _actuator_servos_pub.advertise(); _actuator_servos_trim_pub.advertise(); @@ -430,7 +432,12 @@ ControlAllocator::Run() // Publish status at limited rate, as it's somewhat expensive and we use it for slower dynamics // (i.e. anti-integrator windup) if (now - _last_status_pub >= 5_ms) { - publish_control_allocator_status(); + publish_control_allocator_status(0); + + if (_num_control_allocation > 1) { + publish_control_allocator_status(1); + } + _last_status_pub = now; } @@ -571,15 +578,15 @@ ControlAllocator::update_effectiveness_matrix_if_needed(EffectivenessUpdateReaso } void -ControlAllocator::publish_control_allocator_status() +ControlAllocator::publish_control_allocator_status(int matrix_index) { control_allocator_status_s control_allocator_status{}; control_allocator_status.timestamp = hrt_absolute_time(); - // TODO: handle multiple matrices & disabled motors (?) + // TODO: disabled motors (?) // Allocated control - const matrix::Vector &allocated_control = _control_allocation[0]->getAllocatedControl(); + const matrix::Vector &allocated_control = _control_allocation[matrix_index]->getAllocatedControl(); control_allocator_status.allocated_torque[0] = allocated_control(0); control_allocator_status.allocated_torque[1] = allocated_control(1); control_allocator_status.allocated_torque[2] = allocated_control(2); @@ -588,7 +595,7 @@ ControlAllocator::publish_control_allocator_status() control_allocator_status.allocated_thrust[2] = allocated_control(5); // Unallocated control - const matrix::Vector unallocated_control = _control_allocation[0]->getControlSetpoint() - + const matrix::Vector unallocated_control = _control_allocation[matrix_index]->getControlSetpoint() - allocated_control; control_allocator_status.unallocated_torque[0] = unallocated_control(0); control_allocator_status.unallocated_torque[1] = unallocated_control(1); @@ -604,9 +611,9 @@ ControlAllocator::publish_control_allocator_status() unallocated_control(5)).norm_squared() < 1e-6f); // Actuator saturation - const matrix::Vector &actuator_sp = _control_allocation[0]->getActuatorSetpoint(); - const matrix::Vector &actuator_min = _control_allocation[0]->getActuatorMin(); - const matrix::Vector &actuator_max = _control_allocation[0]->getActuatorMax(); + const matrix::Vector &actuator_sp = _control_allocation[matrix_index]->getActuatorSetpoint(); + const matrix::Vector &actuator_min = _control_allocation[matrix_index]->getActuatorMin(); + const matrix::Vector &actuator_max = _control_allocation[matrix_index]->getActuatorMax(); for (int i = 0; i < NUM_ACTUATORS; i++) { if (actuator_sp(i) > (actuator_max(i) - FLT_EPSILON)) { @@ -620,7 +627,7 @@ ControlAllocator::publish_control_allocator_status() // Handled motor failures control_allocator_status.handled_motor_failure_mask = _handled_motor_failure_bitmask; - _control_allocator_status_pub.publish(control_allocator_status); + _control_allocator_status_pub[matrix_index].publish(control_allocator_status); } void diff --git a/src/modules/control_allocator/ControlAllocator.hpp b/src/modules/control_allocator/ControlAllocator.hpp index 1b016dd331..0281aa925e 100644 --- a/src/modules/control_allocator/ControlAllocator.hpp +++ b/src/modules/control_allocator/ControlAllocator.hpp @@ -64,6 +64,7 @@ #include #include #include +#include #include #include #include @@ -131,7 +132,7 @@ private: void check_for_motor_failures(); - void publish_control_allocator_status(); + void publish_control_allocator_status(int matrix_index); void publish_actuator_controls(); @@ -174,7 +175,7 @@ private: uORB::Subscription _vehicle_thrust_setpoint1_sub{ORB_ID(vehicle_thrust_setpoint), 1}; /**< vehicle thrust setpoint subscription (2. instance) */ // Outputs - uORB::Publication _control_allocator_status_pub{ORB_ID(control_allocator_status)}; /**< actuator setpoint publication */ + uORB::PublicationMulti _control_allocator_status_pub[2] {ORB_ID(control_allocator_status), ORB_ID(control_allocator_status)}; uORB::Publication _actuator_motors_pub{ORB_ID(actuator_motors)}; uORB::Publication _actuator_servos_pub{ORB_ID(actuator_servos)};