Page 1 of 6

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Wed Jun 12, 2013 5:38 am
by alex.khoroshko
Ok, let me make my point clear. Drawbacks of current version:
First and IMO the main - sticks scaling change when PIDs are adjusted. Do everyone agree? All the other mini-drawbacks I find insignificant and I wouldn't start my implementation if this issue wasn't present.
2.
Theory: D = (error - previous_error)/dT

Totally agree! But in current (v2.2) code, the D term is calculated not from error, like it should, but from gyro alone. Let me cite the code to ensure proper understanding:
delta = gyroData[axis] - lastGyro[axis]; // 16 bits is ok here, the dif between 2 consecutive gyro reads is limited to 800
lastGyro[axis] = gyroData[axis];
deltaSum = delta1[axis]+delta2[axis]+delta;
delta2[axis] = delta1[axis];
delta1[axis] = delta;

DTerm = ((int32_t)deltaSum*dynD8[axis])>>5; // 32 bits is needed for calculation

I hope now it's obvious (let me focus the issue once again), that there's no rcCommand variable in D calculation at all, so D is calculated only based on gyro output and tries to dampen ANY changes of angle rates, including these induced by moving the sticks.
it should look like this:

Code: Select all

delta          = error - lastError[axis];
    lastError[axis] = error;

3. I agree, that I control alone may introduce overshoot. But combined with limiting the I value (it is already present in code! but to some unadjustable 16000 values) and presence of P and D this would be insignificant. I component really helps in extreme controls on bad quads like one of my multirotors - the P just can not be set high enough to have good control. I agree - for good systems where influence of ESCs, motors etc are far on the high frequencies this doesn't matter, but these systems fly well with almost any control - I think that main focus should be on making the bad frames fly as good.
4. I hope everyone agree, that current implementation has RATE impacts the stick scaling and that's why the control seem more sharp when RATE is increased?
Last remark. To increase the quality of control, we should provide as small error as possible. Current approach with reducing the gain doesn't look good, IMO. I don't think, that it significantly impacts anything though.

I've tested my implementation. P and I work really well, also I don't see any overshoot even without limiting I value at all. There's no obvious improvement over current version (which was obvious from the beginning), but now I'm really comfortable with swapping the battery and retuning - all the sticks scaling is still the same. D needs tweaking still. Nonlinear control didn't have a good test yet. Also, I've found plenty of scientific articles on multirotor advanced control algorithms (who could think that these are being made at all!). Trying to figure out what can be applied to ACRO mode. Most of them are on navigation, but that's another topic.

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Wed Jun 12, 2013 12:54 pm
by Phil S.
shikra wrote:MultiWii ACRO is already considered one of the best if not the best performance in acro. (when tuned).

Don´t know who considers! I usually fly CCP helicopters (not too well, but a bit of that Parkinson like 3D stuff) and agree to what Alex (Khoroshko) said. Even a 15.-$ HobbyKing copy of a KK5.5 FC performs a lot better flying acro.

I spent hours on tuning my quads using MultiWii and MegapirateNG on AIOPs and Arducopter on a APM 2.5. Ardu tuning is a lot easier by using CH6 of the radio, modifying one parameter in flight and immediately getting the response of what this parameter changes. So IMO in matters of acro flying Ardupilot (or MegapirateNG) performs a bit better than MultiWii apart from not flipping or flying loops over pitch axis. But in the end I always switched back to a cheap piezo FC on my fun copter (Gaui 500X) to get the real feeling of control. Using MW or AP or MP, there is always someone else steering my quad!

I opened a thread in this forum some weeks ago. I had (and still have) the problem that I cannot get sufficient yaw rates with MultiWii. (With MP on the same board and with an APM or a piezo FC on the same copter I can!) I hope I understood correctly what Alex said in terms of stick scaling and turning rates, but from a pilots point of view ist seems quite strange to me as well that I have to reduce Ps and Ds (permanently by lowering the values or relative to stick travel by using RATE) to increase turning rates, sacrificing stabilitiy in manuevers they obviously need it more than just hovering around. As far as yaw ist concerned it simpy just doesn´t work this way!

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Thu Jun 13, 2013 8:14 am
by scrat
Phil S. wrote:
shikra wrote:MultiWii ACRO is already considered one of the best if not the best performance in acro. (when tuned).

Don´t know who considers! I usually fly CCP helicopters (not too well, but a bit of that Parkinson like 3D stuff) and agree to what Alex (Khoroshko) said. Even a 15.-$ HobbyKing copy of a KK5.5 FC performs a lot better flying acro.

I spent hours on tuning my quads using MultiWii and MegapirateNG on AIOPs and Arducopter on a APM 2.5. Ardu tuning is a lot easier by using CH6 of the radio, modifying one parameter in flight and immediately getting the response of what this parameter changes. So IMO in matters of acro flying Ardupilot (or MegapirateNG) performs a bit better than MultiWii apart from not flipping or flying loops over pitch axis. But in the end I always switched back to a cheap piezo FC on my fun copter (Gaui 500X) to get the real feeling of control. Using MW or AP or MP, there is always someone else steering my quad!

I opened a thread in this forum some weeks ago. I had (and still have) the problem that I cannot get sufficient yaw rates with MultiWii. (With MP on the same board and with an APM or a piezo FC on the same copter I can!) I hope I understood correctly what Alex said in terms of stick scaling and turning rates, but from a pilots point of view ist seems quite strange to me as well that I have to reduce Ps and Ds (permanently by lowering the values or relative to stick travel by using RATE) to increase turning rates, sacrificing stabilitiy in manuevers they obviously need it more than just hovering around. As far as yaw ist concerned it simpy just doesn´t work this way!


Set in EEPROM.ino and you'll double stick rates--I have a lot more response now and I'm using P 7.0 I 56 and D 68 for pitch and roll. But Yaw is still very slow.

for(i=0;i<6;i++) {
lookupPitchRollRC[i] = 2* (2500+conf.rcExpo8*(i*i-25))*i*(int32_t)conf.rcRate8/2500;

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Thu Jun 13, 2013 11:57 am
by Phil S.
Response on roll and pitch is not the issue. yaw is.

With MultiWii roll and pitch always feels kind of flying in gusty winds although conditions are perfectly calm. There is not that kind of clear reaction as with KK5.5 or similar simple FCs, rolling or pitching if you steer and no movement at all when sticks are centered. You get certainly used to that MultiWii style after a while, but when you switch back to piezo you instantly know how real control feels like!

Another issue is:
I am a pilot, I do not want to dig into codes, GUI has to solve my problems!

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Fri Jun 14, 2013 11:00 am
by scrat
I have kk blackboard 5.5 and hk kk green board v2.1 and KK2.0 and I know what are you saying. But I'm telling you how to increase stick response and you will get instant response from mwii like kk boards. And I know that Yaw is an issue.

If you're just a pilot...then mwii is not for you.

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Fri Jun 14, 2013 1:35 pm
by alex.khoroshko
Guys, wait, don't panic!
Here's my firmware with totally rewritten PIDs.
Changes:
-The sticks scaling is no more affected by PID coefficients. Rates (to the right of the PIDs in GUI) now work as stick scaling. Default is zero (minor response) to 1.00 (totally insane scaling).
-D term revised (based on error now). Both D and I are CycleTime corrected. I has WindUp protection, independent from I coefficient.
-Nonlinear control is there, but commented out. Worked relatively well for my bad quad, but has very significant drawback - wrong tuning can lead to fatal oscillation when applying extreme sticks. Some really hard work should be done to make this control good and safe for everyone.
-Angle and Horizon modes use ACRO PID for control now. Their implementation became MUCH shorter. Because of that, level mode is controlled only by P coefficient (no I needed because the system is integrating by itself).
-I've changed the horizon mode, sorry. Before, it was just level mode with acro addition at extreme sticks. I changed the concept (because I have no idea, where can old horizon mode used - addition of ACRO only allows for flips, but they are better flown acro mode). Now it is done another way - it's acro, but slowly drifts toward horizontal position. This concept doesn't change any extreme piloting stuff making at the same time hovering easier. This is how I like it for FPV - I don't have to hold the stick all the way forward like in angle mode, but it's much easier to hover. The speed of drift towards horizontal position is determined by I coefficient of level mode
-All top-level modes like horizon, level, GPS etc don't change with stick scaling (they are connected to PID after scaling) so nothing needs adjusting when changing the scaling.

I changed the default values to the ones from my config. Just reset the settings and you'll see them.
WARNING! I've tested only the ACRO PID well. Level and horizon work, but I didn't test them in all possible ways. I had no chance to test the other modes at all, though they should work. Do not consider this sketch a ready to fly version! Test it, and do it very VERY carefully.

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Fri Jun 14, 2013 2:13 pm
by timecop
Here's a diff, for those who would prefer to see what was actually changed

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Fri Jun 14, 2013 2:34 pm
by alex.khoroshko
Oh wow, how did you do that? :)

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Fri Jun 14, 2013 3:46 pm
by Phil S.
scrat wrote:If you're just a pilot...then mwii is not for you.

That´s been a bit of exaggeration. Wouldn´t be to much of a problem modifying code as you described but i am not too keen on it! On the other hand it seems to me that some of the guys programming MultiWii are good in writing code but not too keen on flying!

Guys like you and Alex doing both (at higher levels) appear to be a minority group.

Alex, did you rewrite PIDs for all three axes or just for roll and pitch?

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Fri Jun 14, 2013 3:59 pm
by alex.khoroshko
All. Yaw is totally insane (very sensitive) at full rate setting. I can not guarantee that the code is safe in all aspects (more testing needed) but it would fit your needs. If you can bear some risk, it would be great if you help testing.

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Fri Jun 14, 2013 5:24 pm
by Phil S.
I will definitely try. Weather forecast ist not bad so there could be something to tell tomorrow!

Is your modification based on 2.2 final or on any dev? Which Conf resp. WinGUI version is required?

What about the problem with gyro scaling (klick) that disturbs selflevelling when you switch from acro to angle immediately after flying some flips?

Edit:
Modified my IMU as proposed by Plüschi, and this worked perfectly so far. Do you see any conflict with your code?
By the way and answering my first question, as this part of your code is identical to 2.2 final, you obviously did not work on a dev!

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Fri Jun 14, 2013 11:59 pm
by alex.khoroshko
Oh wow, it's not a release at all - just applied my ideas to see whether they are good.
What's with gyro scaling? I mean, I saw the thread, but what kind of disturbance are you talking about? If the quad is not horizontal when you turn level mode on, it moves towards stick-defined angle as fast as it can. I was unable to find any other inconsistencies in switching modes. I had no chance to try flips though, because I fly on small road near home among the power lines (that's why I couldn't test GPS as well).

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Sat Jun 15, 2013 9:34 am
by Phil S.
As I said before, Iam a user/pilot, so I can tell about setup and flying, not what particular line in the code is responsible for doing this or that.

First thing, you cannot setup MW 2.2 with MWConfig 2.1, even each dev version has its own Config or WinGUI. So as far as I understood you have too look for compatibility between firmware version and configuration software.

Second thing, when you fly lets say five, six loops in a row with 2.2, ACC looses orientation and it takes some time before it knows again what is up and down and horizontal. Switching back to angle or horizon immediately after flipping brings up unpredictable orientation of the craft, means it flips over, ends up nose down or anywhere else far from expected levelling.
My primitive understanding of the problem is that ACC has to count exactly 360 degrees for each flip to function properly, but because of this failure it counts lets say 344 or 412! Plüschis mod teached it counting correctly and from my practical point of view it does now. Did not try more than 20 or 30 flips but it is working until there.

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Sat Jun 15, 2013 10:22 am
by BarneyG
Alex ... any reason why you've changed the #define I2C_SPEED 400000L to #define I2C_SPEED 100000L for the Crius AIOP v1 definitions ?

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Sat Jun 15, 2013 11:18 am
by chris_kmn
I just came back from first flight.

My first try with the new firmware was based on my original PID and scaling settings.It was almost not flyable. Insane rates and tending to oscillating. also the horizon/level was almost not working bebause I used to fly little I - values.
So for those guy who are used to "horizon-flying" you have to have higher I values in level settings.

I'll try to adapt my settings now and do some more flights.

By the way, is there any reason why the "old" version 2.20 and not 2.21 was used ?

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Sat Jun 15, 2013 12:23 pm
by alex.khoroshko
Alex ... any reason why you've changed the #define I2C_SPEED 400000L to #define I2C_SPEED 100000L for the Crius AIOP v1 definitions ?

The reason was the I2C errors I was getting - it has gone away when I've washed the board with alcohol, but I forgot to change all back (I know, I should have to). Sorry - I didn't care much because it won't be used anywhere (except for testing here).
By the way, is there any reason why the "old" version 2.20 and not 2.21 was used ?

I've downloaded it some time ago and didn't check the latest version in the repository. There's no reason for that.
It was almost not flyable

Yes, the scaling for all coefficients changed, I tried to keep them close to the original though (except for scaling, which was IMO way too low). I changed horizon mode completely, as well as both acc-based modes have another PID organization (they don't have their own pid, they confrol ACRO pid). You can save your settings via GUI and then reset the settings to defaults. I've set default values into what was good for me (except for rates, which are set to zero), it may be the good point to start.

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Sat Jun 15, 2013 1:45 pm
by chris_kmn
could you post something like a sketch of the control loop just to understand where the parameters act in what way ? that would be great and helpful to trim.

so far you did a great job !!!

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Sat Jun 15, 2013 2:56 pm
by chris_kmn
ok, I tested it with your proposed values with a good result. With the "rate" values at 0 it is absolt controlable and it's a good base to start with. But what I might not like is the horizon performance. It is really coming back to level very slowly. So for FPV it could be an issue.

Unfortunately it's very stormy here today. But I am really astonished how stable my copter is even in strong blasts ! And mine is a lightweight of only 340 grams.

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Sat Jun 15, 2013 3:19 pm
by crazyal
alex.khoroshko wrote:Oh wow, how did you do that? :)

