Board index FlightGear Development Aircraft Autopilot and route manager

Implementing and testing pid controller

Designing a stable autopilot is one of the hardest things. Need help?

Implementing and testing pid controller

Postby tjark » Wed Apr 15, 2020 9:31 pm

Hey,

im studying electrical engineering in Germany and due to Corona we have to do a project instead of an exam. The task is to implement a pid controller for roll, pitch and yaw and optimize them. I read the articles in the wiki regarding the autopilot and know how to code the controller but i still have no idea how to implement it or test it. I also tried to get a debug file to visualize the behavior of the aircraft, but it isnt generated or saved in some mysterious path..
I hope someone can help me and has an idea how i can get this working.

Tjark
tjark
 
Posts: 5
Joined: Wed Apr 15, 2020 9:04 pm

Re: Implementing and testing pid controller

Postby Johan G » Thu Apr 16, 2020 1:16 am

tjark wrote in Wed Apr 15, 2020 9:31 pm:I read the articles in the wiki regarding the autopilot and know how to code the controller but i still have no idea how to implement it or test it.

It might help to look at existing examples, for example the KAP 140 of the Cessna 182. Typically autopilots can be found under the Systems directory of aircraft directories. Look at the simple ones, and do not forget to also look at the Aircraft-set.xml file to see how it is set up.


PID tuning can be quite tricky, and while one can throw control theory like Nyquist plots at it, one can also approach it with trial and error. To some degree, order of operations is relevant, in this context which gains to adjust and when.

It might help to search YouTube for "PID regulator tuning" and going through some videos. A good starter is the below might be:

Electronoobs, "PID Balance+Ball | full explanation & tuning" (13 min, uploaded July 14, 2019). The PID tuning stuff begins at 7 minutes.


tjark wrote in Wed Apr 15, 2020 9:31 pm:I also tried to get a debug file to visualize the behavior of the aircraft, but it isnt generated or saved in some mysterious path..

The debug file, if it is fgfs.log, is probably not that helpful. A good help might be either of the FlightGear wiki article Logging properties if a simple CSV file is enough, or Generic protocol if you want something more flexible.

Unfortunately I do not remember how, but you could use properties instead of fixed values for the PID gain filters and adjust them live from the property browser.
Low-level flying — It's all fun and games till someone looses an engine. (Paraphrased from a YouTube video)
Improving the Dassault Mirage F1 (Wiki, Forum, GitLab. Work in slow progress)
Some YouTube videos
Johan G
Moderator
 
Posts: 6629
Joined: Fri Aug 06, 2010 6:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 2020.3.4
OS: Windows 10, 64 bit

Re: Implementing and testing pid controller

Postby tjark » Fri Apr 17, 2020 3:23 pm

Thanks for your quick reply :)
I already tried some of your suggestions and tuning is not the problem since this is the third lecture on this topic.
After some hours of trying i have now figured out to implement my own controller. So my first problem seems to be solved.

Johan G wrote in Thu Apr 16, 2020 1:16 am:A good help might be either of the FlightGear wiki article Logging properties if a simple CSV file is enough


Getting the csv file would be great. I created an xml file as described in the wiki and referred to it in the additional options, but the file doesnt get created. Any idea what i am missing?
tjark
 
Posts: 5
Joined: Wed Apr 15, 2020 9:04 pm

Re: Implementing and testing pid controller

Postby Octal450 » Fri Apr 17, 2020 4:04 pm

Why would you look in that KAP140? its not the correct way of doing it...

CSV file is not needed - its waste of time. You can tune using property browser!

What are still needing to do with the controller? I can point you in the right directin

Kind Regards,
Josh
Skillset: JSBsim Flight Dynamics, Systems, Canvas, Autoflight/Control, Instrumentation, Animations
Aircraft: A320-family, MD-11, MD-80, Contribs in a few others

Octal450's GitHub|Launcher Catalog
|Airbus Dev Discord|Octal450 Hangar Dev Discord
User avatar
Octal450
 
Posts: 5583
Joined: Tue Oct 06, 2015 1:51 pm
Location: Huntsville, AL
Callsign: WTF411
Version: next
OS: Windows 11

Re: Implementing and testing pid controller

Postby tjark » Fri Apr 17, 2020 9:03 pm

I will tune it using the property browser, but for the documentation i would like to have a graphical visualization.
tjark
 
Posts: 5
Joined: Wed Apr 15, 2020 9:04 pm

Re: Implementing and testing pid controller

Postby Octal450 » Fri Apr 17, 2020 11:27 pm

You may try Phi which has a graphs in it, or FGPlot.

See the links:
http://wiki.flightgear.org/Phi
http://wiki.flightgear.org/FGPlot

Kind Regards,
Josh
Skillset: JSBsim Flight Dynamics, Systems, Canvas, Autoflight/Control, Instrumentation, Animations
Aircraft: A320-family, MD-11, MD-80, Contribs in a few others

Octal450's GitHub|Launcher Catalog
|Airbus Dev Discord|Octal450 Hangar Dev Discord
User avatar
Octal450
 
Posts: 5583
Joined: Tue Oct 06, 2015 1:51 pm
Location: Huntsville, AL
Callsign: WTF411
Version: next
OS: Windows 11

Re: Implementing and testing pid controller

Postby Hooray » Sat Apr 18, 2020 12:14 pm

FGPlot can probably be considered to be obsolete these days, there's a more recent bultin alternative using the Canvas system: http://wiki.flightgear.org/Oscilloscope_addon
Image

Also, you can log to arbitrary file formats using a combination of XML and scripting, so that you can use external standard tools (think gnuplot, matlab etc)
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Implementing and testing pid controller

Postby tjark » Sat Apr 18, 2020 7:39 pm

Thanks for your help, using Phi worked great for me.
tjark
 
Posts: 5
Joined: Wed Apr 15, 2020 9:04 pm


Return to Autopilot and route manager

Who is online

Users browsing this forum: No registered users and 2 guests