More crazy homebrew FC experiments

Twitchity

Senior Member
"Now lets land." One foot off the ground and just cuts throttle :p

Autotune with Tau seems to be better than Cleanflights
 

jhitesma

Some guy in the desert
Mentor
I must have missed an episode. :)

Are you doing anything to fly during autotune?


Yeah, that was right at the start. The board was just rubber banded on at that point :) (the sensors were properly mounted at least, just the discovery board was quick and dirty mounted.)

I was actually doing quite a bit during autotune and had full control, but since it wasn't well tuned it was a bit of a handful to control. I also didn't have a throttle curve setup yet hence the less than elegant landings :)

I've done autotune several times since then and get very similar results each time, it's a lot easier to do it with a good tune already on it though as I have to do very little correcting then. But the twitching it does to autotune definitely makes it a bit trickier to control than a normal hover. My backyard really isn't a good place for it - there's just barely enough room.

I haven't tried CF's autotune yet...since based on what I've heard about it I'm still too chicken to try it :) Too many people talking about near flyaways when using it for me to risk my emax frame to it which is the only thing I currently have running Naze. I may try it one of these days...but having looked at the approach CF takes to autotune compared to the approach Tau took I wouldn't expect the same level of results. Tau's autotune is very well designed and programmed with some serious work behind it. CF's was just borrowed from BradWii which in turn was somewhat based off MW and the autotune was just a fairly quick and dirty implementation of one of the simplest PID tuning algorithms. Tau on the other hand did extensive modeling of their system and PID controller and implemented a very robust system - in fact originally they didn't expect the FC to even pull it off and only expected the FC to collect data that the GCS could crunch to do the actual tuning. But A couple of contributors really knocked it out of the park with code that does it all in the FC.

I didn't get BLheli 13 flashed before dark tonight so no test flights today. Will try to get the ESC's reflashed before I crash tonight but I have some work work to catch up on before I can play with that.
 

jhitesma

Some guy in the desert
Mentor
Got my work work done and got my ESC's reflashed. Discovered that I actually wasn't running damped light on these yet...could have sworn I was. I guess I'll get to do a three way comparison on the auto tune - Just blheli, with damped light, and with damped light and oneshot. All of course still on a larger quad with 8 props and 1400kv motors which will in itself be interesting to compare.

However I'm not having any luck bench testing oneshot yet. Still trying to figure out how to enable it correctly in Tau - I thought I had it all setup right...but my motors don't spin up until almost half stick and they never get to full power. So something is off. I may have to calibrate the ESC's in oneshot mode...but that's going to be tricky because my USB issues have raised their head again.

Apparently I can get linux to connect over usb if I connect both USB ports on the Discovery board. The Discovery board has two USB ports, one the "HID" port which is part of the development board but which doesn't power the board when connected - the other the "VCP" port is part of the stlink debugger module on the other end of the board and does provide power when connected. So if I don't want to power off my flight pack I just connect both USB ports. The actual connection happens through the HID port - but the VCP port provides the power - I can confirm this by disconnecting the HID port and seeing my connection in GCS drop.

But...if I try to connect over the HID port while powered off my flight pack...GCS never detects the quad. And if I try to connect the flight pack while both USB ports are connected...GCS crashes.

So right now I have no way to calibrate my ESC's since I can't have the flight pack connected while running GCS on Linux. I can connect to GCS on windows with the flight pack connected...but I'm not setup to build GCS from code on windows and the official nightly builds aren't building oneshot yet so I can't use them as the uavobjects set doesn't match. (On Tau like OP the GCS has to be built to match the FW)

All of which means I've got some more bugs to work out before I can test oneshot. (I'm also not clear on whether oneshot is possible with PPM input right now or not...some of the talk about it made it sound like it wouldn't work...but then some of it sounds like it does. The guy who implemented oneshot on Tau is only using Graupner's serial interface (like a spektrum sat or futaba s.bus) and hasn't tested with PPM yet...so that could be my issue as well.)

Oh well, too late to do anymore tonight and I didn't even get to the hardware updates on my Twitchity acro quad I was really hoping to do and post about tonight...but since my build table is a bit covered in balsa still that's probably a good thing ;)

Tomorrow I'll test autotune with damped light and see how that goes. At least I have that much to look forward to :D
 

jhitesma

