@@ -87,12 +87,17 @@ void CalculateControlVector(float *euler_angles, float *g, float *motor_control_
87
87
// ----------- PD/PID state gains -----------
88
88
// const float kD = 0.04769*2*radioRecieverVals[INDEX_LEFT_KNOB]/100.0; // Derivitive feedback term
89
89
// 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 ;
93
98
94
99
// Reference adjustment
95
- const float Nbar = kP ; // 0.1118;
100
+ // const float Nbar = kP; //0.1118;
96
101
// ---------------------------------------
97
102
98
103
float pitch_angle_deg = 0.0 ;
@@ -152,8 +157,13 @@ void CalculateControlVector(float *euler_angles, float *g, float *motor_control_
152
157
// scale_val = min(1.0, (input_left_throttle / 100.0) * (input_left_throttle / 100.0));
153
158
pitch_err_rad = (-input_radio_values[INDEX_RIGHT_STICK_UPDOWN] - pitch_angle_deg) * DEG2RAD;
154
159
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
+ }
157
167
moment_pitch = (pitch_err_rad * kP ) + ((0 .0f - pitch_rate_deg) * DEG2RAD * kD ) + (integrated_pitch_err_rad * kI );
158
168
moment_roll = (roll_err_rad * kP ) + ((0 .0f - roll_rate_deg) * DEG2RAD) * kD + (integrated_roll_err_rad * kI );
159
169
@@ -176,7 +186,6 @@ void CalculateControlVector(float *euler_angles, float *g, float *motor_control_
176
186
motor_control_vector[1 ] = 0.0 ;
177
187
motor_control_vector[2 ] = 0.0 ;
178
188
motor_control_vector[3 ] = 0.0 ;
179
-
180
189
}
181
190
}
182
191
0 commit comments