Skip to content

Commit fbffff2

Browse files
committed
Only keep integrator error when flying;
Updating gains from xcos simulation;
1 parent 35d3ec4 commit fbffff2

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
-6.23 KB
Binary file not shown.

src/QuadCopterCode/controller.cpp

+16-7
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,17 @@ void CalculateControlVector(float *euler_angles, float *g, float *motor_control_
8787
// ----------- PD/PID state gains -----------
8888
// const float kD = 0.04769*2*radioRecieverVals[INDEX_LEFT_KNOB]/100.0; // Derivitive feedback term
8989
// const float kP = 0.6212*2*radioRecieverVals[INDEX_LEFT_KNOB]/100.0;// Propoortional feedback term
90-
const float kP = 0.07; //*radioRecieverVals[INDEX_LEFT_KNOB]/100.0;// Propoortional feedback term
91-
const float kI = 0.55; // Integral feedback term
92-
const float kD = 0.055; // *radioRecieverVals[INDEX_LEFT_KNOB]/100.0; // Derivitive feedback term
90+
// const float kP = 0.07; //*radioRecieverVals[INDEX_LEFT_KNOB]/100.0;// Propoortional feedback term
91+
// const float kI = 0.55; // Integral feedback term
92+
// const float kD = 0.055; // *radioRecieverVals[INDEX_LEFT_KNOB]/100.0; // Derivitive feedback term
93+
94+
// From Xcos simulation
95+
const float kP = 0.05;
96+
const float kI = 0.015;
97+
const float kD = 0.02;
9398

9499
// Reference adjustment
95-
const float Nbar = kP; //0.1118;
100+
// const float Nbar = kP; //0.1118;
96101
// ---------------------------------------
97102

98103
float pitch_angle_deg = 0.0;
@@ -152,8 +157,13 @@ void CalculateControlVector(float *euler_angles, float *g, float *motor_control_
152157
// scale_val = min(1.0, (input_left_throttle / 100.0) * (input_left_throttle / 100.0));
153158
pitch_err_rad = (-input_radio_values[INDEX_RIGHT_STICK_UPDOWN] - pitch_angle_deg) * DEG2RAD;
154159
roll_err_rad = (input_radio_values[INDEX_RIGHT_STICK_LEFTRIGHT] - roll_angle_deg) * DEG2RAD;
155-
integrated_pitch_err_rad = constrain(integrated_pitch_err_rad * 0.999 + (pitch_err_rad * delta_time), -0.25, 0.25);
156-
integrated_roll_err_rad = constrain(integrated_roll_err_rad * 0.999 + (roll_err_rad * delta_time), -0.25, 0.25);
160+
161+
// Only accrue integrator error once we're flying (so it doesn't ratchet up on the ground)
162+
if (input_left_throttle > 50)
163+
{
164+
integrated_pitch_err_rad = constrain(integrated_pitch_err_rad * 0.999 + (pitch_err_rad * delta_time), -0.25, 0.25);
165+
integrated_roll_err_rad = constrain(integrated_roll_err_rad * 0.999 + (roll_err_rad * delta_time), -0.25, 0.25);
166+
}
157167
moment_pitch = (pitch_err_rad * kP) + ((0.0f - pitch_rate_deg) * DEG2RAD * kD) + (integrated_pitch_err_rad * kI);
158168
moment_roll = (roll_err_rad * kP) + ((0.0f - roll_rate_deg) * DEG2RAD) * kD + (integrated_roll_err_rad * kI);
159169

@@ -176,7 +186,6 @@ void CalculateControlVector(float *euler_angles, float *g, float *motor_control_
176186
motor_control_vector[1] = 0.0;
177187
motor_control_vector[2] = 0.0;
178188
motor_control_vector[3] = 0.0;
179-
180189
}
181190
}
182191

0 commit comments

Comments
 (0)