Current status of GPS & I2C GPS board on 328p

Post Reply
edsimmons3
Posts: 100
Joined: Thu Sep 10, 2015 11:29 am

Current status of GPS & I2C GPS board on 328p

Post by edsimmons3 »

Hi all,

I have been told that the I2C GPS board isn't recommended with multiwii 2.4 and been given no reason... I'm making sure it's possible!

I have set up Multiwii 2.4 with the I2C GPS board and bluetooth (also works with my OSD with bluetooth removed) and found that initially I was very short of RAM on the main 328... not really a surprise but it's so marginal it should be doable. I frequently run microcontrollers right up to the limits of the ram quite safely.

I found some code posted by EOSBandi that worked out the amount of free ram and I added this to my firmware and did some testing.

With the following enabled in config.h I had issues with running out of memory, the FC was glitchy and reset when conditional code ran (for example it was stable with the TX switched off and would crash when turning on the TX):

Code: Select all

#define QUADX
#define HK_MultiWii_SE_V2
#define FAILSAFE
#define DEADBAND 10
#define I2C_GPS
#define VBAT
#define POWERMETER_HARD
#define SUPPRESS_DEFAULTS_FROM_GUI
#define PSENSOR_SMOOTH 16   // the next three are default settings for averaging filter array lengths
#define VBAT_SMOOTH 16
#define RSSI_SMOOTH 16


When I reduced the size of the arrays used for averaging battery voltage and current values I was then able to get a sensible reading for the available ram and the controller didn't reset any more. With the following defined, around 5 bytes was free and the controller seemed ok. This wasn't what I would consider a safe margin, though.

Code: Select all

#define PSENSOR_SMOOTH 8
#define VBAT_SMOOTH 8
#define RSSI_SMOOTH 8


With the following defined I had around 60 bytes of free ram running the controller with a GPS fix, radio on and testing stick input, enabling GPS hold and RTH all seems fine. I left this running for quite a long time with a decent GPS fix. This change effectively disables all averaging of the Vbat and current values.

Code: Select all

#define PSENSOR_SMOOTH 1
#define VBAT_SMOOTH 1
#define RSSI_SMOOTH 1


My first scan through the GPS code didn't reveal anything that consumes a lot of memory that I didn't make use of in my ground testing... I think I'm good to go.

I think that free ram monitoring is a very important thing for this multirotor boards (it would have instantly stopped me from flying if I could have seen I had no free ram) and it would cut down on the number of crashes caused by people (who like me, want to get a lot on a small FC). It would be nice if this was a permanent fixture, it hardly costs any code space, ram or really impacts on cycle time as far as I can tell...

edsimmons3
Posts: 100
Joined: Thu Sep 10, 2015 11:29 am

Re: Current status of GPS & I2C GPS board on 328p

Post by edsimmons3 »

I have now flown for about 30-40 minutes using my newly compiled firmware...

First impressions were that it felt much smoother than before and nothing unexpected happened at all (:D, huge relief). I mostly ran down 4x 5500mAh 3s Lipo packs in testing and PID tweaking yesterday.

I think I can conclude that MW2.4 + I2C nav board is possible to get working well with some care and attention to the free ram...

With a little more testing today I realised it's also possible to enable headfree mode without costing much more ram usage. More bench testing showed this is fine for long periods with GPS modes and Headfree enabled... :)

Ciki
Posts: 19
Joined: Mon Sep 14, 2015 7:59 pm

Re: Current status of GPS & I2C GPS board on 328p

Post by Ciki »

Hi! I've a multiwii se v2.5 with multiwii 2.4 code mounted on a quad x. Two weeks ago i bought a Crius gps v3.1 with i2c gps nav board. It works well but my flight controller went crazy two times. I was flying well and i lost the possibility to use the throttle and the motors started to make classic noise of high pid (as they were changing their speed quickly).Even if i put the gas to zero they didn't stop (i could use only pitch rudder and roll but the quad was very unstable)!!! So i made a safe crash with no problem to my quad. I haven't had any problem before mounting gps and i would try to reload the mw firmware without that line code in order to understand if the problem is the quantity of memory . When you talk about instability and crash, which problems did you find?

edsimmons3
Posts: 100
Joined: Thu Sep 10, 2015 11:29 am

Re: Current status of GPS & I2C GPS board on 328p

Post by edsimmons3 »

My quad's GPS home was activated (EZgui told me) while flying and the copter turned to face me (classic RTH behaviour) without any input from me...