In case you haven't found out how to create a patch allready.
It's really easy with tortoise svn on windows: http://tortoisesvn.net/docs/release/Tor ... patch.html
I like your new pid implementation, if I manage to fix my copter I'll probably try it next week.

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Sat Jun 15, 2013 3:48 pm
by alex.khoroshko
could you post something like a sketch of the control loop

Yes, would be done! I'm in progress of drawing the full diagram including maximum variables values etc (I like well documented projects). Would post ASAP.
So for FPV it could be an issue

You can try to increase the I gain in level settings - in my implementation it controls the horizon return rate. When this coefficient is set really high it should feel more or less alike the old horizon, though unlike the old implementation, it would try to level in extreme sticks as well. I think I should fix that (centered - goes towards horizontal position with the set rate, extreme sticks - pure ACRO). The thing is - I like horizon to help just a bit, not be the level mode at sticks centered, so I didn't think it would be needed. It would be cool to make horizon mode fit everyone's vision of it by just changing the single coefficient value.
I would be glad to hear your thoughts on horizon, what in your opinion should it be.
So, current conclusion:
1. Rates are way too high? I used it at around 0.50 value (I like sharp control). I doubt someone would need it higher, so I can scale it down.
2. autolevel shut-off at extreme sticks needed (in form of mixing - the more sticks inclination, the less autolevel).
It's really easy with tortoise svn on windows

Thank you, I'm currently reading up on SVN concept (I worked as an embedded system developer, but I was the only one code writer).

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Sat Jun 15, 2013 4:19 pm
by chris_kmn
alex.khoroshko wrote:Yes, would be done! I'm in progress of drawing the full diagram including maximum variables values etc (I like well documented projects). Would post ASAP.

Thanks for your support on this !

The thing is - I like horizon to help just a bit, not be the level mode at sticks centered, so I didn't think it would be needed. It would be cool to make horizon mode fit everyone's vision of it by just changing the single coefficient value.
I would be glad to hear your thoughts on horizon, what in your opinion should it be.


I agree that it's a good way to not having too much level for nice acro flying. I also don't like to allways counteract against level with the sticks. Maybe a deadband or so could be nice to disable level when sticks are out of center. but in that case you have to hold the value of the integrator cause it would wind up and if sticks then come back to center it is just too big.

1. Rates are way too high? I used it at around 0.50 value (I like sharp control). I doubt someone would need it higher, so I can scale it down.


I think downscaling of about 20 to 50% would be good.

2. autolevel shut-off at extreme sticks needed (in form of mixing - the more sticks inclination, the less autolevel).


I think mixing could be an issue cause the integrator could wind up and work against stick input. Maybe a small deadband could be better and then higher I-values or even I and P

Again thanks a lot for that nice contribution ! :-)

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Sat Jun 15, 2013 7:11 pm
by chris_kmn
Some flights later.....

I increased the I value up to 1 and still almost no leveling in horizon mode. How high can/should I set the I value ?

Yaw is in my opinion to hard. Due to the high rev differences between the props the whole copter is getting instable. Maybe the yaw should be scaled down more than the roll/nick scaling. I used 0.4 for yaw rate and it still was very hard.

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Sat Jun 15, 2013 7:48 pm
by BarneyG
I just added this into my code along with the Gyro Scaling changes. Unfortunately I'd also removed the expo from the MultiWii config as I had that set up in my RX as well :roll: so it wasn't a direct comparison. I reset my PID's to the defaults set in the code after making a backup of my existing ones.

Being a beginner I fly in Angle mode most of the time and this test run was really no different also since I'm a beginner I'm not sure exactly how informed my observations are :). The sticks are loads more sensitive to input (that will be in part due to the removing of the double expo) but in the complete opposite to what I was worried about when I first discovered this it actually made it easier to control. Loads of wind here just now and while the quad was being blown about there wasn't much in the way of judder when it was compensating. There was also very little/no oscillation when it was descending slowly, through its own prop-wash, or rapidly.

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Sat Jun 15, 2013 10:43 pm
by Phil S.
Alex, you are a genius!

