Loiter mode and PSC tunning

@LoopZilla I looked at your log and your parameters. It appears that you have not done any tuning of your Rate controller. It looks like you used the default parameters which are not recommended. I would suggest that you read through the tradheli wiki and tune your rate PID gains. In order for the controller to hold attitude well in a hover, you will need to set the ATC_RAT_PIT_ILMI and ATC_RAT_RLL_ILMI to some non-zero value. I typically recommend 0.08 which gives the controller the ability to hold up to 5 deg of attitude error.

Also I would suggest while you are tuning to use the following LOG_BITMASK of 131071. This will give you high logging sample rate. You will then be able to see noise from the rotor vibrations. Use the Harmonic notch to clean up your control feedback signals.

After you tune your attitude controller, then you might revisit tuning of the position controller parameters.

If you need any help or have questions with the tuning guide, let me know.

@bnsgeyer
Could you show us a snippet of the symptom in our rate control you are seeing in the log file (showing >5deg attitude error)? Possibly where the rates are off and I am not able to hover well? I’d just like to visualize what you are suggesting versus our experience watching it hover. We did indeed sped quite a bit of time following the Wiki, but we also spent quite a bit of time flying it in a lot of different conditions.

Two additional questions:

  • Which log file parameters are you comparing to see the >5deg?
  • What is the play IMLI and IMAX make in FFF? I believe this is why we went back to default numbers…

Gonna go hover real quick to generate a new log file with higher rates and less confusion…

@LoopZilla Here is a snippet from your flight


Notice how the actual rates don’t even follow the desired rates. The controller is probably putting in a lot more desired rate in order to achieve the response you are requesting because the rate controller was not tuned properly. The plot below is for a tuned 600 size heli

Here you can see that the actual rates closely match the desired rates which give the auto pilot much better control over the vehicle. also you’ll notice the noise is much less in the actual rates. A notch filter was used to attenuate the noise from the rotor 1/rev vibration.

I wasn’t saying that I saw 5 deg of attitude error but that using ILMI of 0.08 will give the autopilot the capability of absorbing 5 deg of attitude error if necessary (due to winds or whatever). Right now ILMI is zero so for ground speed less than 5 m/s, there is no ability for the controller to compensate for bias that you see in the attitude traces (shown below)


note the large error between desired and actual attitudes. You may not notice this visually from flying the aircraft but the puts the autopilot at a serious disadvantage when trying to hold position because it is not getting the expected attitudes requested by the position controller. Therefore you can get toilet bowl effect and just poor performing system. It may only have been performing better with the high PSC_VELXY_P gains because it had to overcompensate for the inaccurate attitudes that it was requesting.

Hopefully this helps.

Copy all.

That does indeed help, and exposes quite a bit of the reason the learning curve is so steep for most folks. The fact I missed these artifacts is evidence that even though people are diligently acting according to the Wiki, a visually appealing hover is where we call it good, and just move on to solving the bigger issues (especially those of us more familiar with bang - bang control architecture).

So, I will certainly revisit the rate tuning right now and post the results.

@ZvikaF I hope this isn’t considered hijacking your thread…

OK - I learned a lot more. Visually, in a hover nothing changed. As far as the ‘feel’ the heli feels more sluggish with a IMLI of 0.08. But I captured this log after tuning the D and P rates again, and setting the IMLI to 0.08.

https://drive.google.com/file/d/1yb-nvv4INFfC2UJYWdghii-SK-vSJo_w/view?usp=sharing

The D wasn’t far off what we had it set to originally (it had a payload mounted at that time) and today we went from 0.001 to 0.0013. Mad oscillations at 0.0020 and I can pull that log if we need to. For P, it did indeed need work, and went from 0.024 to ~0.058. A more than doubling is indeed significant.

I hope to get on revisiting the I, IMAX, and ILMI tomorrow as well as applying the notch filter.

So, I think the traces look WAY better - but overall the performance didn’t change much, even in PosHold where I was expecting a position oscillation due to over-tuning, which it didn’t.

I’m super happy to have it closer to perfection! Thanks @bnsgeyer!

1 Like

Not at all @LoopZilla, the more the merrier…
I’m getting exposed to more information and hopefully it will help me on the tuning.

Did you tune the VFF gain. That is one of the more important ones to tune.

@bnsgeyer,
Regarding notch filter, checked the FFT from my last flight, 9Hz seems the main freq. so i enabled the notch on 9Hz, enabled the harmonic as well. INS_HNTCH _MODE =2 as i have rpm sensor.
Is it correct ?

