Skip to content

Commit 3bff9bc

Browse files
committed
no PID when idle
1 parent 7763d18 commit 3bff9bc

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

examples/01.Quadcopter/01.Quadcopter.ino

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,20 @@ Yaw right (CCW+ CW-) -++-
339339
*/
340340

341341
// IMPORTANT: This is a safety feature to remind the pilot to disarm.
342-
// Set throttle to at least armed_min_throttle, to keep at least one prop spinning when armed. The [out] module will disable motors when out.armed == false
343-
float thr = armed_min_throttle + (1 - armed_min_throttle) * rcl.throttle; //shift throttle range from [0.0 .. 1.0] to [armed_min_throttle .. 1.0]
344-
345-
//Quad mixing
346-
out.set(0, thr - PIDpitch.PID - PIDroll.PID - PIDyaw.PID); //M1 Back Right CW
347-
out.set(1, thr + PIDpitch.PID - PIDroll.PID + PIDyaw.PID); //M2 Front Right CCW
348-
out.set(2, thr - PIDpitch.PID + PIDroll.PID + PIDyaw.PID); //M3 Back Left CCW
349-
out.set(3, thr + PIDpitch.PID + PIDroll.PID - PIDyaw.PID); //M4 Front Left CW
350-
}
342+
// Set motor outputs to at least armed_min_throttle, to keep at least one prop spinning when armed. The [out] module will disable motors when out.armed == false
343+
float thr = armed_min_throttle + (1 - armed_min_throttle) * rcl.throttle; //shift motor throttle range from [0.0 .. 1.0] to [armed_min_throttle .. 1.0]
344+
345+
if(rcl.throttle == 0) {
346+
//if throttle idle, then run props at low speed without applying PID. This allows for stick commands for arm/disarm.
347+
out.set(0, thr);
348+
out.set(1, thr);
349+
out.set(2, thr);
350+
out.set(3, thr);
351+
}else{
352+
// Quad mixing
353+
out.set(0, thr - PIDpitch.PID - PIDroll.PID - PIDyaw.PID); //M1 Back Right CW
354+
out.set(1, thr + PIDpitch.PID - PIDroll.PID + PIDyaw.PID); //M2 Front Right CCW
355+
out.set(2, thr - PIDpitch.PID + PIDroll.PID + PIDyaw.PID); //M3 Back Left CCW
356+
out.set(3, thr + PIDpitch.PID + PIDroll.PID - PIDyaw.PID); //M4 Front Left CW
357+
}
358+
}

examples/02.QuadcopterAdvanced/02.QuadcopterAdvanced.ino

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385,12 +385,20 @@ Yaw right (CCW+ CW-) -++-
385385
*/
386386

387387
// IMPORTANT: This is a safety feature to remind the pilot to disarm.
388-
// Set throttle to at least armed_min_throttle, to keep at least one prop spinning when armed. The [out] module will disable motors when out.armed == false
389-
float thr = armed_min_throttle + (1 - armed_min_throttle) * rcl.throttle; //shift throttle range from [0.0 .. 1.0] to [armed_min_throttle .. 1.0]
390-
391-
// Quad mixing
392-
out.set(0, thr - PIDpitch.PID - PIDroll.PID - PIDyaw.PID); //M1 Back Right CW
393-
out.set(1, thr + PIDpitch.PID - PIDroll.PID + PIDyaw.PID); //M2 Front Right CCW
394-
out.set(2, thr - PIDpitch.PID + PIDroll.PID + PIDyaw.PID); //M3 Back Left CCW
395-
out.set(3, thr + PIDpitch.PID + PIDroll.PID - PIDyaw.PID); //M4 Front Left CW
388+
// Set motor outputs to at least armed_min_throttle, to keep at least one prop spinning when armed. The [out] module will disable motors when out.armed == false
389+
float thr = armed_min_throttle + (1 - armed_min_throttle) * rcl.throttle; //shift motor throttle range from [0.0 .. 1.0] to [armed_min_throttle .. 1.0]
390+
391+
if(rcl.throttle == 0) {
392+
//if throttle idle, then run props at low speed without applying PID. This allows for stick commands for arm/disarm.
393+
out.set(0, thr);
394+
out.set(1, thr);
395+
out.set(2, thr);
396+
out.set(3, thr);
397+
}else{
398+
// Quad mixing
399+
out.set(0, thr - PIDpitch.PID - PIDroll.PID - PIDyaw.PID); //M1 Back Right CW
400+
out.set(1, thr + PIDpitch.PID - PIDroll.PID + PIDyaw.PID); //M2 Front Right CCW
401+
out.set(2, thr - PIDpitch.PID + PIDroll.PID + PIDyaw.PID); //M3 Back Left CCW
402+
out.set(3, thr + PIDpitch.PID + PIDroll.PID - PIDyaw.PID); //M4 Front Left CW
403+
}
396404
}

src/madflight/cfg/cfg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ void CfgClass::load_madflight(const char *board, const char *config) {
468468
}else{
469469
Serial.println("madflight_config is empty");
470470
}
471-
hdr.madflight_param_crc = crc; //save crc (and write it to eeprom with next CLI cwrite)
471+
hdr.madflight_param_crc = crc; //save crc (and save it to eeprom with next CLI 'save')
472472
}
473473

474474
//returns true on success

0 commit comments

Comments
 (0)