I’m off to London tomorrow morning, and up to Cambridge after work, so I’m packing her up ready for her journey.
She’s probably doing the best she can given the inaccuracy of the sensors, but I’m still not quite confident she’s good enough for an indoor demo, based upon a few tuning test flights this morning.
So fingers crossed for a safe journey and a good day on Saturday, and I’ll update you on the results.
Wish us luck!
P.S. Just cheated and run her through the calibration cube again with the aim of getting the best possible set of sensor readings for the show.
- one bug fix to integrated the gyros rather than just using the last sample
- one deletion of redundant conversion from horizontal velocity to required angle whose PID is ancient history
- retune the horizontal PIDs’ gains
- test flight leading to a number of literally flipping crashes as my guestimate PID gains were way too high
- fix resultant Phoebe who wouldn’t boot after crashes – SD card socket damaged irreparably – new model A (reserved for the now unnecessary radio control)
- retune again with much reduced PID gains resulting in…
- final test flight of the day: she takes off at the angle she was tilted on the ground resulting in rapid backward movements which then slows, stops, and she then returns to the point she took off from.
Net: probably the best motion tracking flight yet, but the day would have been much more satisfying had I not had been forced to rebuild her mid-way through. Still on track for CamJam in 1 week.
Velocity vs Angle
Same data as the previous post, but this time with velocity vs compensatory angle. As before, forward velocity is positive, nose-up (reverse acceleration) is positive.
So as the forward velocity increases (for example), so does the reverse acceleration to compensate, but there’s a lag; in fact the velocity and the compensatory acceleration are about 90° out of sync and oscillating, suggesting the horizontal velocity PID is overcompensating, causing the velocity correction to overshoot, cause the horizontal PID to overcompensate…
And that means I know where to go next with my tuning: to make the P gain less dominant and increase D gain instead..
although probably not what you want to hear. I think I’m biting off more than anyone else has ever chewed before: autonomous (self-contained) flight control. I was watching a normal guy’s first flight of his DIY quad. I’ve no idea of it’s build, but the first test flight was in his 4m x 4m lounge (my estimate) full of furniture, and it went better than Phoebe had ever achieved.
Then I started thinking back through all the other YouTube videos of quads in flight, and they all share the same piece that I am missing – an external PID feedback system whether it’s a human with a transmitter or the external monitoring system as shown by Raffaello D’Andrea’s video.
So I started looking at quadcopter PID images on Google, and they show the same thing: they all have an external feedback system (usually a user with an RC transmitter) where I have my velocity PIDs. This is why I’m having so much trouble with drift control: untuned acceleromer integration to produce drift feedback simply cannot work due to offset / gain inaccuracies; for completely autonomous control, the accelerometer tuning with trend lines to incorporate temperature shifts may well be the only solution until drift becomes large enough for GPS to take over.
I think I may have to return to the tedious trend line tuning to get better trends and hence better drift control.
Still, it’s motivationally exciting to think I may be breaking new ground. Shame it’s taken me so long to come to this conclusion.
with the offset / gain in place, and a tweak of the horizontal velocity PIDs, I finally can see drift control working. It’s still there, but so much better than ever before.
It also confirmed I need to do some temperature trend-lining for accelerometer offsets and gains – I did the offset / gains indoors at about 20°C. Outside it’s only 10°C and that definitely had a significant effect on vertical velocity, and to a lesser extent horizontal too.
I almost daren’t say it, but it really does now feel I’m on the downhill run and the finish line is finally in sight – still in the distance – but visible at last. Phew!
I spent a fair proportion of today and yesterday tweaking and tuning the offsets out of the accelerometer and gyro. Gyro was a doddle as expected, and I’ve now got a process to reduce the accelerometer tune to a hour rather than a day, though it does start early in the morning before the sun rises. I suspect it won’t work well in a mid-summer heatwave where the temperature doesn’t drop much at night.
All I do it move Phoebe outdoors to the coldest spot I can find (the garage) and leave her for a while to cool down. While that’s going on, I move indoors and spend the time making the test platform as horizontal as possible – I even bought a super-spirit level a while back just for this job. When all’s ready, I whisk her indoors, power her up, and run her calibration code which reads the accelerometer, gyro and temperature sensors, writing the output to file. How often I do this depends on how rapidly the temperature rises – every few seconds at first, increasing to perhaps every 1/2 hour at the end, aiming for 0.5°C rise per sample. I’m aiming for an even spread as this will give me the most accurate trendline to use in the code. Phoebe is powered from the micro-USB port rather than the battery as this leaves the ESCs / motors unpowered and so noise is minimized.
Net result 0.001g accuracy in all 3 accelerometer axes, i.e. instead of reading (0, 0, 1)g, they read (0.001, 0.001, 1.001)g or roughly (0.01, 0.01, 10.01)ms-2. Previously the raw sensor output was more like (0.04, 0.036, 1.06)g so a 40 – 60-fold improvement. Vertically, that’s probably OK, but horizontally, I’m less confident. Over 10s that 0.001g equates to 0.5m horizontal drift, which is not good enough for my ultimate goal of a 1 minute flight with drift < 10cm – i.e. demo’s in schools and Jams.
Still, I’ll give it a shot tomorrow to see if my unpowered tuning holds up in powered testing. Only time will tell.
Gyro and accelerometer trends
Just a quicky: I spent yesterday gathering these higher quality trends mapping gyro and accelerometer offsets to temperature.
The trend lines are a lot more closely tied to the data points, so hopefully that’ll mean more accuracy. I’ll give it a try today or tomorrow – I’m hoping that the net result will be even more limited drift, plus longer flight (different sides of the same coin essentially).
The latest code matching the flight in the previous post’s video is now up on GitHub with the default PID gains set to match the flight. If I were you though, I’d wait a couple of weeks before you try flying your version; there’s various steps of testing / tuning necessary before yours will fly in a controlled way, and a (not so) little bird told me there might be an article coming soon describing those steps in much more detail .
New day, new test rig – and ultimate a set of what seems rock-solid PIDs – see the comments in the previous post for the actual values.
Time to take Phoebe outside. She flew, but round in a 3m diameter circle (ish). That’s effectively oscillation in the X and Y plane slowly and 90 degrees out of sync. I was already slightly suspicious the Ki gains were too high (based solely on past experience), and this confirmed it.
FWIW if you’ve got oscillations in your quad in flight, here’s how to spot the root cause:
- swooping (like above) back and forth at a rate of >> 1s is generally over enthusiastic Ki gain
- swinging on an axis at a rate of ≈ 1s is generally over enthusiastic Kp gain
- jittering like the quad has drunk too much coffee is Kd gain’s fault.
Anyway, depending on the weather tomorrow afternoon (kid’s are off to a birthday party so I have the place to myself for a couple of hours), I’ll either rerun my step-ladder PID tuning rig but with the suspension strings nearer her centre of gravity or I’ll head outside to play with the Ki gain.
Just realized why I’m struggling so much using Z-N PID tuning. Currently Phoebe is resting the fingertips of her stationary motors on the test platform. But her centre of gravity is above this point making her extremely unstable, and therefore very hard to tune. I need to simulate as closely as possible her flight position by suspending her as close to her centre of gravity as possible which is by her wrists. Some string tied between the back of some chairs and her wrists should do the job nicely. I’ll update this post tomorrow with results.
I won’t hear a bad word said about Z-N! Once I’d got Phoebe strung up like this (strapped between the legs of a step ladder – the string / chairs combo wasn’t strong enough), I ran the test with only PID p gain to determine the ultimate gain Ku and combined with the wobbles count of the test came up with Kp, Ki, and Kd for all of the options (classic, some-overshoot, no-overshoot). All were good, but none were perfect. However, once you have a set of good PIDs, then it’s safe to merge them to make it perfect, cherry picking the best features of each – in this case a blend of ‘some-over shoot’ and ‘classic’ with slightly increased Kd gain for some spice. Have a careful look:
Z-N PID tuning setup
You can just about see the nearest and furthest blades spinning to keep Phoebe horizontal, and they are doing it so well that she looks frozen in space yet the shutter speed was 1/50s. The lack of blur in the photo (other than the props) gives a really good indication of how well the tuned stability PID was working!