Welcome to Multi-Rotor UK. Please login or sign up.

Tuesday,April 30, 2024, 00:39:30

Login with username, password and session length

Shoutbox

Gaza07:
23 Apr 2024 08:09:45
The Domain expires for the forum in 60 days, I'm not going to renew it this time unless I see any activity  :beer2:
Gaza07:
20 Apr 2024 18:02:50
Is there anyone who would like to see this forum stay open ? :shrug:
hoverfly:
17 Apr 2024 17:15:13
 :rolleyes:
Bad Raven:
26 Mar 2024 08:41:05
 :(
Andy7:
25 Mar 2024 14:49:21
An excess of work and rain.  :thumbdown:
Bad Raven:
23 Mar 2024 18:12:38
Almost a personal Blog, it would seem. LOTS of members, but NO posts.  :-/   :shrug:
Gaza07:
06 Mar 2024 16:59:49
Anyone still here  :shrug:
ched:
24 Dec 2023 11:48:48
Hope you all have a Great Christmas and a happy New Year.
Bad Raven:
20 Dec 2023 06:17:47
 ~~   :beer2: 
Gaza07:
19 Dec 2023 22:20:27
Merry Christmas All  :beer2:
Members
  • Total Members: 8,196
  • Latest: Skyflix
Stats
  • Total Posts: 201,427
  • Total Topics: 20,261
  • Online today: 21
  • Online ever: 530
  • (Tuesday,June 26, 2012, 08:34:46 )
Users Online
Users: 0
Guests: 15
Total: 15

Theme Changer





3d - Printworx

Multiwii PID tuning via Pot

Started by barneyg, Friday,November 15, 2013, 11:16:06

Previous topic - Next topic

barneyg

Splitting this off from the 2.3 thread :

you need to add into the config.h :

#define DIAL_TUNING_BG
#define POT_P AUX4
#define POT_I AUX2
#define POT_D AUX3  (choose AUX values  that match which pot you want to use)
#define POT_PID <PID Group>

where <PID Group> is one of :
PIDROLL (which will also do PIDPITCH at the same time)
PIDYAW
PIDALT
PIDPOS (P and I Terms Only)
PIDPOSR
PIDNAVR
PIDLEVEL
PIDMAG (P Term Only)

Make sure you don';t have any of the AUX';s set to activate flight modes in your EEPROM before you upload this as I';m not sure what the end effect would be  :whistling:

Attached is the patch needed.

Once you';ve Tuned each PID you will need to write the values into eeprom or else when you rebuild and re-upload for the next Set you will loose your values.  The use of something like the Andriod ezgui app is probably well advised.

Please bench test before you try to fly  :smiley:


barneyg

#1
I';ve now run through a battery tuning the pitch and roll PID';s using this patch.  It looks like it does what it says on the tin :)

I wonder about the range that is set ... it might be better with just a simple range rather than taking it from the Ziegler Nichols method 
The current Ranges are :

P = 0->18.6
I = 0->0.124
D = 0->69


I';m not quite sure how the values are saved in EEPROM though as I got distracted when I was reconnecting to do the upload of the YAW tuning option so I can';t remember exactly the process I used ... I';ll try and make better notes after I';ve tuned the YAW PID';s.

P = 5.4
I= 0.024
D = 33

Rate = 0.50

Quad spec :
450 clone
SunnySky  X2216 980kV motors
9x4.5 Carbon reinforced props
Zippy Compact 2450mah 35C
AUW about 1Kg

teslahed

I have never had my P settings higher than about 6.8 on pitch or roll and i believe those values are unusually high.

So you may not need P to go all the way up to 18.6. I suspect 10 would be more than enough to cover the required range.

I am not sure when i will get the chance to test this code as my only multiwii multirotor at the moment is the FPV hex which i dont really want or need to experiement with. I will put a normal multiwii in the next ready to fly teslaquad i build and use that to test with i think - hopefully a week or two.
One circlip short of a quadcopter.
 1 lobe short of an antenna.

benedikt

this is awesome, thanks guys!  :notworthy:
I chucked this onto my pocket quad, and the P range is waay too much, so I modified the kp calculation to I get a P range from 1.0 to 3.7:

  #if defined(POT_P)
      int ku = ((constrain(rcData[POT_P],1000,2000) -1000) << 1) >> 6 ; // * 20/640;
      int kp = ku + 8; // P range from 1.0 to 3.7
      conf.pid[POT_PID].P8 = kp;
      if (POT_PID == PIDROLL)
      conf.pid[PIDPITCH].P8 = kp;