Some guy in the desert
Mentor
So got to do a quick test flight at lunch, didn't really notice a big difference with damped light enabled but didn't really expect one. With the 12a BS ESC's on my mini I noticed a bit of a difference but not nearly as much as the KISS make so on this larger setup with bigger props that carry more inertia I expected even less of a difference and that was about what I got.

I did notice the motors and ESC's were a bit warmer than normal after just a short flight though.

I didn't get video of autotune because I didn't get to try it until after dark. But I did get fairly different results even though the handling is still very good and the damped light effect isn't all that noticeable.


Original autotune results with BLheli 12.2 and no damped light:


Measured properties
GainBiasTau(s)Noise
Roll9.28895-0.03581390.047464.107
Pitch8.887930.006541380.047563.658


Tuning aggressiveness
Damping1.1
Noise sensitivity1 %
Natural frequency3.9


Computed Values
RateKpRateKiRateKd
Roll0.001875890.003730836.45268e-05
Pitch0.002801350.005571419.63607e-05
Outer Kp3.65604--
Derivative cutoff13--


And revised results after upgrading to BLheli 13 and enabling damped light:


Measured properties
GainBiasTau(s)Noise
Roll9.73757-0.01270940.034282.1875
Pitch9.20915-0.02308260.0342166.793


Tuning aggressiveness
Damping1.1
Noise sensitivity1 %
Natural frequency5.4


Computed Values
RateKpRateKiRateKd
Roll0.001648970.00451024.13095e-05
Pitch0.002797090.007650457.00715e-05
Outer Kp5.02803--
Derivative cutoff18--


Things that jump out at me...the noise readings went down significantly from the 500 range down to the 100 range. Tau went down as well (though I'm still unclear on just what that represents...I'm starting to understand but haven't reached the point where I can describe it yet)

The natural frequency went up. But the PID values went down for P and D and up for I. The outer P term (which is what controls auto level I believe) went up significantly.

Not sure just what to make of these changes since I'm still learning how the Tau Labs PID controller works. It did feel significantly more locked in after the autotune. I'm thinking about disabling damped light and doing one more try just to have more consistent data with the same version of blheli and the frame in the same condition (it's had a few bumps since the original autotune and isn't quite as flat as it was so that may have affected performance some.)

Just may not get to try that for a few more days as we've got 25-35 MPH winds predicted for the next two days :(

I may try tonight still...it's calm out. But flying this thing at night is tricky even with all the LED's I've got on it I really need to put some on the top and/or bottom of the booms as well to help tell how much tilt I've got going on.

Plus I still want to get oneshot working on this setup to see how that does. Still not sure why I can't get it working and the goofy USB issues on Linux are keeping me from being able to calibrate the ESC's when oneshot is enabled.
 

jhitesma

Some guy in the desert
Mentor
Ok, did some more testing tonight....kind of thinking I may start a new thread to share these results in. Not sure how many people are still following this thread and this seems kind of worth sharing.

What I did was try to replicate what Peabody124 did with oneshot - only since I don't have oneshot working yet I did it with damped light. And since I'm not quite the math whiz he is I can't toss around terms like tau and anova...I barely feel qualified to use Quantitative. I also don't have as much flight experience as quadmovr/warthox or FGA or charpu - but I have enough to have a good feel for what I like in the air and what I don't like. So this is slightly quantitative but also a good bit "butt dyno" if you will ;)

I ran 3 sets of autotune with damped light enabled. After doing three sets all of which were very similar I checked the temps on my motors and ESC's as they felt a little warm to me. Both motors and ESC's were in the 94f range. I did see a few spikes up to about 100 but my infrared thermometer isn't super accurate and it was never more than just a quick flash - mostly I saw numbers in the 93-95 degree range on both motors and ESC's. Since all three autotune trails were very similar I loaded the suggested tune from the last one and gave it a try in the air. Wow! It felt GREAT. Super locked in, very responsive and snappy. I was smiling ear to ear. On the Qualitative side my Tau figures ranged from 0.0344 to 0.0388.

Side note. I still don't feel quite like I'm capable of really explaining Tau...but I'll give it a shot. My understanding (and I could be wrong) is that Tau in this context is the time constant of the PID loop. Meaning it's a measure of how quickly the PID loop reached equilibrium and stabilizes on a value. So the lower the Tau the faster the PID is locking on to achieve the control desired.

I then hooked up blhelisuite and switched from damped light to high PWM on all four ESC's then did 3 more sets of auto tune.

After the three sets of autotune I again checked temps. They were a little lower on the motors - I'd say in the 92 degree range though again I saw a few spikes up to 100 and a few lows down around 87-88. It was a little cooler out by now (it was after dark so no video of these tests BTW) so that may have been as much or more of a factor as disabling damped light. The ESC's actually gave slightly higher temp readings this time. (Note these tests were done 2 hours apart so things had cooled completely between them.) After the three tests which again were very consistent with each other I loaded the suggested settings from the last test and gave it a quick test flight. It still felt good...but it wasn't nearly as locked in and snappy feeling. Descents were slower and it didn't snap into position with as much authority when I gave it some stick. It was a tune I'd be happy to fly this setup on - but it didn't feel quite as good as it did with damped light.

On the Qualitative side my Tau figures had gone up to 0.0563 to 0.0587. That's a bigger change in Tau than Peabody saw with vs. without oneshot. By quite a bit.

I have screen shots to back this up...but they're on my other computer. I'll share them once dropbox gets around to syncing them. Until then I've got dinner to eat - and damped light to re-enable :) I was a little worried about the motors feeling warm with damped light...but testing seems to show they're not significantly warmer than without - and performance is significantly improved even if not as obvious as it is on smaller quads.
 

peabody124

Junior Member
Really nice work, and if my work inspired more rigorous quantitative testing in this field then I'm super pleased!

Just to clarify the tau is not the speed of the PID loop (exactly), but rather the time constant of the ESC response. So a tau of 0.05 means that the ESC will get to 67% ( 1 - e^-1 ) of it's final value in 50 milliseconds. The end result of a faster ESC is that you can set up the PIDs to respond much more quickly without having oscillation. So your intuition about it affecting the speed of the control loop is correct (after autotuning calculates the new value). I think the natural frequency on the gui is the speed of the control loop (can't remember if it is Hz or rad/s).

