Page 1 of 1

Question about Automatic Drone Balancing activity

Posted: Sat Jan 20, 2024 3:03 pm
by hbenac
Type your question below and then press Submit!
Hello!
The code is acting very weirdly, changing ki makes the speedchange grow bigger infinitely.
also the joysticks shows it works on the serial monitor but the drone can't keep up. it doesn't respond somehow.
can you please help?
thank you so much!



-------------------------------------
Leave this to help the Experts:
The activity can be viewed at: Automatic Drone Balancing

Re: Question about Automatic Drone Balancing activity

Posted: Mon Jan 22, 2024 7:36 am
by bfinio
Hi - PID control is a pretty advanced topic, very small changes to the controller gains can result in very large changes in the drone's behavior. Integral control (the Ki variable) can result in "drift" where as you noticed the error just keeps accumulating so the speed change will just keep getting bigger and bigger. You can prevent this in your code by adding an IF statement to prevent the speed change from going above (or below) some maximum value, for example:

if(speedChange > maxValue){
speedChange = maxValue;
}

Here, for example, if your maxValue is set to 1000, then every time your speedChange variable goes over 1000 (becomes 1001), the IF statement will reset it to 1000, preventing it from ever going higher than 1000.

Depending on the gain settings and how fast you move the joystick, the drone may not be able to keep up. If you are having a lot of trouble with this project, we recommend doing the altitude control version with an ultrasonic sensor first, it is generally easier to get this one working:

https://www.sciencebuddies.org/stem-act ... de-control

Hope that helps!