barneyg

Yeah ... I just adapted a chunk of code that someone had developed that tuned all 3 terms P,I and D on a single Pot based on a formula so I just used the ranges from that just split out the terms into separate pots.

I';d tried his code but hadn';t liked the end result ... it cranked the D term up too fast in comparison to P for my liking - My OCD requires I have more control  ::)

benedikt

one might think PID is the cure for OCD..
oh no, it just adds to the list  :banghead:

I have further modified this to adjust gyro P and D with one pot, and acc P with a second.
Posted that over in the PQ thread on RCG.

barneyg

Quote from: benedikt on Tuesday,November 19, 2013, 09:11:32
one might think PID is the cure for OCD..
oh no, it just adds to the list  :banghead:

I have further modified this to adjust gyro P and D with one pot, and acc P with a second.
Posted that over in the PQ thread on RCG.

That link doesn';t go where you think it goes :)

jimbo385

Hiya,

Will this code work on the CRIUS AIOP v2?

I';ve got. JR PCM9x2 which doesn';t have pot but does have 2 sliders. Can I use them?

Also, there is mention of writing the PIDs back to the EEPROM via the android app, how does that work?
Does it increase the PID settings in the app?

Cheers.
F450 Clone KK2.0 General Batting around!

FPV550 KK2.0 FPV No gear on it yet!

DJI F350 Naza Lite Naza Experience

FPV 250 With RCTimer Power kit. Pocket Rocket!

Wishlist - Tarot FY680 Pro

barneyg

Quote from: jimbo385 on Saturday,December 28, 2013, 16:22:40
Hiya,

Will this code work on the CRIUS AIOP v2?

I';ve got. JR PCM9x2 which doesn';t have pot but does have 2 sliders. Can I use them?

Also, there is mention of writing the PIDs back to the EEPROM via the android app, how does that work?
Does it increase the PID settings in the app?

Cheers.

Yep this is the FC I';ve got.
I don';t see why you couldn';t use the sliders ... you just need to map them to what the FC see';s as AUX2, AUX3 and AUX4 (though obviously you can only do 2 of those with the sliders  :smiley:)

If you are using the Android app every time you adjust a pot/slider hit read in the PID section and you will see the current value ... the process I';ve been using is :


  • Upload sketch with POT tuning enabled
  • Fly and tune quad to my liking
  • On the android app going to the PID page and press "Read".
  • Save those settings to a profile in the app.
  • Uploading a new sketch with the POT tuning turned off.
  • Connect the Android App to the FC and go back to the PID page, load the profile in the app and then press "Save to EEProm"

dirtyharry

I';ve never modified the multiwii software other than the basic setup so any help appreciated on how to do this would realy help me

Is the patch loaded as a new library in arduino?

do you just cut n paste in the extra bits in the config.h , and where abouts on the page do you paste them or does it not matter ?

anything else i';ll need to do?

barneyg

The files I';ve attached are patch files if you have the right tools they will modify the code where it needs to be modified  :smiley:

But essentially the bits in the config.h file can go anywhere ... just stick them at the bottom.


  #define DIAL_TUNING_BG
  #define POT_PID PIDROLL
  #define POT_P AUX4
  #define POT_I AUX2
  #define POT_D AUX3


the bit that goes in MultiWii.cpp (this patch is against 2.3 btw) has to go in the right place.
go to line 550 in MultiWii.cpp and you should see :


         #endif
     #endif
   }


