GPS integration

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
Fritz
Posts: 11
Joined: Fri Mar 16, 2012 8:48 am
Location: Germany

Re: GPS integration

Post by Fritz »

Hello,

what needs to be set in the GPS?

115200bps
10Hz

and GGA, GSA, VTG ...??

Greetings Fritz

Aclosed someone has of you as a circuit diagram of the GPS module? I think it does not fit with me.

User avatar
kos
Posts: 286
Joined: Thu Feb 16, 2012 4:51 am
Location: Fr

Re: GPS integration

Post by kos »

Fritz wrote:
Bledi wrote:you have I2C errors ! your I2C link with the I2C GPS is not working.
One reason is perhaps your I2C speed. If it's not 400Hz you need to change the speed in the file twi.h to

Code: Select all

#ifndef TWI_FREQ
  #define TWI_FREQ 100000L
  #endif




Fritz wrote: and GGA, GSA, VTG ...??



Aclosed someone has of you as a circuit diagram of the GPS module? I think it does not fit with me.


your seeting are ok , VTG is not required , and i think you swapped the i2c pin , connect A4 -> A4 and connect A5 -> A5

Fritz
Posts: 11
Joined: Fri Mar 16, 2012 8:48 am
Location: Germany

Re: GPS integration

Post by Fritz »

I have asked the manufacturer of the GPS module after a firmware with the preset data, he asked me what I would have set these values​​. Now I know not whether GGA, GSA, VTG.

What am I supposed to be set?

When I connect the module to change the mistakes of the i2c nothing. The Mag is bouncing around in 5000 and the ACC as well. After a short time then it freezes. The Multiwii shows me that they would have 15 satellites, but when I look parallel to the GPS module, it has no satellite.

in twi.h I switched to 400000.

I'm doing now for several days around it: (

Greetings Fritz

karsten j.
Posts: 16
Joined: Mon Mar 05, 2012 7:22 am

Re: GPS integration

Post by karsten j. »

Hi

Now I have setup the I2C-GPS and everything is working fine in the GUI (Satfix, all Sensors... everything how it should be)
I have the Flyduino GPS (FMP04)
First flight outside with the 2.0pre3 : Very stable
ok, I got Satfix and 9 satelites..
I walked with the copter approx. 30meters from the start point and activated GPS HOME
BUT NOTHING !!!
The copter reamains more or less at my current point..
What could be the reason for this behaviour ?

cheers
Karsten

User avatar
jevermeister
Posts: 708
Joined: Wed Jul 20, 2011 8:56 am
Contact:

Re: GPS integration

Post by jevermeister »

Karsten,did you calibrate the mag?What is the distance(Use laptop and walk around- i did that).
Is the function properly bound to aux?
Nilsg

Fritz
Posts: 11
Joined: Fri Mar 16, 2012 8:48 am
Location: Germany

Re: GPS integration

Post by Fritz »

Ok, if you look at the code closely at times, then you can also see what NMEA protocol is used ;)

NMEA GGA, GSA and RMC

Greetings Fritz

MicroRaptor
Posts: 20
Joined: Tue Mar 20, 2012 1:56 am

Re: GPS integration

Post by MicroRaptor »

Greetings to all,

I'd like to share my experience with a quad x I built. It has:, C2822, 8x4's, 480mm motor circle dia. WMP, orig nunchuck, BMP085, HMC5883. I2C gps with GTPA010 @115200, 10Hz.

I made the following modification to I2C nav code so the RTH arrow points home :

from :
float dLat = ((lat2 - lat1)); // difference of latitude in 1/100000 degrees

to:
float dLat = ((lat1 - lat2)); // difference of latitude in 1/100000 degrees

Initial test flights showed the quad would approach the home position but at a skewed direction going to the right (of the home position). Once near the home position, the Quad would begin a counter clockwise flight path around the home position with varying diameter of 15Mtrs to 50Mtrs. The stronger the wind, the larger the diameter, so much so I have to intervene with the controls. During that test flight MW2pre2 was loaded. Mag is calibrated before every flight.

I suspect Magnetic declination might be affecting the flight path and inserted the following to multiwii.ino, now MW2pre4:
from: float radDiff = (GPS_dir-heading ) * 0.0174533f;
to: float radDiff = (GPS_dir-heading + 14) * 0.0174533f; where 14 is the magnetic declination of my area .

Flight test in no wind very improved holding performance, the quad appears to be loitering within a 5Mtrs diameter area around the Home position. I've yet to test RTH in a larger area.

Every comment is welcome.

Judd

ps: Thank you Alex and everyone here who have made Multiwii.

nhadrian
Posts: 421
Joined: Tue Oct 25, 2011 9:25 am

Re: GPS integration

Post by nhadrian »

MicroRaptor wrote:from :
float dLat = ((lat2 - lat1)); // difference of latitude in 1/100000 degrees

to:
float dLat = ((lat1 - lat2)); // difference of latitude in 1/100000 degrees


Thanks for confirming my idea on swapping lat1 and lat2!
But, I think you also changed the dLon calculation, and in main multiwii.ini the sign of errorangle calculation GPS part?

BR
Adrian

MicroRaptor
Posts: 20
Joined: Tue Mar 20, 2012 1:56 am

Re: GPS integration

Post by MicroRaptor »

Hello,

I did not swap dlon or change the sign in the errorangle calculation. I figured that the GPS reading/orientation is different from northern and southern hemisphere and whether you are west or east of Lat 0 (or GMT). I think the stock GPS code works if your in Australia. I also realized when I was reading about magnetic declination and inclination that the stock magnetic orientation is correct if your Australia also. I'm in California, US, BTW.

I forgot to mention that I also changed in the I2c Nav:
from: case 3: if (string[0] == 'S') i2c_dataset.gps_loc.lat = -i2c_dataset.gps_loc.lat;
break;
to :case 3: if (string[0] == 'N') i2c_dataset.gps_loc.lat = -i2c_dataset.gps_loc.lat;
break;


since my GPS outputs N (north) and W (West) string which is correct if you fly in the northern hemisphere, west of GMT.

Regards,

User avatar
jevermeister
Posts: 708
Joined: Wed Jul 20, 2011 8:56 am
Contact:

Re: GPS integration

Post by jevermeister »

Hi,

guys, the direction to home problem is solved by Alex in the trunk, he introduced a 180° shift so the arrow is the other way around now, no need to cvhange all the calculations.

By the way: Imho it would be wiser to calculate the angle from copter's nose to home, this is easily done and way more plausible to read (imho).

The curent method of RTH and PH is not working as you expect it to be.
As discussed above we need to create a cascading control loop to achieve a perfect approach and hold of position.
Just controlling the angle in relation to the distance to target will always overshoot. as the speed it has near the target is not brought to 0 at the target.
(you can play with PID but will always overshoot).
So we need a outer control loop where the groundpseed is the variable value in relation to distance to target, this value is changed by an inner control loop with angle (x,y) as value to achive a speed.
The same principle is used with the baro code by the way.

Alex is aware of that but he is concentrating on 2.0 release of Multiwii right now. So be patient.

This GPS code is only the first very very good mile on a long road to a perfect RTH and PH.


Nils

