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

G-Tune Mode (ZERO PIDs)

Postby MHefny » Mon Jun 02, 2014 8:53 pm




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.
MHefny
 
Posts: 18
Joined: Sun Jan 05, 2014 4:27 pm
Location: Cairo, Egypt

Re: G-Tune Mode (ZERO PIDs)

Postby ezio » Tue Jun 03, 2014 1:34 am

Very interesting. Looking forward for more.
User avatar
ezio
 
Posts: 827
Joined: Sun Apr 01, 2012 11:03 pm
Location: Paris

Re: G-Tune Mode (ZERO PIDs)

Postby MHefny » Tue Jun 03, 2014 1:57 am

EZ :) Thank you for your great APP
MHefny
 
Posts: 18
Joined: Sun Jan 05, 2014 4:27 pm
Location: Cairo, Egypt

Re: G-Tune Mode (ZERO PIDs)

Postby Hamburger » Wed Jun 04, 2014 8:23 am

Intersting. Can we see code please?
User avatar
Hamburger
 
Posts: 2557
Joined: Tue Mar 01, 2011 2:14 pm
Location: air

Re: G-Tune Mode (ZERO PIDs)

Postby shikra » Wed Jun 04, 2014 4:20 pm

+1 cool development
User avatar
shikra
 
Posts: 783
Joined: Wed Mar 30, 2011 7:58 pm

Re: G-Tune Mode (ZERO PIDs)

Postby Crashpilot1000 » Wed Jun 04, 2014 4:27 pm

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?
User avatar
Crashpilot1000
 
Posts: 631
Joined: Tue Apr 03, 2012 7:38 pm

Re: G-Tune Mode (ZERO PIDs)

Postby giiba » Wed Jun 04, 2014 5:21 pm

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

Looking forward to trying this out myself.
giiba
 
Posts: 23
Joined: Tue Apr 22, 2014 6:20 am

Re: G-Tune Mode (ZERO PIDs)

Postby MHefny » Wed Jun 04, 2014 10:08 pm

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.
MHefny
 
Posts: 18
Joined: Sun Jan 05, 2014 4:27 pm
Location: Cairo, Egypt

Re: G-Tune Mode (ZERO PIDs)

Postby copterrichie » Wed Jun 04, 2014 10:17 pm

That makes total sense about the loop time, it has been a pain in the .... for sometime now.
copterrichie
 
Posts: 2261
Joined: Sat Feb 19, 2011 8:30 pm

Re: G-Tune Mode (ZERO PIDs)

Postby o_lampe » Mon Jun 09, 2014 8:04 am

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?
o_lampe
 
Posts: 117
Joined: Sat Nov 02, 2013 5:09 pm

Re: G-Tune Mode (ZERO PIDs)

Postby MHefny » Mon Jun 09, 2014 4:56 pm

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.
MHefny
 
Posts: 18
Joined: Sun Jan 05, 2014 4:27 pm
Location: Cairo, Egypt

Re: G-Tune Mode (ZERO PIDs)

Postby o_lampe » Tue Jun 10, 2014 9:29 am

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.
o_lampe
 
Posts: 117
Joined: Sat Nov 02, 2013 5:09 pm

Re: G-Tune Mode (ZERO PIDs)

Postby dominicclifton » Sun Jul 06, 2014 3:30 am

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.
dominicclifton
 
Posts: 202
Joined: Tue Feb 05, 2013 10:28 pm

Re: G-Tune Mode (ZERO PIDs)

Postby ny_racer_xxx » Tue Aug 05, 2014 12:21 am

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

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

Re: G-Tune Mode (ZERO PIDs)

Postby MHefny » Thu Aug 07, 2014 2:24 pm

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 529 times
MHefny
 
Posts: 18
Joined: Sun Jan 05, 2014 4:27 pm
Location: Cairo, Egypt

Re: G-Tune Mode (ZERO PIDs)

Postby Hypermobile » Mon Aug 11, 2014 9:40 pm

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

i'll give it a try on my new quad in a while
Hypermobile
 
Posts: 94
Joined: Mon Jan 13, 2014 8:53 pm

Re: G-Tune Mode (ZERO PIDs)

Postby ny_racer_xxx » Tue Aug 12, 2014 12:02 am

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
ny_racer_xxx
 
Posts: 16
Joined: Fri Apr 18, 2014 11:10 am

Re: G-Tune Mode (ZERO PIDs)

Postby MHefny » Wed Aug 13, 2014 4:44 am

@ny_racer_xxx it should be engaged using AUX :)
MHefny
 
Posts: 18
Joined: Sun Jan 05, 2014 4:27 pm
Location: Cairo, Egypt

Re: G-Tune Mode (ZERO PIDs)

Postby mxspode » Wed Aug 13, 2014 6:14 pm

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...
mxspode
 
Posts: 1
Joined: Sat Jan 29, 2011 6:32 am

Re: G-Tune Mode (ZERO PIDs)

Postby acessford » Wed Sep 17, 2014 9:23 pm

Has anyone successfully tried this auto tune? Im having difficulty tuning a new build, and would love to try this.
acessford
 
Posts: 14
Joined: Sun Oct 13, 2013 11:18 pm

Re: G-Tune Mode (ZERO PIDs)

Postby izeman » Sun Oct 19, 2014 7:37 pm

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?
izeman
 
Posts: 57
Joined: Tue Sep 16, 2014 10:49 am

Re: G-Tune Mode (ZERO PIDs)

Postby giiba » Sun Oct 19, 2014 9:02 pm

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
AutoTuning~01.jpg
Gtune usage flowchart
giiba
 
Posts: 23
Joined: Tue Apr 22, 2014 6:20 am

Re: G-Tune Mode (ZERO PIDs)

Postby giiba » Sun Oct 19, 2014 11:33 pm

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?
giiba
 
Posts: 23
Joined: Tue Apr 22, 2014 6:20 am

Re: G-Tune Mode (ZERO PIDs)

Postby ny_racer_xxx » Mon Oct 20, 2014 1:28 am

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
ny_racer_xxx
 
Posts: 16
Joined: Fri Apr 18, 2014 11:10 am

Re: G-Tune Mode (ZERO PIDs)

Postby izeman » Mon Oct 20, 2014 4:13 pm

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 ...
izeman
 
Posts: 57
Joined: Tue Sep 16, 2014 10:49 am

Re: G-Tune Mode (ZERO PIDs)

Postby giiba » Thu Oct 23, 2014 5:13 am

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 191 times
giiba
 
Posts: 23
Joined: Tue Apr 22, 2014 6:20 am

Re: G-Tune Mode (ZERO PIDs)

Postby izeman » Thu Oct 23, 2014 8:51 am

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.
izeman
 
Posts: 57
Joined: Tue Sep 16, 2014 10:49 am


Return to Software development

Who is online

Users browsing this forum: No registered users and 1 guest

cron