Tune and Trim a Magpie

I just finished setting up my Magpie AP airplane to use the ArduPilot UAV controller, and used a fast and easy way to setup the PID and trim values.I made a ground station that can send new trim values up to the plane while it's in flight. That made trimming easy - only took two flights to get it straight, level, and stable.

The ground station consists of an ATMega168 running the code, an XBee pro for the radio transceiver, a box full of buttons, a rotary pot to adjust values, a serial LCD for the display and a 1700 mah NiMh battery.The ArduPilot code was changed to put many of the adjust and trim constants into EEPROM settings and code variables so they could be changed, and stored on the fly as tuning progressed.The ground station allows me to send up new PID values (Kp, Ki, Kd, Min/Max) and trim settings (roll_trim, pitch_trim) as well as any other variables I'm adjusting (Fly_by_Wire_Roll_Gain, Fly_by_Wire_Throttle_Set_Point, etc)

The ArduPilot code only required a small change to add the code required to receive the messages from the ground. (The GPS was removed, and the XBee on the plane was connected to both Rx & Tx for send/receive to/from the ground station during the trimming process)

The commands from the ground are very simple. I only send one value at a time. ( Roll_Kp = 0.3 ) The ground station controller uses a Menu system to scroll thru the various commands available. Each screen shows the variable being adjusted, it's current value (sent from the plane via the std ArduPilot Print_Data sequence) The rotary pot is used to dial in a new value. Once the value is set via the pot, one of the red buttons is pressed to actually transmit the command to the airplane. The code in the plane sends back an "ack" and the ground station beeps 3 times to signal a successful transmission of the data to the plane. That way I KNOW the new value is in place. I can also confirm the new value via the display - the aircraft is always transmitting the current values - and these show up in the ground station display in real time.Using this ground station to up-link data to the aircraft made setup and trimming a breeze.In general, here is the sequence I followed:1. Do ground testing of the UAV control stuff - test the sensors to confirm control surfaces move in the proper direction when tilting the aircraft.2. Get the aircraft flying under manual control. Adjust and trim for straight, level flight.3. Switch to "Fly by Wire" mode and watch what happens.(Be ready to quickly switch back to manual control)Does the aircraft dive?, climb?, Roll?, wobble?, Stall?, all of the above?4. My aircraft oscillated about the roll axis, and wanted to dive.I knew this meant the roll PID was set too high, and the pitch trim was off.5. I decided to work on the roll values first.- I turned off the pitch PID (by setting pKp and pKi to zero.)- I turned off the roll Ki (set it to very low: .04), so I could first tune Kp.Oscillations mean Kp is set too high. The PID is overshooting it's mark.There are some good articles on tuning PIDs.The current EasyStar Kp value was 0.7. I started dropping by 0.1 to 0.6, 0.5, and at 0.4 the oscillations stopped. I took manual control of the airplane, placed it in a steep roll, and turned on the AutoPilot. The plane immediately righted itself, and returned to almost straight flight. Increasing the roll Ki to 0.1 brought the aircraft to a more stable level position. (adjust Kp for quick, gross response without oscillations. Adjust Ki to fine tune the setting)6. I needed to adjust the pitch trim. The aircraft wanted to dive.I turned the pitch PID values back on (Kp = 1.3, Ki = 0.7)The current trim setting was zero. I sent up the value pitch_trim = 10. From manual straight and level flight, I switched into Fly by Wire mode, aircraft immediately dove. Back to manual control. Sent up the value pitch_trim = -10. Entered Fly by Wire, and the aircraft was flying straight and level.I had been hoping I could read the pitch & roll data real time during flight via the ground station, but I kept getting radio interference during flight, and unreliable radio connection while the aircraft was overhead. We had to glide the aircraft low and slow (no motor) near the ground station to send up commands.

E-mail me when people leave their comments –

You need to be a member of diydrones to add comments!

Join diydrones

Comments

  • Chris has suggested in other posts that software serial is really nonfunctional for this app, I wonder what you ( Clarence) have done differently
  • Rather than using the same serial line for GPS and telem, what we did, was simply add a software serial line to pins 8 and 11. This allows us to communicated at about 12 Hz with filtering and all that fun stuff.We have tested this system, actually controlling two AC at once. Just a thought for ya
  • Hi Pete,

    Any updates on the rest of this? Can a standard Ardupilot board be used for this easily?

    Rgrds
    Sarel Wagner
  • Pete, Very useful project! Would love to see your circuits for the ground station and how you wired the Eeprom to change the PID settings on the fly!

    re your XBee radio interference- I'll assume your RC Tx is on a different frequency, and that you have 50 or 200mW XBees. Is the XBee powered by the flight LiPo? If so, maybe you're getting noise over the power line from the motor or Esc. Have you tried powering the XBee with another battery? Or you can try filtering caps on the XBee power wires.

    Are you using a dipole antenna on the XBee ground station? You can improve the ground station antenna dB by switching to a polarized patch antenna, here is some good easy diy plans for a 8 dB gain antenna http://webx.dk/rc/video-wireless/patch5.pdf and the author's testing results http://webx.dk/rc/video-wireless/ant24measurements.htm. This patch is working great for me at 2.4Ghz.
    http://webx.dk/rc/video-wireless/patch5.pdf
  • Here is a link to the Arduino version of the XBee Base Station software. Includes copies of the changes made to the ArduPilot code. http://www.photopete.com/swarm/ArduBase.zip
    http://www.photopete.com/swarm/ArduBase.zip
  • 3D Robotics
    If you can think of a way to "productize" your ground station and make it something we can make and sell, we'd be delighted to so. I presume it includes the functionality and code of ArduStation? (If not, it should!)
  • Nicely done, what a great way to tune the aircraft!!!! I suppose a natural progression would be to add another switch channel to the ardupilot (or another atmega45) to control the input to the RX channel, so that you could flip btw GPS and adjustments.
  • Here's a link the the Ground Station code, and the receiver part of the ArduPilot code.
    http://www.photopete.com/swarm/XBeeBase.zip
    It's very figure-out-able.
  • Yes, I will open source it. Sooon...
  • 3D Robotics
    Excellent! We were going to do this with ArduPilot Mega but you beat us to it!

    Are you planning to open source it? We might want to incorporate some elements into the standard codebase.
This reply was deleted.