![]() ![]() ![]() The I term (integral) is meant to take care of accumulated errors (which are usually long term errors). Going with the “less is more” truism with PID controllers, I started with a P value of 0.1, and an I value of 0.01 (P/10). Many will also have an I (integral) value set, but not many use the D term (derivative). They will basically always have a P (proportional) set. In the YouTube video, I talk about the various types of PID controllers. If your gains are too high, you could get giant oscillations and other undesirable behaviors. When setting PID values, it is almost always a good idea to start small and work your way up. For example, if the aircraft has a roll of 10 degrees to the left (-10), and the P=0.2, the output from the PID controller will be -2. This essentially means make the output be 20% of the error between the setpoint and the current value. The default values with the PID library are P=0.2, I=0, D=0. But they do need to be set with smart values for the initial run. Then we can initialize the control instances. Put the file in the same working directory as everything else then import it with import PID at the top with the rest of the imports. current_roll = posiĬurrent_pitch = posi 3 – Initializing the PID controllersįirst you need to get the PID control file from the Ivmech (Ivmech Mechatronics Ltd.) GitHub page. There are 7 elements returned with that method, and two of them are roll and pitch. In the first post, the monitorExample.py code included obtaining the position with posi = client.getPOSI(). # rest of the loop code goes here 2 – Obtaining current roll/pitch values from X-Plane # when the if statement evaluates to true, the first thing we'll do is set the last update to the current time so the next iteration fires at the correct time If (datetime.now() > last_update + timedelta(milliseconds = update_interval * 1000)): # this if statement is evaluated with every loop execution To do so requires wrapping all of the loop code into a new if statement that evaluates the time and only executes if the current time is 100 milliseconds greater than the last loop execution: # loop is the "while True:" statement # last update needs to be defined as a global within the monitor() function: # alternatively, we could've set start to something in the past. # last_update needs to be set to start for the first execution of the loop to successfully run. ![]() # start is set to the time the line of code is executed, which is essential when the program started 1/0.100 = 10 which is the update interval in Hz Next, define the timing variables: update_interval = 0.100 # this value is in seconds. To accomplish this task, we need to set up some timing variables.įirst of all, add an import statment for datetime and timedelta: from datetime import datetime, timedelta For reference, my RC plane running ArduPlane on Pixhawk uses 50 Hz as a standard update frequency. Most control loop algorithms run in the 10-100 Hz range (10-100 times per second). It could potentially execute thousands of times per second, which is entirely unnecessary. We do not want the loop running uninhibited, because that will result in variable loop execution times and we like to keep those things constant. Since we will be targeting a 10 Hz update rate, we need to develop a method to ensure the loop does not run more frequent than once every 100 milliseconds. Monitoring the control loops via debug prints.Controlling the aircraft with the new PID output.Feeding the PID controllers within the control loop.Obtaining current pitch/roll values from X-Plane.Python Tutorial: code a wing leveler in X-Plane using PID loops Contents The full code will be at the end of this post. Some debugging output to keep track of what the PIDs are doing.Two PID controllers, one for roll, one for pitch.A control loop timer (we will be targeting a loop frequency of 10 Hz, or 10 updates per second).Today will add a few features to our XPlane autopilot written in Python. The first post was just about making sure we could get data into and out of X-Plane. Continuing from the first post, where we hooked up X-Plane to our Python code, we will build a wing leveler today. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |