G-Tune Mode (ZERO PIDs)

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
MHefny
Posts: 18
Joined: Sun Jan 05, 2014 4:27 pm
Location: Cairo, Egypt
Contact:

G-Tune Mode (ZERO PIDs)

Post by MHefny »




This topic is about PID auto tuning algorithm that can tune your Quadcopter from PIDs ZERO as a start value.
Introduction
Adjusting PIDs is a problem for many of Quadcopter’ pilots, it would be nice to get your quadcopter to adjust PIDs for itself. I made some investigation in this area, and found many complex algorithms that are related to Adaptive PIDs, and Fuzzy Logic. Although my background is engineering but I don’t like complex math when you can make simple solutions :)
I started with multiwii version 2.3, I chose it because its code is not that complex, while it has many GUI tools and debug facilities to trace, and it has one of the largest community that can test and verify the results. Anyway I have developed a new mode that I called G_TUNE, which enables quadcopter to calculate flyable PIDs values for ACRO mode. i.e. PIDs for GYRO.
How to Use
G_Tune mode starts by resetting all Gyro' PIDs for Roll, Pitch & Yaw to Zero’s. Then pilot needs to takeoff !! yes it will take off as the algorithm will start instantly to correct errors and update PIDs parameters accordingly. Pilot should try not to make aggressive maneuvers. That is because the error in multiwii is calculated as (RC_Stick - Gyroreading) as stick position acts as rotation speed target i.e. the target rpm, so moving stick suddenly generates false errors.
The algorithm mainly works as our human eye. what you do is that if you find your quad tilt you give thrust to motor to adjust this tilt.


Caution
1- This is a test mode that I tested only on my quadcopter with Simonk ESC, 10x4.5 props and Turnigy 1100 KV. It should work on other configuration, but I have not try it myself.
2- Moving ELE & ALE sticks just before changing from G_TUNE to ACRO mode could corrupt the values, so please try to fly as stable as possible and switch to ACRO while sticks are almost released for best results.
3- Switching back from GYRO to G_Tune mode in AIR could be dangerous -however the correction is very fast and it normally works- because PIDs are reset to ZEROs in AIR.

User avatar
ezio
Posts: 827
Joined: Sun Apr 01, 2012 11:03 pm
Location: Paris
Contact:

Re: G-Tune Mode (ZERO PIDs)

Post by ezio »

Very interesting. Looking forward for more.

MHefny
Posts: 18
Joined: Sun Jan 05, 2014 4:27 pm
Location: Cairo, Egypt
Contact:

Re: G-Tune Mode (ZERO PIDs)

Post by MHefny »

EZ :) Thank you for your great APP

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: G-Tune Mode (ZERO PIDs)

Post by Hamburger »

Intersting. Can we see code please?

User avatar
shikra
Posts: 783
Joined: Wed Mar 30, 2011 7:58 pm

Re: G-Tune Mode (ZERO PIDs)

Post by shikra »

+1 cool development

User avatar
Crashpilot1000
Posts: 631
Joined: Tue Apr 03, 2012 7:38 pm

Re: G-Tune Mode (ZERO PIDs)

Post by Crashpilot1000 »

Your G-spot tuning looks to be working fine. Can you outline the working principle? Can it run all the time i.e do some inflight tuning all the time?

giiba
Posts: 23
Joined: Tue Apr 22, 2014 6:20 am

Re: G-Tune Mode (ZERO PIDs)

Post by giiba »

You're teasing us with a demo and no code!

Looking forward to trying this out myself.

MHefny
Posts: 18
Joined: Sun Jan 05, 2014 4:27 pm
Location: Cairo, Egypt
Contact:

Re: G-Tune Mode (ZERO PIDs)

Post by MHefny »

Thank you for your interest in the G_TUNE.
I am working more on the algorithm by trying it on my own firmware HefnyCopter.
It needs some tuning, as I notice some dependent on loop time.
I will publish it when it is solid on different platforms.

copterrichie
Posts: 2261
Joined: Sat Feb 19, 2011 8:30 pm

Re: G-Tune Mode (ZERO PIDs)

Post by copterrichie »

That makes total sense about the loop time, it has been a pain in the .... for sometime now.

o_lampe
Posts: 117
Joined: Sat Nov 02, 2013 5:09 pm

Re: G-Tune Mode (ZERO PIDs)

Post by o_lampe »

Wouldn't it be better to start with PIDs preset to values known to be working and start autotune from there?
Or start with 50% value?

OT-question: Do you have public access to GPS satellites in egypt?

MHefny
Posts: 18
Joined: Sun Jan 05, 2014 4:27 pm
Location: Cairo, Egypt
Contact:

Re: G-Tune Mode (ZERO PIDs)

Post by MHefny »

The idea is to start with no settings, to help ppl. that are not in interest in setting their quad to fly.

yes we do have GPS in Egypt.

o_lampe
Posts: 117
Joined: Sat Nov 02, 2013 5:09 pm

Re: G-Tune Mode (ZERO PIDs)

Post by o_lampe »

MHefny wrote:The idea is to start with no settings, to help ppl. that are not in interest in setting their quad to fly.


You are right, when your code set the values to zero.

dominicclifton
Posts: 202
Joined: Tue Feb 05, 2013 10:28 pm

Re: G-Tune Mode (ZERO PIDs)

Post by dominicclifton »

Any update on this? I think many on are are keen to see the code regardless of it's state of completion - code is never really finished anyway and can always be changed later when people get time so don't be afraid of posting it.

ny_racer_xxx
Posts: 16
Joined: Fri Apr 18, 2014 11:10 am

Re: G-Tune Mode (ZERO PIDs)

Post by ny_racer_xxx »

Looks very promising, please post a sketch when it ready to test...

CR

MHefny
Posts: 18
Joined: Sun Jan 05, 2014 4:27 pm
Location: Cairo, Egypt
Contact:

Re: G-Tune Mode (ZERO PIDs)

Post by MHefny »

Hi Guys,

Sorry I took a long time, however I believe I have made some good progress. and now I am ready to reveal the code :)



kindly access details on here http://technicaladventure.blogspot.com/2014/08/zeropid-tunes-for-multirotors-part2.html

or in DIYhttp://diydrones.com/profiles/blogs/zero-pid-tunes-for-multirotors-part-2?xg_source=msg_appr_blogpost

Regards
Attachments
Multiwii_GTune1.0.2.zip
G_Tune ... Multiwii
(155.72 KiB) Downloaded 663 times

Hypermobile
Posts: 94
Joined: Mon Jan 13, 2014 8:53 pm

Re: G-Tune Mode (ZERO PIDs)

Post by Hypermobile »

Looks Great, another great improvement on MultiWii :!: :!: :D

i'll give it a try on my new quad in a while

ny_racer_xxx
Posts: 16
Joined: Fri Apr 18, 2014 11:10 am

Re: G-Tune Mode (ZERO PIDs)

Post by ny_racer_xxx »

Thank you for posting the sketch!!!

I haven't loaded it up on my quad yet...

Does G-Tune work automatically in Acro mode, or is it set to an Aux switch?

CR

MHefny
Posts: 18
Joined: Sun Jan 05, 2014 4:27 pm
Location: Cairo, Egypt
Contact:

Re: G-Tune Mode (ZERO PIDs)

Post by MHefny »

@ny_racer_xxx it should be engaged using AUX :)

mxspode
Posts: 1
Joined: Sat Jan 29, 2011 6:32 am

Re: G-Tune Mode (ZERO PIDs)

Post by mxspode »

Nice, Mr. Miniature is at it again. ;)

I will be testing. Not that I can't adjust PID's on my own, I just don't have the patience for it.

Rob...

acessford
Posts: 14
Joined: Sun Oct 13, 2013 11:18 pm

Re: G-Tune Mode (ZERO PIDs)

Post by acessford »

Has anyone successfully tried this auto tune? Im having difficulty tuning a new build, and would love to try this.

izeman
Posts: 57
Joined: Tue Sep 16, 2014 10:49 am

Re: G-Tune Mode (ZERO PIDs)

Post by izeman »

maybe someone can help me how to use it. the instructions are VERY short ;)
once installed on my FC i set GTUNE to be activated by a switch on my remote. works so far. when i engage the switch all PIDs of ROLL, PITCH and YAW are set to zero.
the instructions doesn't say if ACRO, LEVEL or ANGLE have or have NOT to be engaged. i guess it has to be ACRO (so no other modes enabled)?!

Code: Select all

ALT I value has to be set to 0.1
LEVEL P value has to be set to 1.0
LEVEL I value can be set between 0.1 and 0.2
LEVEL D value has to be set to 10

correct so far? do i have to take off and land in ACRO mode and then re-read the value from usb or with an app by bluetooth?
then i should be able to fly with those calculated values?
problem i have: if i try to lift off the copter wants to flip immediately even with very very little throttle gain. it's very hard to fly.
any advice for me?

giiba
Posts: 23
Joined: Tue Apr 22, 2014 6:20 am

Re: G-Tune Mode (ZERO PIDs)

Post by giiba »

I dug around last night as I was having the same trouble. Mhefney doesn't explain usage in the part two post he links. I dug and found part 1 (not easy via the mobile sites):

http://technicaladventure.blogspot.ca/2 ... s.html?m=1

I haven't had time to actually test it but a little down the page there is a flowchart of how to use the mode. I think that will do it. I will report back later.
Attachments
Gtune usage flowchart
Gtune usage flowchart

giiba
Posts: 23
Joined: Tue Apr 22, 2014 6:20 am

Re: G-Tune Mode (ZERO PIDs)

Post by giiba »

So I tried this methodology just now and I didn't get positive results... Just flipping over as soon as the throttle was high enough.

Any advice on usage Mhefny?

ny_racer_xxx
Posts: 16
Joined: Fri Apr 18, 2014 11:10 am

Re: G-Tune Mode (ZERO PIDs)

Post by ny_racer_xxx »

I spent I don't know how many hours screwing with bradwii and autotune, I never did get it going....

Just an FYI, what I did finally to test it, I took a 10' A-frame ladder and ran bungee front to back, and zip ties the frame to it.... no matter what I did, it flapped around like a flounder on hot black top....

CR

izeman
Posts: 57
Joined: Tue Sep 16, 2014 10:49 am

Re: G-Tune Mode (ZERO PIDs)

Post by izeman »

good to know that it's not only me having issues :) i really appreciate ppl doing r&d and spending their time programming new stuff. but a solid HOW-TO is also a lot of work. it's not easy for a pro to know what a noob or someone not able to follow those programming steps needs to know to use the software.
so an easy step by step instructions like:

Code: Select all

install gtune software
attach battery
arm
set gtune mode and acro (nothing else activated)
fly for x minutes
land
deactivate gtune?!
re-read values ...
jadajada ...

giiba
Posts: 23
Joined: Tue Apr 22, 2014 6:20 am

Re: G-Tune Mode (ZERO PIDs)

Post by giiba »

Okay... one problem is that large chunks of the code added at the bottom of MultiWii.cpp for G-Tune is commented out. Dunno why.

Lines 1297 to 1343:

Code: Select all

#if defined (G_TUNE)
    if((f.GTUNE) && f.ARMED)
    {
        calculate_ZEROPID (axis, imu.gyroData[axis]); //error);
/*
      debug[0]= rc;
      debug[1]= abs(error) ;

      int16_t diff_P = (int16_t)(abs(error) - abs(OldError[0][i]));
      int16_t diff_I = (int16_t)(abs(error) - abs(OldError[1][i]));

      if (diff_P > 1)
      {
        if (conf.pid[axis].P8 < 100) conf.pid[axis].P8 +=1;
      }
       if (diff_P < -1)
      {
        if ( conf.pid[axis].P8 > 0)   conf.pid[axis].P8 -=1;
      }
     
      if (diff_I > 1)
      {
        if (conf.pid[axis].I8 < 100) conf.pid[axis].I8 +=1;
      }
       if (diff_I < -1)
      {
        if ( conf.pid[axis].I8 > 0)   conf.pid[axis].I8 -=1;
      }
     

      //if ((abs(rc) < 50) && (rcCommand[THROTTLE] > MINTHROTTLE + 250))
      if ((abs(error) < 50) && (rcCommand[THROTTLE] > MINTHROTTLE + 250))
      {
        AvgPID[axis].P8 = (AvgPID[axis].P8 + conf.pid[axis].P8) / 2;
        AvgPID[axis].I8 = (AvgPID[axis].I8 + conf.pid[axis].I8) / 2;
      }
       debug[2] = diff_P;
       debug[3] = conf.pid[1].P8;

     OldError[0][i] = ( 3 * OldError[0][i] + (int16_t)abs(error)) / 4;
     OldError[1][i] = ( 19 * OldError[1][i] + (int16_t)abs(error)) / 20;

*/
   }


