Skip to content
Snippets Groups Projects
Commit bec43b0b authored by Beat Küng's avatar Beat Küng Committed by Daniel Agar
Browse files

mc_att_control: run rate controller first and increase fmu prio by one

The rate controller is now run directly after a gyro publication, and
as soon as it publishes the actuator controls, the output driver (fmu/...)
runs.

Test on a Pixracer:
Reduces fmu control latency from 219us to 134us.
If we run the rate controller last (same order as before, just increase
the prio), the latency is 201us.

CPU load is unchanged.

The drawback is that the attitude to rate setpoint generation is delayed
by one cycle (4ms), but it will be reduced to 1ms as soon as we run at
1kHz.
parent 95cc6a06
No related branches found
No related tags found
No related merge requests found
...@@ -720,6 +720,14 @@ MulticopterAttitudeControl::run() ...@@ -720,6 +720,14 @@ MulticopterAttitudeControl::run()
/* copy gyro data */ /* copy gyro data */
orb_copy(ORB_ID(sensor_gyro), _sensor_gyro_sub[_selected_gyro], &_sensor_gyro); orb_copy(ORB_ID(sensor_gyro), _sensor_gyro_sub[_selected_gyro], &_sensor_gyro);
/* run the rate controller immediately after a gyro update */
if (_v_control_mode.flag_control_rates_enabled) {
control_attitude_rates(dt);
publish_actuator_controls();
publish_rate_controller_status();
}
/* check for updates in other topics */ /* check for updates in other topics */
vehicle_control_mode_poll(); vehicle_control_mode_poll();
vehicle_status_poll(); vehicle_status_poll();
...@@ -772,13 +780,6 @@ MulticopterAttitudeControl::run() ...@@ -772,13 +780,6 @@ MulticopterAttitudeControl::run()
} }
} }
if (_v_control_mode.flag_control_rates_enabled) {
control_attitude_rates(dt);
publish_actuator_controls();
publish_rate_controller_status();
}
if (_v_control_mode.flag_control_termination_enabled) { if (_v_control_mode.flag_control_termination_enabled) {
if (!_vehicle_status.is_vtol) { if (!_vehicle_status.is_vtol) {
_rates_sp.zero(); _rates_sp.zero();
......
...@@ -114,9 +114,9 @@ typedef struct { ...@@ -114,9 +114,9 @@ typedef struct {
// which typically runs at a slower rate // which typically runs at a slower rate
#define SCHED_PRIORITY_ATTITUDE_CONTROL (SCHED_PRIORITY_MAX - 4) #define SCHED_PRIORITY_ATTITUDE_CONTROL (SCHED_PRIORITY_MAX - 4)
// Actuator outputs should run before right after the attitude controller // Actuator outputs should run as soon as the rate controller publishes
// updated // the actuator controls topic
#define SCHED_PRIORITY_ACTUATOR_OUTPUTS (SCHED_PRIORITY_MAX - 4) #define SCHED_PRIORITY_ACTUATOR_OUTPUTS (SCHED_PRIORITY_MAX - 3)
// Position controllers typically are in a blocking wait on estimator data // Position controllers typically are in a blocking wait on estimator data
// so when new sensor data is available they will run last. Keeping them // so when new sensor data is available they will run last. Keeping them
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment