2016-05-27 01:13:02 -03:00
|
|
|
#include "AC_AttitudeControl.h"
|
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include <AP_Math/AP_Math.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
code to monitor and report on the rate controllers, allowing for
|
|
|
|
notification of controller oscillation
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
update a RMS estimate of controller state
|
|
|
|
*/
|
2016-06-09 03:00:57 -03:00
|
|
|
void AC_AttitudeControl::control_monitor_filter_pid(float value, float &rms)
|
2016-05-27 01:13:02 -03:00
|
|
|
{
|
|
|
|
const float filter_constant = 0.99f;
|
|
|
|
// we don't do the sqrt() here as it is quite expensive. That is
|
|
|
|
// done when reporting a result
|
2016-06-09 03:00:57 -03:00
|
|
|
rms = filter_constant * rms + (1.0f - filter_constant) * sq(value);
|
2016-05-27 01:13:02 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
update state in _control_monitor
|
|
|
|
*/
|
|
|
|
void AC_AttitudeControl::control_monitor_update(void)
|
|
|
|
{
|
2019-01-18 00:23:42 -04:00
|
|
|
const AP_Logger::PID_Info &iroll = get_rate_roll_pid().get_pid_info();
|
2016-06-09 03:00:57 -03:00
|
|
|
control_monitor_filter_pid(iroll.P + iroll.FF, _control_monitor.rms_roll_P);
|
|
|
|
control_monitor_filter_pid(iroll.D, _control_monitor.rms_roll_D);
|
|
|
|
|
2019-01-18 00:23:42 -04:00
|
|
|
const AP_Logger::PID_Info &ipitch = get_rate_pitch_pid().get_pid_info();
|
2021-09-08 09:57:47 -03:00
|
|
|
control_monitor_filter_pid(ipitch.P + ipitch.FF, _control_monitor.rms_pitch_P);
|
2016-06-09 03:00:57 -03:00
|
|
|
control_monitor_filter_pid(ipitch.D, _control_monitor.rms_pitch_D);
|
|
|
|
|
2019-01-18 00:23:42 -04:00
|
|
|
const AP_Logger::PID_Info &iyaw = get_rate_yaw_pid().get_pid_info();
|
2016-06-09 03:00:57 -03:00
|
|
|
control_monitor_filter_pid(iyaw.P + iyaw.D + iyaw.FF, _control_monitor.rms_yaw);
|
2016-05-27 01:13:02 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
log a CRTL message
|
|
|
|
*/
|
2021-02-01 12:26:25 -04:00
|
|
|
void AC_AttitudeControl::control_monitor_log(void) const
|
2016-05-27 01:13:02 -03:00
|
|
|
{
|
2020-04-06 23:53:57 -03:00
|
|
|
// @LoggerMessage: CTRL
|
|
|
|
// @Description: Attitude Control oscillation monitor diagnostics
|
|
|
|
// @Field: TimeUS: Time since system startup
|
|
|
|
// @Field: RMSRollP: LPF Root-Mean-Squared Roll Rate controller P gain
|
|
|
|
// @Field: RMSRollD: LPF Root-Mean-Squared Roll rate controller D gain
|
|
|
|
// @Field: RMSPitchP: LPF Root-Mean-Squared Pitch Rate controller P gain
|
|
|
|
// @Field: RMSPitchD: LPF Root-Mean-Squared Pitch Rate controller D gain
|
|
|
|
// @Field: RMSYaw: LPF Root-Mean-Squared Yaw Rate controller P+D gain
|
2021-08-17 06:57:41 -03:00
|
|
|
AP::logger().WriteStreaming("CTRL", "TimeUS,RMSRollP,RMSRollD,RMSPitchP,RMSPitchD,RMSYaw", "Qfffff",
|
2016-05-27 01:13:02 -03:00
|
|
|
AP_HAL::micros64(),
|
2018-11-02 09:37:29 -03:00
|
|
|
(double)safe_sqrt(_control_monitor.rms_roll_P),
|
|
|
|
(double)safe_sqrt(_control_monitor.rms_roll_D),
|
|
|
|
(double)safe_sqrt(_control_monitor.rms_pitch_P),
|
|
|
|
(double)safe_sqrt(_control_monitor.rms_pitch_D),
|
|
|
|
(double)safe_sqrt(_control_monitor.rms_yaw));
|
2016-06-09 03:00:57 -03:00
|
|
|
|
2016-05-27 01:13:02 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-06-01 04:18:58 -03:00
|
|
|
return current controller RMS filter value for roll
|
2016-05-27 01:13:02 -03:00
|
|
|
*/
|
2016-06-01 04:18:58 -03:00
|
|
|
float AC_AttitudeControl::control_monitor_rms_output_roll(void) const
|
2016-05-27 01:13:02 -03:00
|
|
|
{
|
2018-11-02 09:37:29 -03:00
|
|
|
return safe_sqrt(_control_monitor.rms_roll_P + _control_monitor.rms_roll_D);
|
2016-06-01 04:18:58 -03:00
|
|
|
}
|
|
|
|
|
2016-06-09 03:25:19 -03:00
|
|
|
/*
|
|
|
|
return current controller RMS filter value for roll_P
|
|
|
|
*/
|
|
|
|
float AC_AttitudeControl::control_monitor_rms_output_roll_P(void) const
|
|
|
|
{
|
2018-11-02 09:37:29 -03:00
|
|
|
return safe_sqrt(_control_monitor.rms_roll_P);
|
2016-06-09 03:25:19 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
return current controller RMS filter value for roll_D
|
|
|
|
*/
|
|
|
|
float AC_AttitudeControl::control_monitor_rms_output_roll_D(void) const
|
|
|
|
{
|
2018-11-02 09:37:29 -03:00
|
|
|
return safe_sqrt(_control_monitor.rms_roll_D);
|
2016-06-09 03:25:19 -03:00
|
|
|
}
|
|
|
|
|
2016-06-01 04:18:58 -03:00
|
|
|
/*
|
|
|
|
return current controller RMS filter value for pitch
|
|
|
|
*/
|
|
|
|
float AC_AttitudeControl::control_monitor_rms_output_pitch(void) const
|
|
|
|
{
|
2018-11-02 09:37:29 -03:00
|
|
|
return safe_sqrt(_control_monitor.rms_pitch_P + _control_monitor.rms_pitch_D);
|
2016-06-01 04:18:58 -03:00
|
|
|
}
|
|
|
|
|
2016-06-09 03:25:19 -03:00
|
|
|
/*
|
|
|
|
return current controller RMS filter value for pitch_P
|
|
|
|
*/
|
|
|
|
float AC_AttitudeControl::control_monitor_rms_output_pitch_P(void) const
|
|
|
|
{
|
2018-11-02 09:37:29 -03:00
|
|
|
return safe_sqrt(_control_monitor.rms_pitch_P);
|
2016-06-09 03:25:19 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
return current controller RMS filter value for pitch_D
|
|
|
|
*/
|
|
|
|
float AC_AttitudeControl::control_monitor_rms_output_pitch_D(void) const
|
|
|
|
{
|
2018-11-02 09:37:29 -03:00
|
|
|
return safe_sqrt(_control_monitor.rms_pitch_D);
|
2016-06-09 03:25:19 -03:00
|
|
|
}
|
|
|
|
|
2016-06-01 04:18:58 -03:00
|
|
|
/*
|
|
|
|
return current controller RMS filter value for yaw
|
|
|
|
*/
|
|
|
|
float AC_AttitudeControl::control_monitor_rms_output_yaw(void) const
|
|
|
|
{
|
2018-11-02 09:37:29 -03:00
|
|
|
return safe_sqrt(_control_monitor.rms_yaw);
|
2016-05-27 01:13:02 -03:00
|
|
|
}
|