MicroRaptor
Posts: 20
Joined: Tue Mar 20, 2012 1:56 am

Re: GPS integration

Post by MicroRaptor »

Nils,

Thanks for pointing out the changes in the trunk. I didn't notice that since I was using i2c nav.

I know that the GPS code is still in its infancy. I am just amazed by the evolution of Multiwii. Succeeding in GPS interfacing opens up new possibilities.

Judd

PatrikE
Posts: 1976
Joined: Tue Apr 12, 2011 6:35 pm
Location: Sweden
Contact:

Flying below SeaLevel

Post by PatrikE »

Found a possible overflow.
It's possible to fly at altitudes below SeaLevel..

Code: Select all

static uint16_t GPS_altitude,GPS_speed;                      // altitude in 0.1m and speed in 0.1m/s - Added by Mis

Big parts of Holland is actually below SeaLevel.

/Patrik

MicroRaptor
Posts: 20
Joined: Tue Mar 20, 2012 1:56 am

Re: GPS integration

Post by MicroRaptor »

I just realized that inverting (lat2-lat1) was needed because I swapped "N" for "S" in the I2C Nav code (I did that when I was debugging my setup). Everything now works fine as it is (MW2p4 and I2CGPS v0.1)for my setup. Arrow points home.


Sorry if it caused some confusion.

Judd

User avatar
mbrak
Posts: 136
Joined: Sat Dec 03, 2011 8:08 pm
Location: Germany, Lemgo

Re: GPS integration

Post by mbrak »

hi

are the modifications on gps-code for both systems (i2c and serial gps)? or only i2c gps?
i am a bit confused when reading
I just realized that inverting (lat2-lat1) was needed because I swapped "N" for "S" in the I2C Nav code

MicroRaptor
Posts: 20
Joined: Tue Mar 20, 2012 1:56 am

Re: GPS integration

Post by MicroRaptor »

Just I2C. But as I said, code works as is, no modification needed.

Fritz
Posts: 11
Joined: Fri Mar 16, 2012 8:48 am
Location: Germany

Re: GPS integration

Post by Fritz »

Hello again,

Now I have the GPS module built up again with an Arduino Pro Mini Board.

SCL -> SCL, SDA -> SDA. Both at 5 volts, RX -> TX and TX -> RX. The GPS module is receiving satellite.

EOSBandi code on the Arduino and the address 0x20 set point. Otherwise, I've changed nothing in this code.

In the main board I have the following codes:

Code: Select all

/ / # 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 clones WMP


Code: Select all

/* GPS using a SERIAL port
   only available on MEGA boards (this might be possible on 328 based boards in the future)
   if enabled, define here the Arduino Serial port number and the UART speed
   note: only the RX PIN is used, the GPS is not configured by multiwii
   the GPS must be configured to output NMEA sentences (which is generally the default conf for most GPS devices)
   uncomment the first line to select the GPS serial port of the arduino */
//#define GPS_SERIAL 2 // should be 2 for flyduino v2. It's the serial port number on arduino MEGA
#define GPS_BAUD   115200
//#define GPS_BAUD   9600

/* I2C GPS device made with an independant arduino + GPS device
   including some navigation functions
   contribution from EOSBandi
   http://code.google.com/p/i2c-gps-nav/ */
#define I2C_GPS


Code: Select all

  #define I2C_GPS_ADDRESS                         0x20 


twi.h and in which I have changed this:

Code: Select all

   # ifndef TWI_FREQ
   # define TWI_FREQ 400000L
   # endif


I absolutely think of anything more. Does anyone have any idea? Does anyone have a schematic of how he built it?

In the GUI, it still looks like this:
ScreenShot014.jpg


Fritz

Wayne
Posts: 86
Joined: Sun Jul 31, 2011 10:44 pm

Re: GPS integration

Post by Wayne »

Fritz I wish I could help but I ussing Serial GPS...

My MW Home never seams to be where I am. Off by a few meters to 30-40 or more at times.
The first Fix I get always is way off and resting MW after HDOP is down around 1.0 helps a lot.

In an effort to reset Home I did write a few lines and get a button to toggle 0/1 at debug2 in the GUI.
That’s as far as took it, now thinking setting Home after HDOP is about 1.2 or so may be a better idea.

MicroRaptor
Posts: 20
Joined: Tue Mar 20, 2012 1:56 am

Re: GPS integration

Post by MicroRaptor »

Fritz, did you replace the twi.c and twi.h with the patch from :
http://code.google.com/p/i2c-gps-nav/so ... 253Dclosed
located in the arduino-1.0\libraries\Wire\utility folder?

You are having I2C errors meaning that there is communication problem between the main and secondary arduino.

User avatar
Gartenflieger
Posts: 65
Joined: Sat Oct 01, 2011 10:07 pm
Location: Dortmund, Germany

Re: GPS integration

Post by Gartenflieger »

Wouldn't it be good to set home with the first arming of the motors?
That way no additional step is required and the arming is usually done at the launch point.

Regards, Christoph

Fritz
Posts: 11
Joined: Fri Mar 16, 2012 8:48 am
Location: Germany

Re: GPS integration

Post by Fritz »

Hello MicroRaptor

yes, the two files I've already replaced two times. I also have just one more time controls. This is correct.

I now have time measured with the oscillator at the i2c. The motherboard is made ​​through the i2c data. Here you can see the communication between the sensors and the processor.
On the second Arduino is doing nothing at all. Since I've gotten everything out and measured it out of the i2c everything is ok, I've already tried three different boards, I do not think that it is up to the hardware.

In the play of the I2C_GPS_NAV on the processor, you have to play with as yet another file? Do you have to rename it? I feel as if it does not work at all.

The boot loader is set to play.

greeting

Wayne
Posts: 86
Joined: Sun Jul 31, 2011 10:44 pm

Re: GPS integration

Post by Wayne »

Good idea Christoph or maybe reset each time we arm.
To do this we would have to separate the LED functions, one for armed/tilted the other for Fixed.
Or a new flash rate for Armed/Fixed would work too.

Also I noticed that MW does not stop flashing the LED after 3D fix is lost by the module.

User avatar
fr3d
Posts: 97
Joined: Sun Feb 06, 2011 11:21 am
Location: Cappelle la grande near the ch'ti village
Contact:

Re: GPS integration

Post by fr3d »

Wayne wrote:Good idea Christoph or maybe reset each time we arm.

great idea nice.
Last edited by fr3d on Sat Mar 24, 2012 3:25 pm, edited 1 time in total.

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: GPS integration

Post by Alexinparis »

nhadrian wrote:
MicroRaptor wrote:from :
float dLat = ((lat2 - lat1)); // difference of latitude in 1/100000 degrees

to:
float dLat = ((lat1 - lat2)); // difference of latitude in 1/100000 degrees


Thanks for confirming my idea on swapping lat1 and lat2!
But, I think you also changed the dLon calculation, and in main multiwii.ini the sign of errorangle calculation GPS part?

BR
Adrian

For the moment, I've just added a +180 in the Serial output to match the right direction in GUI.
I will change thing from the root (like you did) in future releases.

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: Flying below SeaLevel

Post by Alexinparis »

PatrikE wrote:Found a possible overflow.
It's possible to fly at altitudes below SeaLevel..

Code: Select all

static uint16_t GPS_altitude,GPS_speed;                      // altitude in 0.1m and speed in 0.1m/s - Added by Mis

Big parts of Holland is actually below SeaLevel.

/Patrik

I is measurable with the GPS accuracy ?
Anyway, you're right. I thin in Poland, there is no problem for MIS ;)

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: GPS integration

Post by Alexinparis »

Wayne wrote:Fritz I wish I could help but I ussing Serial GPS...

My MW Home never seams to be where I am. Off by a few meters to 30-40 or more at times.
The first Fix I get always is way off and resting MW after HDOP is down around 1.0 helps a lot.

In an effort to reset Home I did write a few lines and get a button to toggle 0/1 at debug2 in the GUI.
That’s as far as took it, now thinking setting Home after HDOP is about 1.2 or so may be a better idea.


I think it's a good idea to reset the home position at each arming stage, and not once at the power on stage.
It should allow the GPS to stabilize and then get home accuracy with a small HDOP.

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: GPS integration

Post by Alexinparis »

Wayne wrote:Also I noticed that MW does not stop flashing the LED after 3D fix is lost by the module.

Yes, it's currently a one way toggle state.

MelihK
Posts: 13
Joined: Sat Feb 18, 2012 10:00 pm

Re: GPS integration

Post by MelihK »

Hi Guys,

After 3 weeks delay (because of a design problem and reproduction) Navigatron I2C GPS modules in stocks.
I 'am glad to announce that %10 discount for first 20 units :)

Image

Image

Navigatron boards including GPS + onboard Arduino + battery backup and fully compatible with our other I2C sensors and OpenLRS Multi controller boards.

@EOSBandi, please check your message box :)

@Alexinparis, are your repository open for other developers? I'm modifying MultiWii code for my opensource receiver system and it is working on our v2 receivers and OpenLRS Multi boards. I will glad to be a developer and add OpenLRS receiver integration on current code.

have a nice weekend
Melih

User avatar
djrm
Posts: 40
Joined: Wed Feb 15, 2012 11:32 pm
Location: North Yorkshire, UK

Re: GPS integration

Post by djrm »

Greetings,
I'm in the process of building an I2C GPS receiver for my Multiwii.

During testing I've found what I believe may be a bug in the GPS_fix_home setting section towards the end of the GPS_NewData function. At around line 61 of the pre4 version of the GPS module this line of code "if (rcData[AUX4]>1800 || GPS_fix_home == 0) " will tell the GPS to store the current position, even if there is no GPS fix. This is executed every time through the function before lock is achieved, I suspect this is not intended behaviour.

My GPS receiver is based on an Arduino Mini Pro 3.3 volt 8MHz together with a GoldTop Micro GPS serial module with onboard antenna, I had some I2C timing problems in the Multiwii software trying to get this to work but I'm making progress now.

hth David.

Wayne
Posts: 86
Joined: Sun Jul 31, 2011 10:44 pm

Re: GPS integration

Post by Wayne »

Darn MelihK, I ordered with Ohararp and Flyduino a couple of days ago.
I am glad to see you added some mounting holes.
Lack of mounting holes on your serial module kept me from ordering it.

User avatar
dramida
Posts: 473
Joined: Mon Feb 28, 2011 12:58 pm
Location: Bucharest
Contact:

Re: GPS integration

Post by dramida »

MelihK wrote:Hi Guys,

After 3 weeks delay (because of a design problem and reproduction) Navigatron I2C GPS modules in stocks.
I 'am glad to announce that %10 discount for first 20 units :)

Image

Image

Navigatron boards including GPS + onboard Arduino + battery backup and fully compatible with our other I2C sensors and OpenLRS Multi controller boards.

@EOSBandi, please check your message box :)

@Alexinparis, are your repository open for other developers? I'm modifying MultiWii code for my opensource receiver system and it is working on our v2 receivers and OpenLRS Multi boards. I will glad to be a developer and add OpenLRS receiver integration on current code.

have a nice weekend
Melih

I like the Rfm 22b Chip on MWC, it has 3 Km range of bi-directional com on level ground.

Splashy
Posts: 11
Joined: Wed Sep 21, 2011 8:26 pm

Re: GPS integration

Post by Splashy »

MelihK wrote:Hi Guys,

After 3 weeks delay (because of a design problem and reproduction) Navigatron I2C GPS modules in stocks.
I 'am glad to announce that %10 discount for first 20 units :)

Image

Image

Navigatron boards including GPS + onboard Arduino + battery backup and fully compatible with our other I2C sensors and OpenLRS Multi controller boards.

@EOSBandi, please check your message box :)

@Alexinparis, are your repository open for other developers? I'm modifying MultiWii code for my opensource receiver system and it is working on our v2 receivers and OpenLRS Multi boards. I will glad to be a developer and add OpenLRS receiver integration on current code.

have a nice weekend
Melih


Ordered .. and I think I am the first !

Keep up the good work !

User avatar
Gaijin
Posts: 82
Joined: Sat Jan 14, 2012 8:00 am

Re: GPS integration

Post by Gaijin »

[/quote]
Ordered .. and I think I am the first !

Keep up the good work ![/quote]

Nope, you are beaten!

But the forum locked me out and it took an age to get a new password!

@Mhelihk have you pre-flashed the boards with EosBandi's code, if not presumably you do so via FTDI.

@EosBandi could you consider a merge with the ideas here http://www.multiwii.com/forum/viewtopic.php?f=7&t=1033 when you consider the code is ready, I have an HC-SR04 knocking about and it seems pointless to buy an I2c sonar module when a secondary processor is available.

I'm sure I could do so myself but I'm kinda feeling my way here...

wilco1967
Posts: 156
Joined: Thu Aug 18, 2011 6:04 pm
Location: Winterswijk, Netherlands

Re: GPS integration

Post by wilco1967 »

There seem to be two path being followed on GPS integration
- Serial GPS directly to arduino (MEGA only, flyduino GPS board)
- GPS connected to second arduino and I2C connection to main multiwii arduino. (EosBandi code on MelihK board for example )

I'm thinking of buying a GPS, but which methode is most likely to be the most future proof ?

I understand the advantages of the I2C methode, being unloading complex calculations from the multiwii arduino, thus allowing a normal arduino to be used. But I also have a Flyduino mega board, which has plenty of computing power to do the calculations onboard.

Any opinion ?

User avatar
NikTheGreek
Posts: 348
Joined: Thu Dec 08, 2011 4:17 pm
Location: Greece
Contact:

Re: GPS integration

Post by NikTheGreek »

Any opinion ?

My VOTE for I2C GPS....

marbalon
Posts: 107
Joined: Thu Aug 18, 2011 10:59 am

Re: GPS integration

Post by marbalon »

MelihK wrote:Hi Guys,

After 3 weeks delay (because of a design problem and reproduction) Navigatron I2C GPS modules in stocks.
I 'am glad to announce that %10 discount for first 20 units :)

Image

Image

Navigatron boards including GPS + onboard Arduino + battery backup and fully compatible with our other I2C sensors and OpenLRS Multi controller boards.

@EOSBandi, please check your message box :)

@Alexinparis, are your repository open for other developers? I'm modifying MultiWii code for my opensource receiver system and it is working on our v2 receivers and OpenLRS Multi boards. I will glad to be a developer and add OpenLRS receiver integration on current code.

have a nice weekend
Melih


I read datesheet and there is an information "No traces and vias are allowed to pass the area" on page 6. This is the center of PCB, and you put Atmega in this place. This is a bug? Or you talk with globalsat about this suggestion. In newer modules they suggest place a hole under module, so I think it is not a good idea put CPU there...

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: GPS integration

Post by Alexinparis »

MelihK wrote:@Alexinparis, are your repository open for other developers? I'm modifying MultiWii code for my opensource receiver system and it is working on our v2 receivers and OpenLRS Multi boards. I will glad to be a developer and add OpenLRS receiver integration on current code.

Yes it is, just pm me a mail which is recognized by googlecode.
I saw your great adaptation !
If possible, I would move OpenLRS.pde inside RX.pde as a specific part to keep the tab structure.

wilco1967
Posts: 156
Joined: Thu Aug 18, 2011 6:04 pm
Location: Winterswijk, Netherlands

Re: GPS integration

Post by wilco1967 »

refractions wrote:Hi,

Got around to removing all the shielding on this board. You are correct in that the usb chip is a PL-2303. Seems simple enough from datasheet.

pin 1 TXD
pin 5 RXD
pin 20 VDD
pin 21 GND

Just need a small enough iron tip now.

Iain


Hi Iain,

managed to get my old Globalsat BU-303 GPS mouse working on Flyduino Mega.
this one.... http://www.globalsat.co.uk/product_page ... _bu303.htm

Forgot to make pictures while it was open, and now it is hot-glued closed... :roll:
So I try to explain with a thousand (or so) words....

The PL-2303 USB-RS232 converter on the BU-303 GPS mouse is under the shield on the top side, where the antenna is. I simply used an exacto knife to cut through the solder holding the shield to the board, and the whole top could be removed. The receiver antenna is only held by a single coax cable.

I connected power to the terminal row called J3 (just a row of 6 soldering pads,), next to the connector where the USB cable was connected (not under the cover..). So no need to make all connections on the small SMD pins of the 2303.
+5V on the most right pin (from the row, NOT the larger one on the edge, orientation with usb connector facing towards me).
GND on one of the 3 leftmost pins (they all seem connected).

The serial data can be picked up from the PL-2303 pin 5 (5th pin from the left, where the dot is). Pin 1 (TXD) is not needed. So only one wire on the small SMD pins.

To test, you can also use a FTDI instead of the Flyduino. I just used the same program on the computer when it still was connected through the original USB cable (might have to change the comm port). The original USB cable connection still works (if I hadn't cut it up....).

The old USB cable can be re-used as it has the same connector as used on the Flyduino V2 serial port. I simply cut off the USB plug, and soldered the wires directly to the GPS receiver.

Flyduino most right pin (1) = GND = black
pin 2 = +5V = (red)
pin 3 = RX according to Flyduino site, but It did not work here (white)
pin 4 = TX, this is where I had to connect the serial data wire from PL-2303 pin5 (green)

By default, the BU-303 sends NMEA data at 4800 baud, and has an update of only 1 Hz.

In config.h just set
#define GPS_SERIAL 2 // should be 2 for flyduino v2. It's the serial port number on arduino MEGA
#define GPS_BAUD 4800

that's all.... :)

when powering up, the led on the GPS mouse first lights up steady. after a minute or so, it starts blinking, when it has a fix.

The ring around the compass in the GUI will blink if NMEA data is received. it becomes steady if no data is received.
The NUMSAT will show the number of satelites it sees... It becomes green if a fix is made.
As there is no battery back-up, you'll have to be patient for it to get a location fix after you changed batteries.

I've tried it on my Tri, and can definitely see the reaction of the GPS when selecting position hold or RTH....
However,my compass is drifting badly on the tri, from ESC wires etc, so in GPS position hold or return to home, it steers in the wrong direction (the software thinks it is steering correctly, but in fact, it's going in the wrong direction... not the software or GPS fault, but simply due to wrong compass heading).
Will have to find a better location for the compass...
I'm pretty sure the slow update of only 1 hz would be sufficient for approximate postition hold... might not be perfect, but sufficient for purpose.

Now to get that compass sorted.... :roll:
Oh, and don't forget to loose the magnet if you're re-using the housing... it messes up the compass badly

MelihK
Posts: 13
Joined: Sat Feb 18, 2012 10:00 pm

Re: GPS integration

Post by MelihK »

Gaijin wrote:@Mhelihk have you pre-flashed the boards with EosBandi's code, if not presumably you do so via FTDI.


It is coming with EOS Bandit code :)


marbalon wrote:I read datesheet and there is an information "No traces and vias are allowed to pass the area" on page 6. This is the center of PCB, and you put Atmega in this place. This is a bug? Or you talk with globalsat about this suggestion. In newer modules they suggest place a hole under module, so I think it is not a good idea put CPU there...


As you wrote, there is no trace there ;)
I'm designing and selling GPS boards since 4 years.
have a big hole on the PCB there for isolating the antenna input of GPS from near electric lines. Atmega328 hiding the hole. Trust me I'm an engineer ;)
Last edited by MelihK on Sun Mar 25, 2012 6:36 pm, edited 1 time in total.

MelihK
Posts: 13
Joined: Sat Feb 18, 2012 10:00 pm

Re: GPS integration

Post by MelihK »

Alexinparis wrote:
MelihK wrote:@Alexinparis, are your repository open for other developers? I'm modifying MultiWii code for my opensource receiver system and it is working on our v2 receivers and OpenLRS Multi boards. I will glad to be a developer and add OpenLRS receiver integration on current code.

Yes it is, just pm me a mail which is recognized by googlecode.
I saw your great adaptation !
If possible, I would move OpenLRS.pde inside RX.pde as a specific part to keep the tab structure.


Hi Alex,

Oh thanks, I'm glad to be a part of MultiWii project, PM coming.. :)

The main problem of the OpenLRS adaptation is pinouts. We are using few pins for Rx system and you are using same pins for different usage like battery measure or something.
And another is the options of OpenLRS, Current adapted MultiWii code supporting only Rx, but our current OpenLRS release supporting 18ch rx + 9600 baud bidirectional data telemetry + RSSI level checks + Warbird mode + alarm options + Lost plane locator etc. It will be huge file after integrated to MultiWii.

If it possible, i want to be keep separated OpenLRS tab, because it is not static Rx system and growing fast.
Or we can integrate only Rx options of OpenLRS to MultiWii. And enough for %99 of OpenLRS users that they using on multicopter, because most of user interesting about plane usage and this is why they are using other options.
You are the master of MultiWii, i will integrate the OpenLRS where you want :)

Current adaptation including:
  • OpenLRS tab
  • P and I pots(An6 and AN7) for trimming P and I at the field with "checkPots();" command in setup
  • OpenLRS module and LED pins
  • Read_OpenLRS_RC(); command in the loop
  • "#define OpenLRS 1" line in the config.h

marbalon
Posts: 107
Joined: Thu Aug 18, 2011 10:59 am

Re: GPS integration

Post by marbalon »

Hi,
Last days I tried to pay with my i2c GPS and have one small suggestion. Like many user descrribe, it will be useful reset home position on request. So I added function:

Code: Select all

void GPS_reset_home_position()
{
  #if defined(I2C_GPS)
    //set current position as home
    i2c_rep_start(I2C_GPS_ADDRESS);i2c_write(I2C_GPS_COMMAND);i2c_write(I2C_GPS_COMMAND_SET_WP);//Store current position to WP#0 (this is used for RTH)
    i2c_rep_start(I2C_GPS_ADDRESS);i2c_write(I2C_GPS_COMMAND);i2c_write(I2C_GPS_COMMAND_ACTIVATE_WP);//Set WP#0 as the active WP
  #else
    GPS_latitude_home  = GPS_latitude;
    GPS_longitude_home = GPS_longitude;
  #endif
}


and call it when calibrating gyro - I think the easiest way.

Code: Select all

...
      if (rcData[YAW] < MINCHECK && rcData[PITCH] < MINCHECK && armed == 0) {
        if (rcDelayCommand == 20)
        {
          calibratingG = 400;
          GPS_reset_home_position();
        }
...


I also removed this lines from gps.pde

Code: Select all

    if (rcData[AUX4]>1800 || GPS_fix_home == 0) {
      i2c_rep_start(I2C_GPS_ADDRESS);i2c_write(I2C_GPS_COMMAND);i2c_write(I2C_GPS_COMMAND_SET_WP);//Store current position to WP#0 (this is used for RTH)
      i2c_rep_start(I2C_GPS_ADDRESS);i2c_write(I2C_GPS_COMMAND);i2c_write(I2C_GPS_COMMAND_ACTIVATE_WP);//Set WP#0 as the active WP
    }


Not big deal but useful for everyone.

Regards,
Marcin.

MelihK
Posts: 13
Joined: Sat Feb 18, 2012 10:00 pm

Re: GPS integration

Post by MelihK »

Improved version of EOS Bandit's I2C GPS Code,

Features:
  • 9600 baud standard GPS switching code added, this MTK command switching the GPS module to 115200 baud. You can use same command set with any baudrate to 115200
  • NMEA sentence configurator MTK command added. It is removing useless NMEA codes from the stream.
  • LED indicator added. Arduino LED(pin 13) blinking for 3 seconds at start and very short blinks after GPS lock.

@EOS Bandit, Please check it and add into your repository, if they are useful features.

I2C_GPS_NAV.zip
(6.09 KiB) Downloaded 413 times

rbirdie001
Posts: 178
Joined: Fri Apr 01, 2011 10:32 pm
Location: Czech Republic, Prague

Re: GPS integration

Post by rbirdie001 »

Today I tested 2.0 with the I2C GPS and even not perfect, now it seems to work!
What I noticed: GPS position changes aren't continuous and don't have so fine resolution so if higher P for GPS is set, copter near the home position shakes like each arm "walking on stairs" but each arm on different stairway :) . My guess it's that if the computation gives distance to home e.g. 1m and then changes in the step to e.g. 2m copter abruptly corrects the declination and moves one arm e.g. +5cm up in a step and this randomly repeats as the data from GPS changes. Very bad for video/photo :( .
Could someone (sorry I can't code) add some GPS correction smoothing?
I'd like also to vote +1 for for improving the GPS algoritm as suggested by nhadrian here viewtopic.php?f=8&t=649&start=300#p10134.
Today was quite windy, but even in the very low wind I wasn't able to tune position hold to be reasonably stable - always flying in a chaotic circles and other strange shapes within 10m area ;).
Roman

refractions
Posts: 92
Joined: Thu Dec 01, 2011 8:55 pm
Location: Scotter, Lincolnshire, UK

Re: GPS integration

Post by refractions »

wilco1967 wrote:
refractions wrote:Hi,

Got around to removing all the shielding on this board. You are correct in that the usb chip is a PL-2303. Seems simple enough from datasheet.

pin 1 TXD
pin 5 RXD
pin 20 VDD
pin 21 GND

Just need a small enough iron tip now.

Iain


Hi Iain,

managed to get my old Globalsat BU-303 GPS mouse working on Flyduino Mega.
this one.... http://www.globalsat.co.uk/product_page ... _bu303.htm

Forgot to make pictures while it was open, and now it is hot-glued closed... :roll:
So I try to explain with a thousand (or so) words....

The PL-2303 USB-RS232 converter on the BU-303 GPS mouse is under the shield on the top side, where the antenna is. I simply used an exacto knife to cut through the solder holding the shield to the board, and the whole top could be removed. The receiver antenna is only held by a single coax cable.

I connected power to the terminal row called J3 (just a row of 6 soldering pads,), next to the connector where the USB cable was connected (not under the cover..). So no need to make all connections on the small SMD pins of the 2303.
+5V on the most right pin (from the row, NOT the larger one on the edge, orientation with usb connector facing towards me).
GND on one of the 3 leftmost pins (they all seem connected).

The serial data can be picked up from the PL-2303 pin 5 (5th pin from the left, where the dot is). Pin 1 (TXD) is not needed. So only one wire on the small SMD pins.

To test, you can also use a FTDI instead of the Flyduino. I just used the same program on the computer when it still was connected through the original USB cable (might have to change the comm port). The original USB cable connection still works (if I hadn't cut it up....).

The old USB cable can be re-used as it has the same connector as used on the Flyduino V2 serial port. I simply cut off the USB plug, and soldered the wires directly to the GPS receiver.

Flyduino most right pin (1) = GND = black
pin 2 = +5V = (red)
pin 3 = RX according to Flyduino site, but It did not work here (white)
pin 4 = TX, this is where I had to connect the serial data wire from PL-2303 pin5 (green)

By default, the BU-303 sends NMEA data at 4800 baud, and has an update of only 1 Hz.

In config.h just set
#define GPS_SERIAL 2 // should be 2 for flyduino v2. It's the serial port number on arduino MEGA
#define GPS_BAUD 4800

that's all.... :)

when powering up, the led on the GPS mouse first lights up steady. after a minute or so, it starts blinking, when it has a fix.

The ring around the compass in the GUI will blink if NMEA data is received. it becomes steady if no data is received.
The NUMSAT will show the number of satelites it sees... It becomes green if a fix is made.
As there is no battery back-up, you'll have to be patient for it to get a location fix after you changed batteries.

I've tried it on my Tri, and can definitely see the reaction of the GPS when selecting position hold or RTH....
However,my compass is drifting badly on the tri, from ESC wires etc, so in GPS position hold or return to home, it steers in the wrong direction (the software thinks it is steering correctly, but in fact, it's going in the wrong direction... not the software or GPS fault, but simply due to wrong compass heading).
Will have to find a better location for the compass...
I'm pretty sure the slow update of only 1 hz would be sufficient for approximate postition hold... might not be perfect, but sufficient for purpose.

Now to get that compass sorted.... :roll:
Oh, and don't forget to loose the magnet if you're re-using the housing... it messes up the compass badly



Brilliant - many thanks for all this.

Iain

Fritz
Posts: 11
Joined: Fri Mar 16, 2012 8:48 am
Location: Germany

Re: GPS integration

Post by Fritz »

Hello,

Unfortunately for me ha not done anything yet. My GPS does not work still.

Now I have sometimes looked at the code more closely. What about the i2c address? What do I need to adjust? Because of what is read and write. Do I have any of the motherboard in a different address as set in the gps board?

Fritz greeting

P.s. gibt es hier evtl. jemand der deutsch spricht und mir helfen kann?

User avatar
kos
Posts: 286
Joined: Thu Feb 16, 2012 4:51 am
Location: Fr

Re: GPS integration

Post by kos »

refractions wrote:
wilco1967 wrote:
refractions wrote:Hi,


managed to get my old Globalsat BU-303 GPS mouse working on Flyduino Mega.
this one.... http://www.globalsat.co.uk/product_page ... _bu303.htm


The PL-2303 USB-RS232 converter


Brilliant - many thanks for all this.

Iain



if you want to use 10 years old gps , this hack also work with the bluetooth serie (bt 231 , 236 , 238 ..) this way you have a direct serial connection and a bluetooth broadcast to your groundstation (could be a laptop , could be a smartphone) , they cost almost no money on ebay ( you just have to trick the device to prevent power saving if your are not pairing the device with bluetooth.. )

old hack from : http://deniska.dcemu.co.uk/diy-simple-p ... 30035.html

User avatar
djrm
Posts: 40
Joined: Wed Feb 15, 2012 11:32 pm
Location: North Yorkshire, UK

Re: GPS integration

Post by djrm »

The results of a bit of soldering here, Home made I2C GPS board with magnetometer sensor.
I'm still waiting for the Baro chip to arrive to complete the board.
Image
Integrated with Multiwii V2.0 on Crius lite board, yet to be tried in flight but working in WinGui.

Fritz
Posts: 11
Joined: Fri Mar 16, 2012 8:48 am
Location: Germany

Re: GPS integration

Post by Fritz »

Hello djrm,

can you give me your code please send to us. in the slave and the master in.

I can then compare the times with mine. I think I've got an error somewhere.

thank you

User avatar
djrm
Posts: 40
Joined: Wed Feb 15, 2012 11:32 pm
Location: North Yorkshire, UK

Re: GPS integration

Post by djrm »

Hello Fritz,

I had plenty of difficulty getting the code to work. I had to use this test harness to check the operation of the Arduino mini I2C program before I could get the Multiwii to work. The problem is somewhere in the I2C master functions in the multiwii software. My kludge solution is to add a delay between the address send and the data receive parts of the protocol. I'm looking into the possability of using another library to provide the I2C functions but I havnt got very far just yet.

Code: Select all

/**********************************************************
 * Multiwii I2C_GPS_Sample_Sketch
 **********************************************************/

#include "Wire.h"
#define GPS 0x20 //GPS I2C address

uint8_t statusReg  = 0;
long latitude   = 0;
long longitude  = 0;
long utcTime    = 0;
long date       = 0;
int directionToHome = 0;
int distanceToHome = 0;
int speed = 0;
int altitude = 0;

void setup(){
  Wire.begin();
  Serial.begin(115200);
}

void loop(){
  uint8_t *varptr;

  unsigned long timeOut = millis() + 1000;
  while(millis() <= timeOut);

  //let's grab data from the GPS
  Wire.beginTransmission(GPS);
  Wire.write((uint8_t)(0x0)); //set address pointer to zero
  Wire.endTransmission();
  delay(1); //1 millisecond delay is needed before requesting data
  Wire.requestFrom(GPS,26); // number of data bytes
 
  Serial.print("status = 0x");
  Serial.println(Wire.read(), HEX);

  Serial.print("command = ");
  Serial.println(Wire.read());

  Serial.print("byte2 = ");
  Serial.println(Wire.read());

  Serial.print("byte3 = ");
  Serial.println(Wire.read());

  Serial.print("byte4 = ");
  Serial.println(Wire.read());

  Serial.print("byte5 = ");
  Serial.println(Wire.read());

  Serial.print("waypointreg = ");
  Serial.println(Wire.read());


  varptr = (uint8_t *)&speed;         // speed in cm/s for OSD
  *varptr++ = Wire.read();
  *varptr   = Wire.read();
  Serial.print("speed = ");
  Serial.println(speed);
 
  varptr = (uint8_t *)&altitude;       // altitude in meters for OSD
  *varptr++ = Wire.read();
  *varptr   = Wire.read();
  Serial.print("altitude = ");
  Serial.println(altitude);
         
  varptr = (uint8_t *)&utcTime;      // for OSD latitude displaying
  *varptr++ = Wire.read();
  *varptr++ = Wire.read();
  *varptr++ = Wire.read();
  *varptr   = Wire.read();
  Serial.print("UTC Time = ");
  Serial.println(utcTime/1000.0,3);

  varptr = (uint8_t *)&distanceToHome;
  *varptr++ = Wire.read(); 
  *varptr   = Wire.read(); 
  Serial.print("GPS_distanceToHome ");
  Serial.println(statusReg);
 
  varptr = (uint8_t *)&directionToHome;
  *varptr++ = Wire.read(); 
  *varptr   = Wire.read(); 
  Serial.print("GPS_directionToHome ");
  Serial.println(statusReg);

  varptr = (uint8_t *)&latitude;      // for OSD latitude displaying
  *varptr++ = Wire.read();
  *varptr++ = Wire.read();
  *varptr++ = Wire.read();
  *varptr   = Wire.read();
  Serial.print("Latitude = ");
  Serial.println(latitude/100000.0,6);

  varptr = (uint8_t *)&longitude;      // for OSD longitude displaying
  *varptr++ = Wire.read();
  *varptr++ = Wire.read();
  *varptr++ = Wire.read();
  *varptr   = Wire.read();
  Serial.print("Longitude = ");
  Serial.println(longitude/100000.0,6);

  //Format the data to display on Google Maps
  Serial.print("http://maps.google.com/maps?q=");
  Serial.print(latitude/100000.0,6);Serial.print(",");
  Serial.print(longitude/100000.0,6);
  Serial.println("(Multiwii+I2C+GPS+location)&iwloc=A&hl=en");
  Serial.println();
 
}


The next step was to code a similar test appllication using the I2C primitive functions used in Multiwii, this is here:

Code: Select all

//#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
#define INTERNAL_I2C_PULLUPS
#define I2C_PULLUPS_ENABLE         PORTC |= 1<<4; PORTC |= 1<<5;   // PIN A4&A5 (SDA&SCL)
#define AUX4       7


// **********************
// GPS
// **********************
static int32_t  GPS_latitude,GPS_longitude;
static int32_t  GPS_latitude_home,GPS_longitude_home;
static int32_t  GPS_latitude_hold,GPS_longitude_hold;
static uint8_t  GPS_fix , GPS_fix_home = 0;
static uint8_t  GPS_numSat;
static uint16_t GPS_distanceToHome,GPS_distanceToHold;       // distance to home or hold point in meters
static int16_t  GPS_directionToHome,GPS_directionToHold;     // direction to home or hol point in degrees
static uint16_t GPS_altitude,GPS_speed;                      // altitude in 0.1m and speed in 0.1m/s - Added by Mis
static uint8_t  GPS_update = 0;                              // it's a binary toogle to distinct a GPS position update
static int16_t  GPS_angle[2];                                // it's the angles that must be applied for GPS correction

static int16_t rcData[8];    // interval [1000;2000]
static int16_t  i2c_errors_count = 0;
uint8_t rawADC[6];
static uint32_t neutralizeTime = 0;

uint8_t statusReg  = 0x55;


void setup(){
  Serial.begin(115200);
  Serial.println("Initialising");     
  i2c_init();
}

void loop(){

  unsigned long timeOut = millis() + 1000;
  while(millis() <= timeOut);

  GPS_NewData();
  if(GPS_numSat>0)
  {
   
  Serial.print("GPS_fix_home ");
  Serial.println(GPS_fix_home, HEX);
 
  Serial.print("GPS_latitude ");
//  Serial.println(GPS_latitude, HEX);
  Serial.println(GPS_latitude);
 
  Serial.print("GPS_longitude ");
//  Serial.println(GPS_longitude, HEX);
  Serial.println(GPS_longitude);
 
  Serial.print("GPS_fix ");
  Serial.println(GPS_fix, HEX);
 
  Serial.print("GPS_numSat ");
  Serial.println(GPS_numSat, HEX);
 
  Serial.print("GPS_altitude ");
  Serial.println(GPS_altitude, HEX);
 
  Serial.print("GPS_speed ");
  Serial.println(GPS_speed, HEX);
  }

}

// ************************************************************************************************************
// I2C general functions
// ************************************************************************************************************

void i2c_init(void) {
  #if defined(INTERNAL_I2C_PULLUPS)
    I2C_PULLUPS_ENABLE
  #else
    I2C_PULLUPS_DISABLE
  #endif
  TWSR = 0;                                    // no prescaler => prescaler = 1
  TWBR = ((16000000L / I2C_SPEED) - 16) / 2;   // change the I2C clock rate
  TWCR = 1<<TWEN;                              // enable twi module, no interrupt
}

void i2c_rep_start(uint8_t address) {
  TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN) ; // send REPEAT START condition
  waitTransmissionI2C();                       // wait until transmission completed
  TWDR = address;                              // send device address
  TWCR = (1<<TWINT) | (1<<TWEN);
  waitTransmissionI2C();                       // wail until transmission completed
}

void i2c_stop(void) {
  TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);
  //  while(TWCR & (1<<TWSTO));                // <- can produce a blocking state with some WMP clones
}

void i2c_write(uint8_t data ) {   
  TWDR = data;                                 // send data to the previously addressed device
  TWCR = (1<<TWINT) | (1<<TWEN);
  waitTransmissionI2C();
}

uint8_t i2c_readAck() {
  TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA);
  waitTransmissionI2C();
  return TWDR;
}

uint8_t i2c_readNak(void) {
  TWCR = (1<<TWINT) | (1<<TWEN);
  waitTransmissionI2C();
  uint8_t r = TWDR;
  i2c_stop();
  return r;
}

void waitTransmissionI2C() {
  uint16_t count = 255;
  while (!(TWCR & (1<<TWINT))) {
    count--;
    if (count==0) {              //we are in a blocking state => we don't insist
      TWCR = 0;                  //and we force a reset on TWINT register
      neutralizeTime = micros(); //we take a timestamp here to neutralize the value during a short delay
      i2c_errors_count++;
      break;
    }
  }
}

void i2c_getSixRawADC(uint8_t add, uint8_t reg) {
  i2c_rep_start(add);
  i2c_write(reg);         // Start multiple read at the reg register
  i2c_rep_start(add +1);  // I2C read direction => I2C address + 1
  delay(1);//djrm
  for(uint8_t i = 0; i < 5; i++)
  {
    rawADC[i]=i2c_readAck();
  }
  rawADC[5]= i2c_readNak();
}

void i2c_writeReg(uint8_t add, uint8_t reg, uint8_t val) {
  i2c_rep_start(add+0);  // I2C write direction
  i2c_write(reg);        // register selection
  i2c_write(val);        // value to write in register
  i2c_stop();
}

