Skip to content

Commit 8656d36

Browse files
committed
Update main_plane.cpp
1 parent 48ac5bd commit 8656d36

1 file changed

Lines changed: 26 additions & 26 deletions

File tree

examples/20.Plane/main_plane.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -270,17 +270,17 @@ In FBWA mode the rudder is under manual control.
270270
integral_roll += error_roll * imu.dt;
271271
integral_roll = constrain(integral_roll, -i_limit, i_limit); //Saturate integrator to prevent unsafe buildup
272272
float derivative_roll = ahr.gx;
273-
pid.roll = Kp_roll*error_roll + Ki_roll*integral_roll - Kd_roll*derivative_roll; //nominal output -1 to 1 (can be larger)
273+
pid.roll.sum = Kp_roll*error_roll + Ki_roll*integral_roll - Kd_roll*derivative_roll; //nominal output -1 to 1 (can be larger)
274274

275275
//Pitch PID - stabilize desired pitch angle
276276
float error_pitch = pitch_des - ahr.pitch;
277277
integral_pitch += error_pitch * imu.dt;
278278
integral_pitch = constrain(integral_pitch, -i_limit, i_limit); //Saturate integrator to prevent unsafe buildup
279279
float derivative_pitch = ahr.gy;
280-
pid.pitch = Kp_pitch*error_pitch + Ki_pitch*integral_pitch - Kd_pitch*derivative_pitch; //nominal output -1 to 1 (can be larger)
280+
pid.pitch.sum = Kp_pitch*error_pitch + Ki_pitch*integral_pitch - Kd_pitch*derivative_pitch; //nominal output -1 to 1 (can be larger)
281281

282282
//Yaw PID - passthru rcin
283-
pid.yaw = rcl.yaw;
283+
pid.yaw.sum = rcl.yaw;
284284
(void) integral_yaw;
285285
(void) error_yaw_prev;
286286

@@ -290,7 +290,7 @@ In FBWA mode the rudder is under manual control.
290290
integral_yaw += error_yaw * imu.dt;
291291
integral_yaw = constrain(integral_yaw, -i_limit, i_limit); //Saturate integrator to prevent unsafe buildup
292292
float derivative_yaw = (error_yaw - error_yaw_prev) / imu.dt;
293-
pid.yaw = constrain(0.01 * (Kp_yaw*error_yaw + Ki_yaw*integral_yaw + Kd_yaw*derivative_yaw), -1.0f, 1.0f); //Scaled by .01 to bring within -1 to 1 range
293+
pid.yaw.sum = constrain(0.01 * (Kp_yaw*error_yaw + Ki_yaw*integral_yaw + Kd_yaw*derivative_yaw), -1.0f, 1.0f); //Scaled by .01 to bring within -1 to 1 range
294294
295295
//Update derivative variables
296296
error_yaw_prev = error_yaw;
@@ -317,13 +317,13 @@ void control_ROLL(bool zero_integrators) {
317317
integral_roll += error_roll * imu.dt;
318318
integral_roll = constrain(integral_roll, -i_limit, i_limit); //Saturate integrator to prevent unsafe buildup
319319
float derivative_roll = ahr.gx;
320-
pid.roll = Kp_roll*error_roll + Ki_roll*integral_roll - Kd_roll*derivative_roll; //nominal output -1 to 1 (can be larger)
320+
pid.roll.sum = Kp_roll*error_roll + Ki_roll*integral_roll - Kd_roll*derivative_roll; //nominal output -1 to 1 (can be larger)
321321

322322
//Pitch PID - passthru rcin
323-
pid.pitch = rcl.pitch;
323+
pid.pitch.sum = rcl.pitch;
324324

325325
//Yaw PID - passthru rcin
326-
pid.yaw = rcl.yaw;
326+
pid.yaw.sum = rcl.yaw;
327327
}
328328

329329