Yes it will feel sluggish with all of the I gain that you have programmed in there. You should drop your I gain for pitch and roll to 0.1 for now.

So something you have to understand is that you are tuning the heli to follow a command model. This command model dictates the response of the heli. so you can adjust command model parameters to make it fly with the nimbleness of a hummingbird or the sluggishness of a large transport aircraft. BUT your aircraft must possess the acceleration and response to be able to follow the command model. If you set the command model to hot, then the aircraft will never be able to keep up and this could cause problems with the attitude and position controllers. So you must adjust the command model to be within the capability of the aircraft. The parameters that adjust this are ATC_INPUT_TC and ATC_ACCEL_X_MAX. I think that Accel values of 110000 would be a little to high for a 26 lb 800 size heli. You would be good to start off with 60000 for pitch and roll. I recommend INPUT_TC of between 0.18 and 0.2. This is the time constant to achieve steady state attitude if you made a step input.
Now here is how to determine more accurately whether you have a good value for VFF. Look at your PIDR for roll and PIDP for pitch. Plot PIDX.P and PIDX.FF. You should see P term reverse as the FF signal is still climbing.


This is your flight. You can see how the P term is still climb for most of the VFF term. The P term should be reversing almost immediately.

here is a plot from the tuned 600 size heli. You can see the nice “S” shape in the P term during the spike in the FF term at time 10.531.


In this plot you can see a lot of noise. I suggest you use the harmonic notch to clean this up. It will help your controller a lot to get rid of this noise. From the vibrations I’m guessing you are running a head speed of 1800 RPM (30 hz)? You could set a BW of 5 hz and a ATT (depth) of 30 db. I would set it to attenuate the 1st, 2nd and 4th harmonics (assuming this is a 2 bladed heli).

Set it to be dynamic which I believe you would set the REF param to 1. Set the notch center freq which is the frequency when it will start following the RPM signal to 0.5 the rotor speed frequency which would be 16.6 hz if you are running your head at 2000 RPM. set the BW to 5 hz and the ATT to 30 db.

Ok - whew.

Yes, the I gains look out of scope
ATC_RAT_x_I = 0.600 currently, going to 0.100

ATC_INPUT_TC = 0.15 currently, will increase to 0.18 and see how it feels
ATC_ACCEL_x_MAX = will decrease to 60000

I remember playing with those values quite a bit, and this heli even being large is super responsive. I’ll revisit and confirm or deny. I’m tuning for sensors, not agility.

ATC_RAT_x_VFF = 0.06 currently, will increase until I see it squash the P.

Then I believe can make the general assumption that my I gain should be close to equal the new VFF? If so, that concept really needs to be in the Wiki.

Finally, I’ll get the notch filter set up, your guess on head speed is close but I’ll measure before I make the settings.

I’ll also try to get the IMAX figured out, but my notes say we decreased this value for pitch as we were seeing some oscillations in strong headwinds. It was a stab in the dark, but it worked.

Again, thanks for taking the time. Its crazy to think this heli has over 120 flight hours collecting data, but I never got back around to tuning more properly. I wonder if I am alone in that…

If you are using an ESC with the internal governor then, that should be the frequency you set in the harmonic notch. Since they hold head speed really well you can probably set the notch width (BW) to 5 hz.

Well you can turn off the command model and go out and let 'er rip. come back and see what you can get out of her. You want to leave some headroom though. Unless you got a reason to have it super agile, I don’t think you need to set it much higher than 60000 or 70000. It is still pretty responsive.

Yeah I’m still working on what makes a good tune. But I think I’m getting close.

Hmmm… IMAX just dictates how much integrator that can build in forward flight (>5m/s). IMO that should not have any bearing on oscillations in headwinds but with the large amount of I gain, I guess lowering IMAX could have help decouple the integrator from driving the oscillations if it was near the limit. Again that sounds like an issue due to not having the system properly tuned.

No problem. I’m sure you are not alone. This is not a simple flight control system. That’s why I’m working on an autotune feature.

Well… you’re not alone, it is a complex issue, and probably there are more than one set of coefficients that gets you to comfortable enough flights… I do learn all the time… and still feels that i know nothing, this forum is great and the data reveled here helps a lot.

@bnsgeyer

Thanks for your suggestions, I’ve copilled it into this:

Worked like a charm, the ANG_P gotten was at 8.35, RAT_D stayed at 0.001 did also Yaw check and updated the ANG_P from 3.8 to 8…

It is the first time i can hoover and leave the sticks … (had not calm but non gusty environment)

Here is the log, @LoopZilla, this was also done in PosHold mode, from takeoff to land
i did some step commands on all axes, and some side to side as well.
https://drive.google.com/file/d/16cTmC8lM7WfRt7NxCBFskPB008_RwSyb/view?usp=sharing

@ZvikaF The signals look very clean. So the harmonic notch did a great job at attenuating the rotor vibrations. So I looked at your flight.

First I noticed that your FLTD param for both pitch and roll is 5 hz. Now that you completely removed the rotor vibrations which you can see looking at the PIDP.D and PIDR.D signals. Set the FLTD params for pitch and roll to zero. Before you fly, zero your D gains and then go thru the process of tuning them again. I would recommend tuning pitch and roll D gains separately.
After you are finished tuning the D gains, look at the desired and actual attitudes. Hopefully the D term was much more effective in reducing the overshoots. If you are getting attitude overshoots in either pitch or roll, then drop your VFF on that axis until the overshoot is around 2 deg. I wouldn’t drop the VFF gains more than 25% from their current values.

@bnsgeyer Willco, I will take out the FLTD (I did put it in order to calm down the TBS)
and will try to refine the RAT_D and VFF gains again.

Judging by the stability of the copter in PosHold mode, it looked perfect on air.

Checked also LOITER mode for short time, seems that position and velocity tracking is fine, acceleration is a bit off, should i change coefficients dealing with the PSC ?
Following is the latest log with loiter:
https://drive.google.com/file/d/1fXesnEO0jlFUn__qWV0Agcj-yGruGPFF/view?usp=sharing

No. Let’s get your attitude loops where we want them. Then we can start working on the position controller.

@bnsgeyer,

scanned ATC_RAT_XXX_D again, on pitch found unacceptable stability at 0.0048, so changed it to 0.0024, On Roll the instability lurked at 0.002 so i left it on 0.001.
Did some hoovering with the new pitch coefficient, the heli developed quick and low amplitude TBS.
Took the pitch gain down to 0.0018.
The dampening of the attitude was slightly affected … went down from 5 to 4 deg.
Took down the VFF to about 20%, with minor effect.
The stability pitch margin is too small, the heli has pitch rocking from time to time.
I suspect the D part adds instability instead of damping fast movement, it felt better on 0.001.
here is the log of the last flight,
any suggestions ?

https://drive.google.com/file/d/1CucC9P5cAKOaBHHQU6gcnKH8VLYEfGex/view?usp=sharing

Things don’t look as good today. After looking at your plots yesterday, I didn’t bother checking your Harmonic notch settings. Looks like you forgot to turn on the dynamic notch setting. You have to set REF to 1 in order for it to follow your RPM signal. What is interesting though, on your flight yesterday the RPM was 2200 and the flight today your RPM was 1800. Are you changing your rotor speed. Once you set the harmonic notch REF to 1, it shouldn’t matter. It will follow, the RPM to set the notch. Just curious about your RPM and whether you are intentionally changing the rotor speed. I would like to keep the rotor speed constant while we are tuning and then you can change it if you like to see how the tune feels at other rotor speeds. But it is important for now to have a constant rotor speed.

Also, I noticed that you had the static notch enabled. Please disable this notch filter (INS_NOTCH_ENABLE =0)

I think your ANG_P value is too high for the pitch axis. Even though you brought down your VFF gain, there is still considerable overshoot and this hunting when there is little or no input as shown below

Therefore I think you need to bring back the ANG_P in pitch axis to 7.

If you look at the roll axis

Aside from the instability due to the D gain, it follows very nicely with small overshoots which is fine.

So it looks like the FLTD was helping after all with the instability. But I would like to tune with no D Filter at first. Cut your current D gains in half and see if this instability is still there. This is what the instability currently looks like in the Rate traces.


You can see the constant 4 hz oscillations. We want to get rid of them.

So decide on the rotor speed you are going to tune for. Make the adjustments I’ve stated above. Please only fly in stabilize mode. I know you are itching to see how this affects POSHOLD but I can’t assess the goodness of the tune in POSHOLD as the poshold controller is doing other things that cloud what I’m trying to see. When you fly in stabilize, make some sharp 20-30 deg inputs and hold them at that attitude for 2 to 3 seconds and then release the stick and recover. then make slower ramp (slowly increasing stick) inputs to 20 deg. do this in pitch axis and then in roll axis.

Thanks for your patience. It is good for me to see how a smaller 450 size heli behaves with this tuning technique.