Your mod is not less than a revolution. Control is perfect, turning rates on all axes are adjustable to any level you like, yaw is now even better than with my so far favourite, the HK copy of the KK5.5. At the same time setup is easy and far from beeing critical. I started with zeroeing I and D, and a P on roll and pitch of 2,5 (controllable but no fun to fly), from around 3,0 it went acceptable, getting better and better, started to oscillate between 4,8 and 5,0, but oscillations were slight, noncritical. The copter is now literally nailed to the sticks, has not the least tendency to pitch up at high speeds. Yo can flip on the spot or fly really big loops or everything in between. Used Plüschis IMU mod as well, so activating angle mode at any time levels perfectly. Angle mode is fast, the position of the copter follows the stick movement almost instantly. Position Hold, Coming Home, Alt Hold, really good, not as good as my ArduCopter DJI F450 (using ACC in addition to baro for Alt Hold and kind of waypoints for Coming Home resp. Return To Launch), but not far from it. There are definitely no oscillations at all, even if you try to provoke it with very fast stick input. When P and D gets too high, it becomes a bit difficult to control altitude, but it needs even higher values until oscillation begins.

Attached my current setup of my Gaui 500X with a Crius AIOP V2.0. The quad has motors and ESCs right out of the box, no SimonK upgrades, cheap plastic props out of the bag, did not balance them.

You wouldn´t think it to be possible until you fly. What you managed within a few hours is IMO a giant leap for MultiWii FCs! Thank you, Alex!

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Sun Jun 16, 2013 9:32 am
by alex.khoroshko
Thanks for such a good response!
Here's a sketch of the implementation. I've also attached the PDF version (it's hard to read from image). I would try to increase the readablitity (increase font size or something).
pid alex.k11.png

but in that case you have to hold the value of the integrator cause it would wind up

There's no integrator for horizon mode - regulator just requests the angle rate proportionally to angle difference (I used "I" value because it was free. it should be renamed into "horizon P"). The system integrates by itself, because angle is integral from angle rate. As for horizon strength - coefficient of 16 corresponds to the same leveling strength, as 1 for "level" mode (they have equal implementation, only the scaling is different).
For the next version, I've made out the fix for that as well - I just squared the coefficient, so the more you increase GUI value, the faster real coefficient is increased. Should give very weak leveling at 1 (the way I like it) and really locked-in leveling at 4 (like in angle mode - the way you seem to want it to be). Would test myself and then post here (together with scaling fix (all modes) and extreme sticks mix-up for horizon).

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Sun Jun 16, 2013 9:52 am
by timecop
I added this as selectable PID controller to baseflight - set pid_contoller=1 (per-profile setting) to try out.

I gave it a brief hover and it seems to work with the PIDs posted couple posts above, though rate mode was WAY too fast, and my only flying frame (iconic-x) has yaw issues where it almost drops out like a naza when you yaw too fast (it's not related to this code, it does that in general, too).

Snap back to level was much better than what I've seen in multiwii so far.

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Sun Jun 16, 2013 10:23 am
by chris_kmn
Is there any chance to get a version based on the actual V2.21 together with this Plüschi IMU (I don't know anything about this but it seems to be helpful) ?

And then we need to find a way to get it all to an official release :-)

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Sun Jun 16, 2013 11:42 am
by BarneyG
Am I right in saying v 2.21 is in the trunk/MultiWii_shared folder in svn ?

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Sun Jun 16, 2013 11:54 am
by -ralf-
BarneyG wrote:Am I right in saying v 2.21 is in the trunk/MultiWii_shared folder in svn ?

You are right .... but don't forget to use the latest multiwiiconf.pde.

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Sun Jun 16, 2013 12:34 pm
by chris_kmn
is there any chance to get a tutorial how to work with the google.code site ?

which tools do I need for example to update all the releases up to r1474 (somebody references the r1474 changes to this thread) based on the last official release r1391 ?

update: I used SVN to download the _shared. Hope that that includes the r1474 . there is no reference in miltiwii.ino. just says 2.21. Is there already the new PID control loop integrated ?

And for what is the PDE file ?

meanwhile I updated the new gyro scale from Plüschi and it changed a lot for me. I can rise the PID values way more and now the I - value for horizon is working fine. I like the new implementation very much !

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Sun Jun 16, 2013 12:46 pm
by alex.khoroshko
Hey guys! So, what's the deal with SVN updates? How should I proceed? Take the last version and update it to my implementation, post here, if test successful commit to SVN?
Also, as multiwii aims the .c and .h files style, would anybody mind if I create separate file filters.c and move the PID (and later other filters) there? The idea is it would be possible to use one PID code for all loops in style:

Code: Select all

pPID_desc->input = var;
PID (pPID_desc);
output = pPID_desc->output;

This would save a lot of space and also increase performance (reduce processing time) a bit.

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Sun Jun 16, 2013 12:49 pm
by BarneyG
-ralf- wrote:
BarneyG wrote:Am I right in saying v 2.21 is in the trunk/MultiWii_shared folder in svn ?

You are right .... but don't forget to use the latest multiwiiconf.pde.



In which case the IMU fix is already in place in the current _shared directory :)
Edit and I'm also very confused ... there is an awful lot of changes for a 2.2 -> 2.21 style release :) this looks more like the current dev release of 2.3 ?

and another edit :

r1474
- based on some ideas from this thread:
viewtopic.php?f=8&t=3671
- the sticks scaling is no more affected by PID coefficients
- yaw rate (to the right of the PIDs in GUI) now works as stick scaling
- default yaw rate is increased (with yaw rate at 0)
- yaw PID principle is now different from PITCH&ROLL PID:
- yaw ITerm windup is very high, allowing an 'elastic' direction return after a
manual perturbation
- yaw ITerm is also constrained with a windup independent limit
- yaw PTerm is constrained in order to counter the yaw jump effect (maybe to
refine)
- yaw ITerm is canceled if the yaw stick is not centered
Today (14 hours ago)
dubusal

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Sun Jun 16, 2013 2:11 pm
by Alexinparis
Hi,

There are a lot of aspects in this thread.

So let's try to isolate things.

1) PITCH/ROLL acro PID update:
- PID coef must not have impact on stick scalling, OK
- cycleTime should be included in I and D Term computation. Does it really have a noticeable effect on flight performance ? For sure it has a noticeable effect on computation time.
- D component doesn't take into account stick position at all. Again, from wiki link: “In most commercial control systems, derivative action is based on PV rather than error.”. Does it really have a noticeable effect on flight performance to take error rather than PV in the equation ?
- 32bit implementation for I term: Does it really have a noticeable effect on flight performance ?