I also felt like I had pretty much lost control and the only option was to have 'a safe crash' as you said. :-/

If the atmega is running out of ram to cause this behaviour, basically anything could happen! The corrupted memory could change important values in ram such as PID values, the flags that enable the flight modes etc. This is why it is essential to keep track of the memory used. I have seen random resets of the atmega and other weird behaviour when they run out of memory...

edsimmons3
Posts: 100
Joined: Thu Sep 10, 2015 11:29 am

Re: Current status of GPS & I2C GPS board on 328p

Post by edsimmons3 »

Is it a bit of a discrepancy that the I2C nav board firmware begins to flash the LED 3x for a 3D fix when there are 5 or more satellites in the GPS fix, whereas the MultiWii firmware does some things only when there are 6 or more?

Ciki
Posts: 19
Joined: Mon Sep 14, 2015 7:59 pm

Re: Current status of GPS & I2C GPS board on 328p

Post by Ciki »

I'm agree with you. Four satellites are minimum number for a 3d fix and five ones (or more) give a better positioning. I think that i2c nav board flashes 3 times only to say that 3d fix is reached but Multiwii wants 6 satellites (and enables some things) in order to start working with GPS from a very precise position. As with 5 satellites these features are disabled, what happens if it losts one passing from 6 to 5, for example, during RTH? 3d fix isn't compromised so it could governing quad without problem.

edsimmons3
Posts: 100
Joined: Thu Sep 10, 2015 11:29 am

Re: Current status of GPS & I2C GPS board on 328p

Post by edsimmons3 »

When the number of satellites used in GPS fix is below 6 some features disable temporarily while the fix isn't good enough.

I have been testing this on the bench and I've seen that as long as it arms with a good GPS fix the home location is valid. RTH and poshold modes work all the time they are enabled and the fix is good enough.

Even the RTH failsafe fork works nicely in bench tests with the GPS fix dropping out.

I'd prefer it if the I2C Nav board LED indicated GPS is good to go for multiwii, rather than 5 satellites. I have just exported the firmware for the nav board to my github account, I'll work on this in my fork and see if I can get it merged into something official. Since google code is closing I'm not sure where the official version will be for commit access in future.

FightingFlight
Posts: 16
Joined: Sun Jun 07, 2015 9:04 am

Re: Current status of GPS & I2C GPS board on 328p

Post by FightingFlight »

So I've got the i2c gps to work but having problems with position hold, it goes in circles, wobbles and crashes sometimes. Trying to play around with the PIDs.

Found there is a lead filter (enabled) and gps filter (disabled) option in multiwii and in the i2c gps code too (both enabled), which one do I need to change? I would have thought the i2c gps board was just relaying the nmea/ublox sentences to multiwii but it might be doing more. There is also PIDs to change too in i2c gps, do I need to look into those too? I can see changes I make to multwii PIDs do seem to change it a bit. I'm using NMEA at the moment (i think), couldn't get ublox working a few weeks back.

edsimmons3
Posts: 100
Joined: Thu Sep 10, 2015 11:29 am

Re: Current status of GPS & I2C GPS board on 328p

Post by edsimmons3 »

You only need to adjust the PIDs in Multiwii, the I2C nav board stuff doesn't have any effect in 2.4 multiwii (don't know about previous versions)...

Please ensure your heading isn't deviating when you arm the motors and apply some throttle... this will cause circling in pos hold. Check this with props on (carefully!!) to see what happens to the heading. It shouldn't change at all when you arm the motors or apply throttle if it does you need to increase the distance between the flight controller and the power wiring. Alternatively, get a mumetal sheet in between the power wiring and the flight controller, as close to the power wiring as possible. (We are about to have some for sale if you need it...)

If your compass isn't giving bad readings, adjust the PosR PID: if it circles or swings, decrease P or increase D.

I hope that helps...

Ed

FightingFlight
Posts: 16
Joined: Sun Jun 07, 2015 9:04 am

Re: Current status of GPS & I2C GPS board on 328p

Post by FightingFlight »

Thanks Ed,the heading didn't change by much, 1-2 degrees but the mag r/p/y does change a little (jumps by 10-30 very quickly) when revving the motors. I checked the heading briefly whilst in the air and it didn't deviate by much. I ended up decreasing the P in PosR/NavR to 1.4 and D to 0.01, it's more stable now but still makes circles. I get 8 to 10 satellites.

It might be that in level mode, it can drift a bit which might cause these circles, never got level mode working 100% which might just be because of the way I fly (I like making large changes to the stick positions so turned level PIDs down to suit this, thinking about maybe putting level PIDs back up and change RC rate instead to be very low).

For the moment I've given up on GPS functionality, wonder if RTH would also be affected, since it's going in a certain direction it might be better.

edsimmons3
Posts: 100
Joined: Thu Sep 10, 2015 11:29 am

Re: Current status of GPS & I2C GPS board on 328p

Post by edsimmons3 »

What are your stick RC and expo settings? The defaults for these (set by the Multiwii processing GUI) feel really twitchy away from the mid-stick position and i turned mine down quite a bit. Flight was much better....

Once I had the stick rates being kinder, it was much easier to get the feel for tuning level mode. With the default level PID settings, my large quad would push into the wind much too much, the pitch/roll and level Integral settings were too high for my needs and I would end up having to pull the stick 'with the wind' to fight the PIDs after a minute or two of flight in reasonable wind. Getting these sorted out before trying the GPS modes seems like a good plan.

The wind will push the quad around in level mode, but it should be *level*!

Once level is working nicely, the GPS hold mode should be easier to tune since you don't have a fight occurring between the various PIDs.

I find that Pos Rate D being too high (for a given craft) gives oscillations in pitch and roll when GPS hold is enabled. Pos Rate Integral being too high is likely to cause the circling...

Hope that helps...

Ed

FightingFlight
Posts: 16
Joined: Sun Jun 07, 2015 9:04 am

Re: Current status of GPS & I2C GPS board on 328p

Post by FightingFlight »

The RC rate is 0.75 and 0.65 expo, I've also tried bumping up the level P and I while decreasing RC rate to 0.2 and it makes level a bit better but can crash a bit. My test is if I move the right stick 50-75% to the right and let go to see what happens, this is my worst case scenario because I fly with my thumbs and can sometimes push the sticks all the way.

Also I found that my compass was 90 degrees wrong, I had mounted it the wrong way, only found out when playing with miniosd that the RTH arrow was usually 90 degrees off then compared to a compass and found out. Tried the GPS hold again just in the backyard but I couldn't see much improvement so far, I'll put everything back to defaults and start fresh and might try LPF filtering too.

Edit: I've put the defaults back with 42Hz LPF and it seems level is better than my previous one, it used to drift a bit, it still does but no where as bad, I don't mind the quick twitch when moving and seems like rates are good like I had before, so defaults working good so far, just as long as I don't let go of the sticks it should be good to use.

Tried GPS hold again, with the default settings it falls straight away and when I do get it to work, it holds the position for 3-4 seconds, then drifts 2-3m and falls again. If I manually force it out from the hold position, it will fall too. I have to reduce Posr/NavR P to 0, I to 0, D to 0.01 and then it doesn't fall when it drifts but sometimes drifts too much I have to correct it, so something doesn't seem right. If I increase PosR D to 0.02 then it falls, increasing P to 1 makes it fall too. Might try re-calibrating the mag a few times.

Edit 2: Tried again, had to set Pos P to 1, PosR to 1 and everything else 0, it sort of keeps a small circle 2-3m for 10 seconds and I can see it making corrections but then it starts to drift out more and that's when I intervene.

edsimmons3
Posts: 100
Joined: Thu Sep 10, 2015 11:29 am

Re: Current status of GPS & I2C GPS board on 328p

Post by edsimmons3 »

Have you properly shielded the baro from light and wind?

Is your altitude hold working and the PID tuned for your quad?

GPS hold is 2D position hold and is tuned by the two PIDs PosR and NavR. If the quad is falling when you are trying to use position hold, can you tune just the altitude hold on it's own so that it works well enough to fly around a bit without changing height...? After this step you should have more success with position hold...

After your edit 2 info... just keep trying it and gradually increasing the PosR and NavR P until a) it holds well when steady and b) it recovers well to the hold location if it gets blown a couple of meters or more away... NavR controls the recovery and navigation to a point, PosR tries to hold it there when the distance error is small - because of this you will find you probably need a larger P value for NavR than PosR. You do need quite a lot of space to tune these PID settings!

Ed

elaerico
Posts: 7
Joined: Sun May 18, 2014 6:45 pm

Re: Current status of GPS & I2C GPS board on 328p

Post by elaerico »

Hi edsimmons3. Can you please share with me your MultiWii2.4 and I2C GPS code?
Thanks a lot!

Post Reply