uint8_t i2c_readReg(uint8_t add, uint8_t reg) {
  i2c_rep_start(add+0);  // I2C write direction
  i2c_write(reg);        // register selection
  i2c_rep_start(add+1);  // I2C read direction
  delay(1);//djrm
  return i2c_readNak();  // Read single register and return value
}


  #define I2C_GPS_ADDRESS                         0x40       
  /*************** I2C GSP register definitions *********************************/
 
  #define I2C_GPS_STATUS                          0x00   //(Read only)
          #define I2C_GPS_STATUS_NEW_DATA         0x01
          #define I2C_GPS_STATUS_2DFIX            0x02
          #define I2C_GPS_STATUS_3DFIX            0x04
          #define I2C_GPS_STATUS_WP_REACHED       0x08      //Active waypoint has been reached (not cleared until new waypoint is set)
          #define I2C_GPS_STATUS_NUMSATS          0xF0
 
  #define I2C_GPS_COMMAND                         0x01   //(write only)
          #define I2C_GPS_COMMAND_POSHOLD         0x01      //copy current position to internal target location register
          #define I2C_GPS_COMMAND_RESUME          0x02      //copy last active WP to internal target location register
          #define I2C_GPS_COMMAND_SET_WP          0x04      //copy current position to given WP
          #define I2C_GPS_COMMAND_ACTIVATE_WP     0x08      //copy given WP position to internal target location register
          #define I2C_GPS_COMMAND_WP              0xF0      //Waypoint number
 
  #define I2C_GPS_WP_REG                          0x06   //Waypoint register (Read only)
          #define I2C_GPS_WP_REG_ACTIVE           0x0F      //Active Waypoint
          #define I2C_GPS_WP_REG_PERVIOUS         0xF0      //pervious Waypoint
         
  #define I2C_GPS_GROUND_SPEED                    0x07   //GPS ground speed in m/s*100 (uint16_t)      (Read Only)
  #define I2C_GPS_ALTITUDE                        0x09   //GPS altitude in meters (uint16_t)           (Read Only)

  #define I2C_GPS_TIME                            0x0b   //UTC Time from GPS in hhmmss.sss * 100 (uint32_t)(unneccesary precision) (Read Only)
  #define I2C_GPS_DISTANCE                        0x0f   //Distance between current pos and internal target location register in meters (uint16_t) (Read Only)
  #define I2C_GPS_DIRECTION                       0x11   //direction towards interal target location reg from current position (+/- 180 degree)    (read Only)
  #define I2C_GPS_LOCATION                        0x13   //current position (8 bytes, lat and lon, 1 degree = 10 000 000                           (read only)
  #define I2C_GPS_WP0                             0x1B   //Waypoint 0 used for RTH location      (R/W)
  #define I2C_GPS_WP1                             0x23
  #define I2C_GPS_WP2                             0x2B
  #define I2C_GPS_WP3                             0x33
  #define I2C_GPS_WP4                             0x3B
  #define I2C_GPS_WP5                             0x43
  #define I2C_GPS_WP6                             0x4B
  #define I2C_GPS_WP7                             0x53
  #define I2C_GPS_WP8                             0x5B
  #define I2C_GPS_WP9                             0x63
  #define I2C_GPS_WP10                            0x6B
  #define I2C_GPS_WP11                            0x73
  #define I2C_GPS_WP12                            0x7B
  #define I2C_GPS_WP13                            0x83
  #define I2C_GPS_WP14                            0x8B
  #define I2C_GPS_WP15                            0x93
  #define I2C_GPS_WP_NAV_PAR1                     0x9B   //Waypoint navigation parameter 1
          #define I2C_GPS_WP_NAV_PAR1_REACH_LIMIT 0x0F      //lover 4 bit, waypoint reached distance

