1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

Track the output gain instead of amplitude so the measured values are

consistent if the settings are changed afterwards.
This commit is contained in:
James Cotton 2012-08-01 01:21:57 -05:00
parent 5c00451c9e
commit 7ea14ecc22
2 changed files with 2 additions and 5 deletions

View File

@ -254,16 +254,13 @@ static void update_stabilization_settings()
const float gain_ratio_p = 1.0f / 5.0f; const float gain_ratio_p = 1.0f / 5.0f;
const float zero_ratio_p = 1.0f / 5.0f; const float zero_ratio_p = 1.0f / 5.0f;
float input = relaySettings.Amplitude * 4.0f / M_PI; // amplitude of input (fundamental component of fourier series for the square wave)
// For now just run over roll and pitch // For now just run over roll and pitch
for (uint i = 0; i < 2; i++) { for (uint i = 0; i < 2; i++) {
float output = relayTuning.Amplitude[i]; // amplitude of sinusoidal oscillation in output
float wu = 1000.0f * 2 * M_PI / relayTuning.Period[i]; // ultimate freq = output osc freq (rad/s) float wu = 1000.0f * 2 * M_PI / relayTuning.Period[i]; // ultimate freq = output osc freq (rad/s)
float wc = wu * gain_ratio_r; // target openloop crossover frequency (rad/s) float wc = wu * gain_ratio_r; // target openloop crossover frequency (rad/s)
float zc = wc * zero_ratio_r; // controller zero location (rad/s) float zc = wc * zero_ratio_r; // controller zero location (rad/s)
float kpu = input / output; // ultimate gain, i.e. the proportional gain for instablity float kpu = 4.0f / M_PI / relayTuning.Gain[i]; // ultimate gain, i.e. the proportional gain for instablity
float kp = kpu * gain_ratio_r; // proportional gain float kp = kpu * gain_ratio_r; // proportional gain
float ki = zc * kp; // integral gain float ki = zc * kp; // integral gain

View File

@ -2,7 +2,7 @@
<object name="RelayTuning" singleinstance="true" settings="false"> <object name="RelayTuning" singleinstance="true" settings="false">
<description>The input to the relay tuning.</description> <description>The input to the relay tuning.</description>
<field name="Period" units="ms" type="float" elementnames="Roll,Pitch,Yaw"/> <field name="Period" units="ms" type="float" elementnames="Roll,Pitch,Yaw"/>
<field name="Amplitude" units="deg/s" type="float" elementnames="Roll,Pitch,Yaw"/> <field name="Gain" units="(deg/s)/output" type="float" elementnames="Roll,Pitch,Yaw"/>
<access gcs="readwrite" flight="readwrite"/> <access gcs="readwrite" flight="readwrite"/>
<telemetrygcs acked="false" updatemode="manual" period="0"/> <telemetrygcs acked="false" updatemode="manual" period="0"/>
<telemetryflight acked="false" updatemode="periodic" period="1000"/> <telemetryflight acked="false" updatemode="periodic" period="1000"/>