add in after that and before the next "}"


  #if defined(DIAL_TUNING_BG)

    #if defined(POT_P)
      int ku = ((constrain(rcData[POT_P],1000,2000) -1000) << 1) >> 6 ; // * 20/640;
      int kp = ku * 6 ;
      conf.pid[POT_PID].P8 = kp;
      if (POT_PID == PIDROLL)
      conf.pid[PIDPITCH].P8 = kp;
    #endif

    #if defined(POT_I)
       if (POT_PID != PIDMAG){
   ku = ((constrain(rcData[POT_I],1000,2000) -1000) << 1) >> 6 ; // * 20/640;
   kp = ku * 6 ;
   conf.pid[POT_PID].I8 = (kp << 1) / 3;
   if (POT_PID == PIDROLL)
   conf.pid[PIDPITCH].I8 = (kp << 1) / 3;
      }
    #endif

    #if defined(POT_D)
      if ((POT_PID != PIDMAG)&&(POT_PID != PIDPOS)){
   ku = ((constrain(rcData[POT_D],1000,2000) -1000) << 1) >> 6 ; // * 20/640;
   kp = ku * 6 ;
   conf.pid[POT_PID].D8 = (kp * 3) >> 3;
   if (POT_PID == PIDROLL)
   conf.pid[PIDPITCH].D8 = (kp * 3) >> 3;
      }
    #endif

  #endif


Then upload to FC.

dirtyharry

Thanks for the help but i';m stuck again

Have inserted code between the two } } sighns. and added extra bit into config.h

but when I try to verify the code it comes up with

"expected primary expression before ';<'; token and highlights the following 558  line

      conf.pid[POT_PID].P8 = kp;

my inserted code looks like this



#endif
  }
    #if defined(DIAL_TUNING_BG)

    #if defined(POT_P)
      int ku = ((constrain(rcData[POT_P],1000,2000) -1000) << 1) >> 6 ; // * 20/640;
      int kp = ku * 6 ;
      conf.pid[POT_PID].P8 = kp;
      if (POT_PID == PIDROLL)
         conf.pid[PIDPITCH].P8 = kp;
    #endif

    #if defined(POT_I)
       if (POT_PID != PIDMAG){
      ku = ((constrain(rcData[POT_I],1000,2000) -1000) << 1) >> 6 ; // * 20/640;
      kp = ku * 6 ;
      conf.pid[POT_PID].I8 = (kp << 1) / 3;
      if (POT_PID == PIDROLL)
         conf.pid[PIDPITCH].I8 = (kp << 1) / 3;
      }
    #endif

    #if defined(POT_D)
      if ((POT_PID != PIDMAG)&&(POT_PID != PIDPOS)){
      ku = ((constrain(rcData[POT_D],1000,2000) -1000) << 1) >> 6 ; // * 20/640;
      kp = ku * 6 ;
      conf.pid[POT_PID].D8 = (kp * 3) >> 3;
      if (POT_PID == PIDROLL)
         conf.pid[PIDPITCH].D8 = (kp * 3) >> 3;
      }
    #endif

  #endif
}

void setup() {

barneyg

I can';t see anything obvious and when I cut and paste what you have put in it verifies just fine for me.

Try the attached complete tree ... you will need to modify config.h to match your hardware ... this one is for my quad ... X config, Crius v1, CPPM, Bluetooth and GPS etc. - Please double check everything - I wouldn';t want you to kill your quad  :o


dirtyharry

yep that works, will hopefully be able to try it out tomorrow if the wind dies down.

thanks very much

no idea what I did wrong , think i';l have to stick with building stuff as this programming malarky is doing my noodle in.

jimbo385

F450 Clone KK2.0 General Batting around!

FPV550 KK2.0 FPV No gear on it yet!

DJI F350 Naza Lite Naza Experience

FPV 250 With RCTimer Power kit. Pocket Rocket!

Wishlist - Tarot FY680 Pro

jimbo385

This may sound l;ike a silly question but do you use the pots whilst hovering or is it advised to land, change then test?

Cheers.
F450 Clone KK2.0 General Batting around!

FPV550 KK2.0 FPV No gear on it yet!

DJI F350 Naza Lite Naza Experience

FPV 250 With RCTimer Power kit. Pocket Rocket!

Wishlist - Tarot FY680 Pro

barneyg

I use the pots while hovering as far as I can tell it is safe as it is not actually writing anything to the eeprom ...

Just don';t use the android app to write to eeprom when you are in the air ... Or even armed with the motors at idle speed ... I did that once ... It flipped and toasted a pair or props.

Writing to eeprom does weird things to the code as it is relatively slow compared to the loop time of the input and output code.

jimbo385

F450 Clone KK2.0 General Batting around!

FPV550 KK2.0 FPV No gear on it yet!

DJI F350 Naza Lite Naza Experience

FPV 250 With RCTimer Power kit. Pocket Rocket!

Wishlist - Tarot FY680 Pro