void GPS_NewData() {
    static uint8_t _i2c_gps_status;
 
    //Do not use i2c_writereg, since writing a register does not work if an i2c_stop command is issued at the end
    //Still investigating, however with separated i2c_repstart and i2c_write commands works... and did not caused i2c errors on a long term test.
 
    _i2c_gps_status = i2c_readReg(I2C_GPS_ADDRESS,I2C_GPS_STATUS);                    //Get status register
    Serial.print("Status 0x");
    Serial.println(_i2c_gps_status, HEX);
   
    if (_i2c_gps_status & I2C_GPS_STATUS_3DFIX) {                                     //Check is we have a good 3d fix (numsats>5)
       GPS_fix = 1;                                                                   //Set fix
       GPS_numSat = (_i2c_gps_status & 0xf0) >> 4;                                    //Num of sats is stored the upmost 4 bits of status
//       Serial.print(", 3D fix ");
       if (!GPS_fix_home) {        //if home is not set set home position to WP#0 and activate it
Serial.println("GPS fix home set.");       
          i2c_rep_start(I2C_GPS_ADDRESS);i2c_write(I2C_GPS_COMMAND);i2c_write(I2C_GPS_COMMAND_SET_WP);//Store current position to WP#0 (this is used for RTH)
          i2c_rep_start(I2C_GPS_ADDRESS);i2c_write(I2C_GPS_COMMAND);i2c_write(I2C_GPS_COMMAND_ACTIVATE_WP);//Set WP#0 as the active WP
          GPS_fix_home = 1;                                                           //Now we have a home   
       }
       if (_i2c_gps_status & I2C_GPS_STATUS_NEW_DATA) {                               //Check about new data
          if (GPS_update) { GPS_update = 0;} else { GPS_update = 1;}                  //Fancy flash on GUI :D
Serial.println("New data");
          //Read GPS data for distance, heading and gps position
          i2c_rep_start(I2C_GPS_ADDRESS);
          i2c_write(I2C_GPS_DISTANCE);                                                //Start read from here 2x2 bytes distance and direction
          i2c_rep_start(I2C_GPS_ADDRESS+1);
          delay(1);
          uint8_t *varptr = (uint8_t *)&GPS_distanceToHome;
          *varptr++ = i2c_readAck();
          *varptr   = i2c_readAck();
          varptr = (uint8_t *)&GPS_directionToHome;
          *varptr++ = i2c_readAck();
          *varptr   = i2c_readAck();
          varptr = (uint8_t *)&GPS_latitude;      // for OSD latitude displaying
          *varptr++ = i2c_readAck();
          *varptr++ = i2c_readAck();
          *varptr++ = i2c_readAck();
          *varptr   = i2c_readAck();
          varptr = (uint8_t *)&GPS_longitude;      // for OSD longitude displaying
          *varptr++ = i2c_readAck();
          *varptr++ = i2c_readAck();
          *varptr++ = i2c_readAck();
          *varptr   = i2c_readNak();

//Serial.print(", New data 7");
          i2c_rep_start(I2C_GPS_ADDRESS);
          i2c_write(I2C_GPS_GROUND_SPEED);          //Start read from here 2x2 bytes speed and altitude
          i2c_rep_start(I2C_GPS_ADDRESS+1);
          delay(1);
          varptr = (uint8_t *)&GPS_speed;         // speed in cm/s for OSD
          *varptr++ = i2c_readAck();
          *varptr   = i2c_readAck();
          varptr = (uint8_t *)&GPS_altitude;       // altitude in meters for OSD
          *varptr++ = i2c_readAck();
          *varptr   = i2c_readNak();
        }
 
    } else {                                                                          //We don't have a fix zero out distance and bearing (for safety reasons)
      GPS_distanceToHome = 0;
      GPS_directionToHome = 0;
      GPS_numSat = 0;
    } 

    if (rcData[AUX4]>1800 /*|| GPS_fix_home == 0*/) {
Serial.println("GPS fix home set anyway");       
      i2c_rep_start(I2C_GPS_ADDRESS);i2c_write(I2C_GPS_COMMAND);i2c_write(I2C_GPS_COMMAND_SET_WP);//Store current position to WP#0 (this is used for RTH)
      i2c_rep_start(I2C_GPS_ADDRESS);i2c_write(I2C_GPS_COMMAND);i2c_write(I2C_GPS_COMMAND_ACTIVATE_WP);//Set WP#0 as the active WP
    }

}

/* this is an equirectangular approximation to calculate distance and bearing between 2 GPS points (lat/long)
   it's much more faster than an exact calculation
   the error is neglectible for few kilometers assuming a constant R for earth
   input: lat1/long1 <-> lat2/long2      unit: 1/100000 degree
   output: distance in meters, bearing in degrees
*/
void GPS_distance(int32_t lat1, int32_t lon1, int32_t lat2, int32_t lon2, uint16_t* dist, int16_t* bearing) {
  float dLat = (lat2 - lat1);                                    // difference of latitude in 1/100000 degrees
  float dLon = (lon2 - lon1) * cos(lat1*(PI/180/100000.0));      // difference of longitude in 1/100000 degrees
  *dist = 6372795 / 100000.0 * PI/180*(sqrt(sq(dLat) + sq(dLon)));
  *bearing = 180/PI*(atan2(dLon,dLat));
}


The changes which made the software work are the delay(1) statements, I would much rather they were not there. I dont think I made any significant changes to the GPS receiver software, I'll check in a while for you. I did change the GPS baudrare and configured an expanded set of NMEA sentences as described in the GPS device manual but I dont think that is neccessary if you want to stick to the default 9600 bps. If you oare using some device other than the Global one like mine then things could be different anyway. All the problems seemed to lie in the Multiwii master side. You do have to modify the Wire library as described in the instructions for the slave device to work properly. There is some serial print statements in the GPS slave software to help check what the master is sending. look at the source for more details. Just ask if you need more help.

Best regards, David.

User avatar
Loosi
Posts: 63
Joined: Sat Aug 20, 2011 8:31 pm
Location: Germany (HSK)
Contact:

Re: GPS integration

Post by Loosi »

I used the schematic and software from flytron to build my own, its working perfect ;)

Image

Image

Image

Image

quick and dirty, but working perfect.

Fritz
Posts: 11
Joined: Fri Mar 16, 2012 8:48 am
Location: Germany

Re: GPS integration

Post by Fritz »

Hi David,

many thanks! I'll do it myself tomorrow ago. I also think that it was the master - slave has to do.

Fritz greeting

Post Reply