2) YAW PID update:
I think 32bit Ierror term is interresting not to gain more accuracy (from a flight performance point of view), but to gain more windup.
Is there any other approach to counter the yaw jump effect ?

3) ANGLE/HORIZON mode update
I think Horizon mode (relativly new) have good feedback so far, but why not update it
If feedbacks on it are better.

4) wrong MPU scale:
it was reported by ovaltineo
viewtopic.php?f=8&t=3480
and is corrected in _shared
It affects mainly angle calculation after many flips. Nothing to do with PID.

5) versions:
There is no 2.21 version.
The last official version is 2.2.
All other variant after are just dev version for testing purpose based on _shared repository.
And sometimes I create a zip of intermediate dev versions

6) the deal with SVN update
There are few committers that can update it, based on what they think useful.
The best way to suggest evolution is what you did: explain the mod in the forum, share a zip code and get feedbacks.

7) why so many compromises on the code ?
Because it's always a challenge to keep computation time and code size low. More than a challenge, it's also for me a fun way of coding.
I understand it could be disturbing from a theory or coder point of view.

which tools do I need for example to update all the releases up to r1474

You only need to get the last r1474 files.


Snap back to level was much better than what I've seen in multiwii so far.

Did you try to increase LEVEL P with the stock code ?

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Sun Jun 16, 2013 2:50 pm
by alex.khoroshko
- cycleTime should be included in I and D Term computation. Does it really have a noticeable effect on flight performance ?

I component: flight - no. Tune performance - well, it should be. I would try to compile the code with and without loads of functions to see, whether I meaning change when it is not time corrected. Then it would be clear, whether correction needed or not. Also, D correction is needed IMO - it feels a bit better with it, it may be placebo effect though. But it looks logical, that if dt is very different every time, D response would not be consistent.
Does it really have a noticeable effect on flight performance to take error rather than PV in the equation

Yes, at least I feel the difference. When the stick is moved rapidly it creates something like short impulse. Too high D lead to overshoot though.
- 32bit implementation for I term: Does it really have a noticeable effect on flight performance ?
Not quite sure, quite possible that no. Should be carefully tested.
YAW PID update:
I think 32bit Ierror term is interresting not to gain more accuracy (from a flight performance point of view), but to gain more windup.
Is there any other approach to counter the yaw jump effect ?

There is a limiting, which prevents from wind up. Jump effect needs fixing, I agree. Harder limiting would help (just reduce the limits separately from roll and pitch)
ANGLE/HORIZON mode update

It would work the same as old one when coefficient is set high. With low coefficient it would slowly drift towards horizontal position (how me, and, I think, some other FPVers like)
Did you try to increase LEVEL P with the stock code ?