I apologize - I really really really need to write up the autotuning algorithm and have a half done blog post on it. It sucks for people not to have a better understanding of what it does (even if it is awesome ;-).
 

jhitesma

Some guy in the desert
Mentor
Thanks for the clarification! I considered asking you to provide some clarification before posting...but was too excited to share and figured you've got enough on your plate already that you didn't need me bugging you about ;)

That explanation really clarifies a lot for me. I wasn't sure what the time constant was measuring the response of and assumed it was the response of the PID loop not the ESC.

The natural frequency I was even more confused about (which is why I didn't mention it in :D ) I figured it was some kind of measurement of the control loop but had no idea what kind of units it was in and haven't dug into the code to try and figure it out.

My hat really is off to you and the others who made Tau's autotune - it really is amazing and I can't get over how well it does! I wish I had more time to experiment with different aggressiveness settings. But I keep having so much fun flying on the default settings I keep putting it off :D
 

peabody124

Junior Member
If you are bored watch the second half of this video

if I recall correctly, I walk through some analysis of the control structure and show the impact of the ESC performance (speed) and how it is the main limitation on the quad performance.
 

Craftydan

Hostage Taker of Quads
Staff member
Moderator
Mentor
I'm not sure how well I 'follow' this thread, but I still read all the words. :)

CR,

Keep in mind the stuff Peabody is covering is *at least* a 3rd year course material in a colege engineering program. That doesn't mean you shouldn't understand it, just that to fully grasp it you've got to have a good hold on some pretty hard topics.

Gleen what you can, and don't feel any less smart if the rest doesn't come easy -- It's NOT!

This topic alone has created quite a few business students out of perfectly good engineering students.
 

makattack

Winter is coming
Moderator
Mentor
In my humble opinion, Controls Engineering folks speak another language... one where mathematics and physics are so intertwined that my head hurts just saying "Control Theory".

Ok, back to playing with my lego set...
 

jhitesma

Some guy in the desert
Mentor
If you are bored watch the second half of this video

if I recall correctly, I walk through some analysis of the control structure and show the impact of the ESC performance (speed) and how it is the main limitation on the quad performance.

I'll have to check it out again tonight. I did watch it when I was first learning about Tau (Pretty much stalked your Vimeo account and watched every vid you had :D ) I remember that being one of the best PID videos I'd seen...but I can definitely use a refresher!
 

jhitesma

Some guy in the desert
Mentor
Last night I re-enabled damped light after seeing the improvement on paper. But I didn't have time to run autotune on it again before going to bed. So today at lunch I figured I'd give it a go. Except it's windy today. Like blow the door out of my hand have to lean into it to walk windy :D

Well, never being one to do the sensible thing I decided to give autotune a go despite the wind.

First glace at the results I was excited...my Tau got down below 0.03! But then I noticed the noise figures...over 900 and over 1000...well that's not good. Last night it was a bit breezy but my noise figures stayed around 150. (the second round they got closer to 200) Then I noticed the suggested PID's. The P and I terms I've always gotten suggested before are tiny...like 0.00 something. This time it was suggesting I terms in the 800-900 range! Woah. Yeah, not even going to try to fly on those!

Lesson learned - if it's too windy to stand upright comfortably it's too windy to autotune :D Hopefully it will calm down again after dark today and I can give it another go. Then dig in on figuring out why oneshot isn't working for me yet.
 

Twitchity

Senior Member
You should run the autotune in your living room with the ceiling fan off. No wind and I'm sure your wife would enjoy it :) It's nice to see the Tau software notices outside forces acting upon the craft and show you the results.
 

jhitesma

Some guy in the desert
Mentor
My living room isn't big enough to fly my 250 let alone this beast :) With the shaking it does in autotune it can be a handful to control and a decent amount of space is good to have. My living room is barely 10x15 and I can't even hover my Syma X1 in there without making a mess from the propwash blowing stuff around :(

And just for the record it's still up to the user to check that the values look reasonable before accepting them from autotune. I've come to trust it so well I generally just give them a quick glance - and almost missed how far out of whack they were this time! It was only seeing the Tau so crazy low that made me take a closer look at the other numbers and realized how badly the wind had affected it.

Usually when doing auto tune I just give very small inputs to try and keep the quad in the area I want it to stay in. But this time...with the wind...I was at a 10 degree angle minimum at all times just trying to stay in the front yard and never got to take my hands off the sticks. I thought about trying it in the backyard below the fence line where it's less windy...but ended up deciding I'd just wait for a less windy day. I can also just put in the values manually from one of the previous successful runs...but that's more numbers than I feel like entering manually given how many digits the Tau PID's use :D
 

jhitesma

Some guy in the desert
Mentor
Well, may have a oneshot update soon. Still trying to figure out what's causing my USB issues on Linux. For some reason when the quad is powered by it's flight battery it refuses to connect on Linux. I get some very odd errors from deep in the USB subsystem that seem to indicate either a protocol error enumerating the connection or that the hardware is shutting down because of an overcurrent condition on the USB port. Neither of which make much sense since the same cables connected to the same ports work just fine when I power the board off the ST-link connection.

I tried jumpering pin PA9 which has power from the other USB connector (the one that actually connects with Tau) to VDD on the Discovery so I could power the board all off one USB cable...but it give the same errors it does when powered off the flight battery then.

But today (well, technically yesterday now) Peabody added the pull request for oneshot to the main next branch on github so there should be nightly windows builds that I can use GCS from any day now. The linux builds are already up, but the windows hasn't hit yet. And since I don't have USB issues in windows once that hits I can use windows GCS to do my ESC calibration and get oneshot live. Then I can redo the autotune comparison and see if oneshot on BS20 ESC's gives much of a benefit.
 

cranialrectosis

Faster than a speeding face plant!
Mentor
CR,

Keep in mind the stuff Peabody is covering is *at least* a 3rd year course material in a colege engineering program. That doesn't mean you shouldn't understand it, just that to fully grasp it you've got to have a good hold on some pretty hard topics.

Gleen what you can, and don't feel any less smart if the rest doesn't come easy -- It's NOT!

This topic alone has created quite a few business students out of perfectly good engineering students.

One of the things I like best about this hobby is that not only do I not understand it all, no matter how much I learn, I never will. Keep it coming jhitesma and Peabody... For some of us, this is the stuff that keeps the hobby interesting.
 

nilsen

Senior Member
I was shooting some aerial photos for a friend of mine who is selling his house and he was absolutely amazed by the technology in my AP hex. He's from an RC background haivng flown planes for years but hasn't done anything for a long time.
He was telling me he built a mechanical gyro for a helicopter he had as a boy which worked with two spinning plates and a hall effect sensor to regulate the tail motor speed and counteract the yaw.
Point is, this is facinating and reading this thread just adds to the theory and practice and even if we don't understand it all, it's still highly interesting and just adds a bit of extra understanding of our beloved hobby.