@@ -332,9 +332,9 @@ void control_MANUAL() {
332332
Regular RC control, no stabilization. All RC inputs are passed through to the servo outputs.
333333
*/
334334
//pass rcin through to PID - PID values are -1 to +1, rcin values are -1 to +1
335-
pid.roll = rcl.roll; //-1 = left, 1 = right
336-
pid.pitch = rcl.pitch; //-1 = pitch up/stick back, 1 = pitch down/stick forward
337-
pid.yaw = rcl.yaw; //-1 = left, 1 = right
335+
pid.roll.sum = rcl.roll; //-1 = left, 1 = right
336+
pid.pitch.sum = rcl.pitch; //-1 = pitch up/stick back, 1 = pitch down/stick forward
337+
pid.yaw.sum = rcl.yaw; //-1 = left, 1 = right
338338
}
339339

340340
void out_KillSwitchAndFailsafe() {
@@ -396,32 +396,32 @@ void out_Mixer() {
396396

397397
//aileron: when pid.roll positive -> roll right -> deflect left aileron down, deflect right aileron up
398398
#ifdef OUT_LEFT_AILERON_DOWN //left aileron deflects down on high pwm
399-
out.set_output(OUT_LEFT_AILERON_DOWN-1, 0.5 +pid.roll/2.0);
399+
out.set_output(OUT_LEFT_AILERON_DOWN-1, 0.5 +pid.roll.sum/2.0);
400400
#endif
401401
#ifdef OUT_RIGHT_AILERON_UP //right aileron deflects up on high pwm
402-
out.set_output(OUT_RIGHT_AILERON_UP-1, 0.5 +pid.roll/2.0);
402+
out.set_output(OUT_RIGHT_AILERON_UP-1, 0.5 +pid.roll.sum/2.0);
403403
#endif
404404
#ifdef OUT_LEFT_AILERON_UP //reversed: left aileron deflects up on high pwm
405-
out.set_output(OUT_LEFT_AILERON_UP-1, 0.5 -pid.roll/2.0);
405+
out.set_output(OUT_LEFT_AILERON_UP-1, 0.5 -pid.roll.sum/2.0);
406406
#endif
407407
#ifdef OUT_RIGHT_AILERON_DOWN //reversed: right aileron deflects down on high pwm
408-
out.set_output(OUT_RIGHT_AILERON_DOWN-1, 0.5 -pid.roll/2.0);
408+
out.set_output(OUT_RIGHT_AILERON_DOWN-1, 0.5 -pid.roll.sum/2.0);
409409
#endif
410410

411411
//elevator: when pid.pitch is positive -> pitch up -> deflect elevator down
412412
#ifdef OUT_ELEVATOR_DOWN //elevator deflects down on high pwm
413-
out.set_output(OUT_ELEVATOR_UP-1, +pid.pitch/2.0 + 0.5);
413+
out.set_output(OUT_ELEVATOR_UP-1, +pid.pitch.sum/2.0 + 0.5);
414414
#endif
415415
#ifdef OUT_ELEVATOR_UP //reversed: elevator deflects up on high pwm
416-
out.set_output(OUT_ELEVATOR_UP-1, -pid.pitch/2.0 + 0.5);
416+
out.set_output(OUT_ELEVATOR_UP-1, -pid.pitch.sum/2.0 + 0.5);
417417
#endif
418418

419419
//rudder: when pid.yaw is positive -> yaw right -> deflect rudder right
420420
#ifdef OUT_RUDDER_RIGHT //rudder deflects right on high pwm
421-
out.set_output(OUT_RUDDER_RIGHT-1, +pid.yaw/2.0 + 0.5);
421+
out.set_output(OUT_RUDDER_RIGHT-1, +pid.yaw.sum/2.0 + 0.5);
422422
#endif
423423
#ifdef OUT_RUDDER_LEFT //reversed: rudder deflects left on high pwm
424-
out.set_output(OUT_RUDDER_LEFT-1, -pid.yaw/2.0 + 0.5);
424+
out.set_output(OUT_RUDDER_LEFT-1, -pid.yaw.sum/2.0 + 0.5);
425425
#endif
426426

427427
//flaps: (rcin_flaps 0.0:up, 1.0:full down)
@@ -446,32 +446,32 @@ void out_Mixer() {
446446
// when pid.yaw positive -> yaw right -> deflect left ruddervator down, deflect right ruddervator up
447447
// when pid.pitch is positive -> pitch up -> deflect left ruddervator down, deflect right ruddervator down
448448
#ifdef OUT_LEFT_RUDDERVATOR_DOWN //left ruddervator deflects down on high input
449-
out.set_output(OUT_LEFT_RUDDERVATOR_DOWN-1, 0.5 +pid.yaw/2.0 +pid.pitch/2.0);
449+
out.set_output(OUT_LEFT_RUDDERVATOR_DOWN-1, 0.5 +pid.yaw.sum/2.0 +pid.pitch.sum/2.0);
450450
#endif
451451
#ifdef OUT_RIGHT_RUDDERVATOR_UP //right ruddervator deflects up on high input
452-
out.set_output(OUT_RIGHT_RUDDERVATOR_UP-1, 0.5 +pid.yaw/2.0 -pid.pitch/2.0);
452+
out.set_output(OUT_RIGHT_RUDDERVATOR_UP-1, 0.5 +pid.yaw.sum/2.0 -pid.pitch.sum/2.0);
453453
#endif
454454
#ifdef OUT_LEFT_RUDDERVATOR_UP //reversed: left ruddervator deflects down on high input
455-
out.set_output(OUT_LEFT_RUDDERVATOR_UP-1, 0.5 -pid.yaw/2.0 -pid.pitch/2.0);
455+
out.set_output(OUT_LEFT_RUDDERVATOR_UP-1, 0.5 -pid.yaw.sum/2.0 -pid.pitch.sum/2.0);
456456
#endif
457457
#ifdef OUT_RIGHT_RUDDERVATOR_DOWN //reversed: right ruddervator deflects down on high input
458-
out.set_output(OUT_RIGHT_RUDDERVATOR_DOWN-1, 0.5 -pid.yaw/2.0 +pid.pitch/2.0);
458+
out.set_output(OUT_RIGHT_RUDDERVATOR_DOWN-1, 0.5 -pid.yaw.sum/2.0 +pid.pitch.sum/2.0);
459459
#endif
460460

461461
//delta wing:
462462
// when pid.roll positive -> roll right -> deflect left elevon down, deflect right elevon up
463463
// when pid.pitch is positive -> pitch up -> deflect left elevon down, deflect right elevon down
464464
#ifdef OUT_LEFT_ELEVON_DOWN //left elevon deflects down on high input
465-
out.set_output(OUT_LEFT_ELEVON_DOWN-1, 0.5 +pid.roll/2.0 +pid.pitch/2.0);
465+
out.set_output(OUT_LEFT_ELEVON_DOWN-1, 0.5 +pid.roll.sum/2.0 +pid.pitch.sum/2.0);
466466
#endif
467467
#ifdef OUT_RIGHT_ELEVON_UP //right elevon deflects up on high input
468-
out.set_output(OUT_RIGHT_ELEVON_UP-1, 0.5 +pid.roll/2.0 -pid.pitch/2.0);
468+
out.set_output(OUT_RIGHT_ELEVON_UP-1, 0.5 +pid.roll.sum/2.0 -pid.pitch.sum/2.0);
469469
#endif
470470
#ifdef OUT_LEFT_ELEVON_UP //reversed: left elevon deflects down on high input
471-
out.set_output(OUT_LEFT_ELEVON_UP-1, 0.5 -pid.roll/2.0 -pid.pitch/2.0);
471+
out.set_output(OUT_LEFT_ELEVON_UP-1, 0.5 -pid.roll.sum/2.0 -pid.pitch.sum/2.0);
472472
#endif
473473
#ifdef OUT_RIGHT_ELEVON_DOWN //reversed: right elevon deflects down on high input
474-
out.set_output(OUT_RIGHT_ELEVON_DOWN-1, 0.5 -pid.roll/2.0 +pid.pitch/2.0);
474+
out.set_output(OUT_RIGHT_ELEVON_DOWN-1, 0.5 -pid.roll.sum/2.0 +pid.pitch.sum/2.0);
475475
#endif
476476

477477
//0.0 is zero throttle if connecting to ESC for conventional PWM, 1.0 is max throttle

0 commit comments

Comments
 (0)