My little comment - original code does pretty much the same as mine, except that it is now clearly arranged as one control loop inside another, internal is already fine-tuned for acro mode, external is easily tuned with single coefficient. Also, gyro-based correction was initally P-controlled only with this line:

Code: Select all

 PTerm -= ((int32_t)gyroData[axis]*dynP8[axis])>>6; 

New code in repository does the same. My version's internal loop is full PID regulator, that's why additional I for level mode is not needed.

And, what do you think about moving filters to separate file? I'm sure that it would decrease image size at least, but is it compatible with multiwii overall coding style?

P.S. I see where to save A LOT in terms of performance. The I2C transfers should be made asynchronous (interrupt driven). This would allow process I2C transfer in background while at the same time processing the main loop. Drawbacks - increased jitter for software PWM and a little increased code size. I would try and then create separate thread if it would be good.

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Mon Jun 17, 2013 3:07 am
by Plüschi
alex.khoroshko wrote:I would be glad to hear your thoughts on horizon, what in your opinion should it be.


I would like it as you say "centered - goes towards horizontal position with the set rate, extreme sticks - pure ACRO".
Horizon as it is now allows more inclination than angle but doesent allow flips.

One thing i dont understand is running the loop as fast as i goes. My version uses a fix 3.666ms loop time, and i cant feel any difference to the jittering 2.9ms loop time the default code uses. Considering the reaction time of ESC and motors is more in the 100ms range what does 2ms loop time buy?

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Mon Jun 17, 2013 8:21 am
by scrat
Phil S. wrote:
scrat wrote:If you're just a pilot...then mwii is not for you.

That´s been a bit of exaggeration. Wouldn´t be to much of a problem modifying code as you described but i am not too keen on it! On the other hand it seems to me that some of the guys programming MultiWii are good in writing code but not too keen on flying!

Guys like you and Alex doing both (at higher levels) appear to be a minority group.

Alex, did you rewrite PIDs for all three axes or just for roll and pitch?


Sorry for my exaggeration. It wasn't meant like that. Sorry again.

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Mon Jun 17, 2013 8:34 am
by scrat
BarneyG wrote:Alex ... any reason why you've changed the #define I2C_SPEED 400000L to #define I2C_SPEED 100000L for the Crius AIOP v1 definitions ?


Did you know if you have Crius AIOP v1, V1.1 or v2 you can have I2C speed commented out. I have it like that and don't have I2C errors anymore.

/********************************** I2C speed ************************************/
//#define I2C_SPEED 100000L //100kHz normal mode, this value must be used for a genuine WMP
//#define I2C_SPEED 400000L //400kHz fast mode, it works only with some WMP clones

Because there is in def.h file for AIOP vX already defined:

#if defined(CRIUS_AIO_PRO_V1)
#define MPU6050
#define HMC5883
#define MS561101BA
#define ACC_ORIENTATION(X, Y, Z) {accADC[ROLL] = -X; accADC[PITCH] = -Y; accADC[YAW] = Z;}
#define GYRO_ORIENTATION(X, Y, Z) {gyroADC[ROLL] = Y; gyroADC[PITCH] = -X; gyroADC[YAW] = -Z;}
#define MAG_ORIENTATION(X, Y, Z) {magADC[ROLL] = X; magADC[PITCH] = Y; magADC[YAW] = -Z;}
#define MPU6050_I2C_AUX_MASTER // MAG connected to the AUX I2C bus of MPU6050
#undef INTERNAL_I2C_PULLUPS
#define I2C_SPEED 400000L //400kHz fast mode

Posted: Mon Jun 17, 2013 9:11 am
by BarneyG
I've got a v2 ... The reason I asked is that it is the line you bolded has been changed to 100000 in Alex's code :)

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Mon Jun 17, 2013 10:05 am
by Phil S.
scrat wrote:Sorry for my exaggeration. It wasn't meant like that. Sorry again.

"Exaggeration" was pointed at my statement beeing just a pilot not at yours! Wanted to state that I am interested in a bit more than just banging sticks. No need to apologize, I´m not huffy at all!

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Mon Jun 17, 2013 11:15 am
by Hamburger
Plüschi wrote:Horizon as it is now allows more inclination than angle but doesent allow flips.

Plain wrong. I do it all the time.

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Mon Jun 17, 2013 11:55 am
by Plüschi
Hamburger wrote:Plain wrong. I do it all the time.


Why does mine not flip in horizon, but does in angle with acrotrainer enabled ?

Re:

Posted: Mon Jun 17, 2013 1:43 pm
by scrat
BarneyG wrote:I've got a v2 ... The reason I asked is that it is the line you bolded has been changed to 100000 in Alex's code :)