#endif

Lines 1365 to 1406:

Code: Select all

  #if defined (G_TUNE)
 
 if((f.GTUNE) && f.ARMED)
  {
      calculate_ZEROPID (YAW,error);
/*    int16_t diff_P = (int16_t)(abs(error) - abs(OldError[0][YAW]));
      int16_t diff_I = (int16_t)(abs(error) - abs(OldError[1][YAW]));
     
      if (diff_P > 1)
      {
        if (conf.pid[YAW].P8 < 100) conf.pid[YAW].P8 +=1;
      }
       if (diff_P < -1)
      {
        if (conf.pid[YAW].P8 > 0)   conf.pid[YAW].P8 -=1;
      }


      if (diff_I > 1)
      {
        if (conf.pid[YAW].I8 < 100) conf.pid[YAW].I8 +=1;
      }
       if (diff_I < -1)
      {
        if (conf.pid[YAW].I8 > 0)   conf.pid[YAW].I8 -=1;
      }


      //if ((abs(rc) < 50) && (rcCommand[THROTTLE] > MINTHROTTLE + 250))
      if ((abs(error) < 50) && (rcCommand[THROTTLE] > MINTHROTTLE + 250))
      {
        AvgPID[YAW].P8 = (AvgPID[YAW].P8 + conf.pid[YAW].P8) / 2;
        AvgPID[YAW].I8 = (AvgPID[YAW].I8 + conf.pid[YAW].I8) / 2;
      }
     
      OldError[0][YAW] = (3 * OldError[0][YAW] + (int16_t)abs(error)) / 4;
      OldError[1][YAW] = (19 * OldError[1][YAW] + (int16_t)abs(error)) / 20;
  */
  }


  #endif


Notice the main code in both those sections is removed, leaving only the zero PID part. No wonder I get no results but crashing. I've fired up the code with the commenting removed, and it seemed to be learning, but it may be my micro quad (~14g) with fast motors (14,000 kv) is too much for the algorithm to handle. Needs more testing.




Second, I may have made sense of the flow chart. Proceed as follows:

A) ensure all special flight modes are disabled on Tx [ACRO]

1) Plug in flight battery [DISARMED, GTUNE off]
2) Switch on Gtune mode [DISARMED, GTUNE on]
3) Arm the copter [ARMED, GTUNE on]
4) Lift off slowly, avoid stick inputs
5) Eventually the copter should fly well... when done:
6) Land, turn off Gtune [ARMED, GTUNE off]
7) Disarm copter [DISARMED, GTUNE off]

However as my copter obviously doesn't like Gtune mode (looooooooooooooots of crashing to try it out) I cannot confirm this process works. Attached is a substitute MultiWii.cpp with only the commenting changed.


Good Luck!
Attachments
MultiWii.zip
(13.82 KiB) Downloaded 304 times

izeman
Posts: 57
Joined: Tue Sep 16, 2014 10:49 am

Re: G-Tune Mode (ZERO PIDs)

Post by izeman »

thanks. looking good. my code IS learning somehow. but i can't really produce results. and PIDs produced are very high (P=15+) and I~0. i will try with your code changes. i wished the author of GTUNE would pass by and give some input. i think this has great potential and it would help many noobs to find flyable settings to start off tuning.

Post Reply