I know. I have both commented out because in file def.h there is already defined. This apply for v2 too.

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Mon Jun 17, 2013 6:29 pm
by crashlander
Plüschi wrote:
Hamburger wrote:Plain wrong. I do it all the time.


Why does mine not flip in horizon, but does in angle with acrotrainer enabled ?


What are your PID's, pitch roll RATE and RC RATE? I found it difficult to flip it even in ACRO mode until I upped both RATE's (I'm flying wii-esc flashed ESC and gyro PID's P around 8)!

Regards
Andrej

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Mon Jun 17, 2013 6:49 pm
by shikra
Cool developments in places.

Crashlander -
Low D helps with fast flips as well as rates. In standard implementation

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Mon Jun 17, 2013 10:49 pm
by brm
alex.khoroshko wrote:Thanks for such a good response!
Here's a sketch of the implementation. I've also attached the PDF version (it's hard to read from image). I would try to increase the readablitity (increase font size or something).
pid alex.k11.png

but in that case you have to hold the value of the integrator cause it would wind up

There's no integrator for horizon mode - regulator just requests the angle rate proportionally to angle difference (I used "I" value because it was free. it should be renamed into "horizon P"). The system integrates by itself, because angle is integral from angle rate. As for horizon strength - coefficient of 16 corresponds to the same leveling strength, as 1 for "level" mode (they have equal implementation, only the scaling is different).
For the next version, I've made out the fix for that as well - I just squared the coefficient, so the more you increase GUI value, the faster real coefficient is increased. Should give very weak leveling at 1 (the way I like it) and really locked-in leveling at 4 (like in angle mode - the way you seem to want it to be). Would test myself and then post here (together with scaling fix (all modes) and extreme sticks mix-up for horizon).

looking at the code is always problematik.
in essence you are cascading two control loops.
instead of naming it 'tmp' name it desiredRate. this rate is scaled according to mode you are flying.
separating the two loops could lead to code which is more understandable.

on the d-term it is not so simple.
i don't like averaging buffers.
a pt1 element is more predictable.
doing not so the changes on the dterm can saturate your esc.
also the d-term can be calculated on the state or the error.
both have different flightbehaviours.
in general i like the cascaded approach and the error on the d-term.

to prove what you said you need a vicon-system to verify your point of view.
also looking only at the loop/cycletime is wrong - you need the whole feedback loop.
your command has to come through.

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Mon Jun 17, 2013 11:56 pm
by Mis
Did you know if you have Crius AIOP v1, V1.1 or v2 you can have I2C speed commented out. I have it like that and don't have I2C errors anymore.

Do you know, that "#define I2C_SPEED" definition have no effect in most cases because "sensors.ino" have own I2C speed definitions for every sensors ?
BTW this is waste flash, CPU time ect, and cause that I2C work in most cases with 400kHz, even if you declarate "#define I2C_SPEED 100000".
The "#define I2C_SPEED" definition is only usable with old WMP and nunchuk sensors.

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Mon Jun 17, 2013 11:59 pm
by copterrichie
Mis wrote:Do you know, that "#define I2C_SPEED" definition have no effect in most cases because "sensors.ino" have own I2C speed definitions for every sensors ?
BTW this is waste flash, CPU time ect, and cause that I2C work in most cases with 400kHz, even if you declarate "#define I2C_SPEED 100000".
The "#define I2C_SPEED" definition is only usable with old WMP and nunchuk sensors.


there is ALLOT of optimizing that can be done. Seriously.

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Tue Jun 18, 2013 9:45 am
by scrat
Mis wrote:
Did you know if you have Crius AIOP v1, V1.1 or v2 you can have I2C speed commented out. I have it like that and don't have I2C errors anymore.

Do you know, that "#define I2C_SPEED" definition have no effect in most cases because "sensors.ino" have own I2C speed definitions for every sensors ?
BTW this is waste flash, CPU time ect, and cause that I2C work in most cases with 400kHz, even if you declarate "#define I2C_SPEED 100000".
The "#define I2C_SPEED" definition is only usable with old WMP and nunchuk sensors.


No I didn't know that. Thanks for info Mis.

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Wed Jun 19, 2013 11:12 am
by felixrising
Just took this process loop implementation on baseflight/stm32 for a test flight, very nice! Great work alex.k!!! The values posted here by Phil.S are great, though I added a little more RC Expo.. I'll maiden it on one of my Crius AIO Pros on the weekend...

Re: V2.2 - ACRO PID implementation is wrong, right?

Posted: Wed Jun 19, 2013 11:30 am
by felixrising
Alex.k... I hear you like documentation... please ask Hamburger or Alexinparis for a wiki ID and do your worst... :D