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
Scotth72
Posts: 23
Joined: Sat Jan 21, 2012 4:11 am

Re: GPS integration

Post by Scotth72 »


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

Re: GPS integration

Post by Gaijin »

Okay,

To test out UBlox Vs MTK I've ordered a NEO-6M module from RCTimer and AT328 I2C board to test in place of my MTK based Navigatron, do I need to re-flash the UBlox?
Is there a guide to which firmware / settings we need, obviously I understand that I2c is on hold ATM while 2.1 is finished, but will the I2C sketch need much modification to work with the binary protocol?

http://www.rctimer.com/index.php?gOo=goods_details.dwt&goodsid=763&productname=
http://www.rctimer.com/index.php?gOo=goods_details.dwt&goodsid=762&productname=

LuFa
Posts: 160
Joined: Fri Jan 27, 2012 7:56 pm

Re: uBlox binary protocol....

Post by LuFa »

EOSBandi wrote:So I had a very little time for test it, because a quite heavy storm hit my flying place. BUT i had some results.
First, here is a small video....
http://www.youtube.com/watch?v=Uo_v6tBXqNU
....


Very Cool :) !

User avatar
EOSBandi
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary
Contact:

Re: GPS integration

Post by EOSBandi »

Ublox neo modules are not reflashable, but they not need it at all....
You need the u-center software to config the u-blox module.
Here is a settings file for NMEA. You can download it to your module with the tools->GPS configuration menu...
Once the binary protocol parser is committed to Multiwii i'll update the i2c sw too.

One more issue : I found that the onboard battery of these ebay ublox modules are hardly last more than a couple of days... and since the neo-6M does not have flash onboard, then it forgets the settings. So it's worth do buy an i2c EEPROM chip (about .5usd a piece) (Microchip 24AA32A, or ST MC24C32-R) and connect it to the i2c port of the gps (some boards already has i2c port connection, or you can solder it directly to the module). (I'll update the GPS docs about ublox, including the external i2c storage).

I there is interest, i'll make breakout boards with i2c eeprom chips.
Attachments
u-blox-config.nmea.zip
U-blox neo-6 config for NMEA (115200 baud, 10Hz, European SBAS)
(859 Bytes) Downloaded 694 times

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

Re: GPS integration

Post by shikra »

Excellent EOS

Also you shoudl take a snapshot of 1:03 - has to be one of the best Tricopter pictures ever!

User avatar
EOSBandi
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary
Contact:

Re: GPS integration

Post by EOSBandi »

shikra wrote:Excellent EOS

Also you shoudl take a snapshot of 1:03 - has to be one of the best Tricopter pictures ever!

Already did that :D
Snapshot 1 (7-6-2012 12-27 AM).jpg


BUT GUYS !!! I'v been chasing storms for photograpy in the last 15 years, I checked the doppler radar info and lightning tracking on the field continously....
Please do not try this unless you know your location and the distance of the storm. Beeing on the field in a storm easily could be lethal !!!!

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

Re: GPS integration

Post by Gaijin »

EOSBandi wrote:Ublox neo modules are not reflashable, but they not need it at all....
You need the u-center software to config the u-blox module.
Here is a settings file for NMEA. You can download it to your module with the tools->GPS configuration menu...
Once the binary protocol parser is committed to Multiwii i'll update the i2c sw too.

One more issue : I found that the onboard battery of these ebay ublox modules are hardly last more than a couple of days... and since the neo-6M does not have flash onboard, then it forgets the settings. So it's worth do buy an i2c EEPROM chip (about .5usd a piece) (Microchip 24AA32A, or ST MC24C32-R) and connect it to the i2c port of the gps (some boards already has i2c port connection, or you can solder it directly to the module). (I'll update the GPS docs about ublox, including the external i2c storage).

I there is interest, i'll make breakout boards with i2c eeprom chips.


Thanks Eos,

Just thinking though, If you are using an I2C AT328 adapter board, can't you store the Ublox settings on that or force the settings at start up somehow?

tsoumelman
Posts: 4
Joined: Sat Jun 23, 2012 9:05 pm

Re: GPS integration

Post by tsoumelman »

brettwal wrote:
EOSBandi wrote:
brettwal wrote:I am a bit confused on something, perhaps someone can assist.

I have a Crius SE with a Serial GPS module and it is working fine. I purchased a Crius V1.0 (with the I2C pins) and the I2C GPS Navigation module from RCTimer. (http://rctimer.com/index.php?gOo=goods_ ... oductname=). Do I have to load a sketch on to the AT328 on the module? or is this not necessary? I think YES but, find it odd that there are no pins for FTDI on RCTimer board.


Take a closer look. The place for pins is there, even labeled as FTDI, just solder in some pins....



I added pins. Am using Arduino 1.01. When I replace twi.h and twi.c with the patched files, I get compile errors.

C:\Users\bwalker\Desktop\MWC Quad\arduino-1.0.1\libraries\Wire\utility/twi.h: In member function 'uint8_t TwoWire::requestFrom(uint8_t, uint8_t, uint8_t)':
C:\Users\bwalker\Desktop\MWC Quad\arduino-1.0.1\libraries\Wire\utility/twi.h:43: error: too many arguments to function 'uint8_t twi_readFrom(uint8_t, uint8_t*, uint8_t)'
C:\Users\bwalker\Desktop\MWC Quad\arduino-1.0.1\libraries\Wire\Wire.cpp:85: error: at this point in file
C:\Users\bwalker\Desktop\MWC Quad\arduino-1.0.1\libraries\Wire\utility/twi.h: In member function 'uint8_t TwoWire::endTransmission(uint8_t)':
C:\Users\bwalker\Desktop\MWC Quad\arduino-1.0.1\libraries\Wire\utility/twi.h:44: error: too many arguments to function 'uint8_t twi_writeTo(uint8_t, uint8_t*, uint8_t, uint8_t)'
C:\Users\bwalker\Desktop\MWC Quad\arduino-1.0.1\libraries\Wire\Wire.cpp:140: error: at this point in file



NEVERMIND, Found the note in an old post about using Arduino 1.0

I had same problems! Can you show me how did you compile?
Thanks in advance!

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

Re: GPS integration

Post by jevermeister »

Andras,

as stated by you and as experienced by me:
If you hold the copter while it tries to return home it will become more and more aggressive because it wants to speed up.

Because of the bad thunderstorms tonight I haven't got the time to test (thanks for your PM - I suspected the mag too.)
Imagenina the following situation:
The copter is returning home and there is a tree or a wall or something and I will do a stick input to save the day-

Will the copter fight this input the same way it fights me holding it?

If so, we should consider pausing RTH while stick input is done (same way Alex suspends Baro and MAG)

Nils

Sympster
Posts: 15
Joined: Thu May 24, 2012 1:45 am

Re: GPS integration

Post by Sympster »

EOSBandi wrote:One more issue : I found that the onboard battery of these ebay ublox modules are hardly last more than a couple of days... and since the neo-6M does not have flash onboard, then it forgets the settings.


I've read that you have to charge the onboard battery for about 24 hours. I did so by applying 5 volts to the module via the FTDI connected to my computer. Not sure how long it will keep the settings but it's been two days an counting.

User avatar
mOuchadino
Posts: 15
Joined: Sat Jul 07, 2012 3:51 am

Re: GPS integration

Post by mOuchadino »

asked permission to read around ..... :roll:

flyrobot
Posts: 73
Joined: Thu Apr 05, 2012 3:59 pm

Re: GPS integration

Post by flyrobot »

Hi EOSbandi,

I see the more accurate GPS position should be used bigger external ceramic GPS and using additional DIY antenna like this :
http://autoquad.org/wiki/wiki/autoquad- ... oundplane/
Also
Do we need to do this kind of calibration to get more accurate magnetometer ?
http://autoquad.org/wiki/wiki/autoquad- ... libration/
Have you tried this ?

I hope with the latest firmware and above process will have very accurate GPS position like this :
http://diydrones.com/profiles/blogs/aut ... 6#comments

Thanks,
John

User avatar
brettwal
Posts: 93
Joined: Mon Jun 18, 2012 4:51 pm
Location: Louisiana

Re: GPS integration

Post by brettwal »

Use Arduino 1.0 w/ patches, not 1.01



NEVERMIND, Found the note in an old post about using Arduino 1.0[/quote]
I had same problems! Can you show me how did you compile?
Thanks in advance![/quote]

User avatar
EOSBandi
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary
Contact:

Re: GPS integration

Post by EOSBandi »

flyrobot wrote:Hi EOSbandi,

I see the more accurate GPS position should be used bigger external ceramic GPS and using additional DIY antenna like this :
http://autoquad.org/wiki/wiki/autoquad- ... oundplane/

Yes, I already wrote this earlier, it is recommended to have at least a 25mmx25mm patch antenna. (You can easily get it from a cheap external gps antenna)
flyrobot wrote:Do we need to do this kind of calibration to get more accurate magnetometer ?
http://autoquad.org/wiki/wiki/autoquad- ... libration/
Have you tried this ?

I think this is overkill. the standard dance with noise pointing north and down to 45deg is adequate.
flyrobot wrote:I hope with the latest firmware and above process will have very accurate GPS position like this :
http://diydrones.com/profiles/blogs/aut ... 6#comments

Nope,
Autoquad LEA-6T module to record RAW GPS data and anaylise it after the flight on the ground station. Doing RTK on the fly will requires a Linux based extremly powerfull flight controller

What is expected is someting 2x2m or a little more better....

User avatar
EOSBandi
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary
Contact:

Re: GPS integration

Post by EOSBandi »

jevermeister wrote:Andras,

as stated by you and as experienced by me:
If you hold the copter while it tries to return home it will become more and more aggressive because it wants to speed up.

Because of the bad thunderstorms tonight I haven't got the time to test (thanks for your PM - I suspected the mag too.)
Imagenina the following situation:
The copter is returning home and there is a tree or a wall or something and I will do a stick input to save the day-

Will the copter fight this input the same way it fights me holding it?

If so, we should consider pausing RTH while stick input is done (same way Alex suspends Baro and MAG)

Nils

Yes, it is on the list but I think it will be after 2.1 since it's not a simple change and needs significant amount of testing....

User avatar
Bledi
Posts: 187
Joined: Sat Sep 10, 2011 6:36 pm

Re: GPS integration

Post by Bledi »

I just had an idea for the RESET of home position.
Why not using the same switch as the switch for RTH activation but only when motors are not armed :

Code: Select all

if (rcOptions[BOXGPSHOME]) && !armed)
{
GPS_reset_home_position();
}

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

Re: GPS integration

Post by jevermeister »

Bledi wrote:I just had an idea for the RESET of home position.
Why not using the same switch as the switch for RTH activation but only when motors are not armed :

Code: Select all

if (rcOptions[BOXGPSHOME]) && !armed)
{
GPS_reset_home_position();
}

I think the gyro init is good enough.and it is a trigger not a switch.

User avatar
Bledi
Posts: 187
Joined: Sat Sep 10, 2011 6:36 pm

Re: GPS integration

Post by Bledi »

the problem is not to be good enough, but it's not natural to make a gyro init to reset home position, isn't it ?

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

Re: GPS integration

Post by PatrikE »

I allways calibrate gyros on launchPoint after connecting the battery.
Because i dont like to fly with gyros who is not correct init..
I have tested it and its not healty...

flyrobot
Posts: 73
Joined: Thu Apr 05, 2012 3:59 pm

Re: GPS integration

Post by flyrobot »

EOSBandi wrote:Nope,
Autoquad LEA-6T module to record RAW GPS data and anaylise it after the flight on the ground station. Doing RTK on the fly will requires a Linux based extremly powerfull flight controller

What is expected is someting 2x2m or a little more better....


Thanks for the explanation. Im going to try using my spare MKGPS 2.1 using GPS shield (i have to DIY it), its using LEA 6S.
Will it work ? I will try to compare it with my FMP04.

flyrobot
Posts: 73
Joined: Thu Apr 05, 2012 3:59 pm

Re: GPS integration

Post by flyrobot »

EOSBandi wrote:
flyrobot wrote:Hi EOSbandi,

I see the more accurate GPS position should be used bigger external ceramic GPS and using additional DIY antenna like this :
http://autoquad.org/wiki/wiki/autoquad- ... oundplane/

Yes, I already wrote this earlier, it is recommended to have at least a 25mmx25mm patch antenna. (You can easily get it from a cheap external gps antenna)

I know you have mentioned it, What i meant is GPS shield. Made from plain PCB and it was soldered around the external ceramic gps. Its recommend by MK to use GPS shield to increase GPS signal reception.
Anyone have try it? How was the result?

LuFa
Posts: 160
Joined: Fri Jan 27, 2012 7:56 pm

Re: GPS integration

Post by LuFa »

EosBandi ,

News about the UBX Parser ?
cant wait to test it :mrgreen:

User avatar
EOSBandi
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary
Contact:

Re: GPS integration

Post by EOSBandi »

LuFa wrote:EosBandi ,

News about the UBX Parser ?
cant wait to test it :mrgreen:


Stay tuned, i'll flight test it again tomorrow morning... (testing during the day is impossible due the 40+ degree heat...
Menawhile also coded parser for the MTK 1.6 Binary protocol (ala ArduCopter)....

User avatar
EOSBandi
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary
Contact:

Re: GPS integration

Post by EOSBandi »

flyrobot wrote:
EOSBandi wrote:
flyrobot wrote:Hi EOSbandi,

I see the more accurate GPS position should be used bigger external ceramic GPS and using additional DIY antenna like this :
http://autoquad.org/wiki/wiki/autoquad- ... oundplane/

Yes, I already wrote this earlier, it is recommended to have at least a 25mmx25mm patch antenna. (You can easily get it from a cheap external gps antenna)

I know you have mentioned it, What i meant is GPS shield. Made from plain PCB and it was soldered around the external ceramic gps. Its recommend by MK to use GPS shield to increase GPS signal reception.
Anyone have try it? How was the result?


Well it's not a shiled but rather an enlarged ground plane...
Theoretically a bigger ground plane means bigger gain for the antenna. However, increasing the size of the ground plane will shift the center frequency of the GPS antenna. And a smaller patch antenna has a smaller bandwith which means that a shifted center frequency puts the 1.5754Ghz GPS frequency outside of the usable reception range of the antenna.

Bigger patches (25x25 or 35x35) has bigger bandwith so you can use bigger ground planes... for a small patch antenna a bigger ground plane is worst than a no groundplane.

BrokenRotor
Posts: 9
Joined: Sat Mar 19, 2011 2:05 pm

Re: GPS integration

Post by BrokenRotor »

EOSbandi,

I made an I2C GPS BOB and have a problem attaching to a MiniWii with BMA180, it works on another MiniWii with MPU6050. The GPS feature is working but the ACCEL is locked and does not work as long as the I2C GPS is attached with the BMA180 unit.

I tried modifying the GPS_NAV code, #define I2C_NAV_FLAG_LOW_SPEED_D_FILTER 0x40 register to 0x42, but it did not make a difference. I believe the BMA180 address is set to 0x40 as default.

Any ideas where else to try to make a change?

flyrobot
Posts: 73
Joined: Thu Apr 05, 2012 3:59 pm

Re: GPS integration

Post by flyrobot »

EOSBandi wrote:Well it's not a shiled but rather an enlarged ground plane...
Theoretically a bigger ground plane means bigger gain for the antenna. However, increasing the size of the ground plane will shift the center frequency of the GPS antenna. And a smaller patch antenna has a smaller bandwith which means that a shifted center frequency puts the 1.5754Ghz GPS frequency outside of the usable reception range of the antenna.

Bigger patches (25x25 or 35x35) has bigger bandwith so you can use bigger ground planes... for a small patch antenna a bigger ground plane is worst than a no groundplane.


Hi EOSBandi,

Thank you, its very usefull information. Make me understand. Now i know what GPS HW to use.

John

crashlander
Posts: 506
Joined: Thu May 05, 2011 8:13 am
Location: Slovenia

Re: GPS integration

Post by crashlander »

Hello
I'm trying to get GLB's Rabbit GPS module to work (http://www.goodluckbuy.com/rabbit-gps-r ... oller.html).
But it always resets its settings to 9600 and 1Hz, in less than a minute after disconnecting it from power source. I have charged the battery for 24h (as somebody suggested couple posts back) and no change.
So will it be possible to send init string from flight controller to set those parameters or is there any other solution?

Andrej

Edit: Maybe I'm doing something wrong, because the battery shows 2.38V after charging and 2.4V while charging... and GPS forgets its settings in an instant?!

ReM
Posts: 14
Joined: Sun Jul 08, 2012 12:02 pm
Location: Lithuania

Re: GPS integration

Post by ReM »

I set in I2C_GPS_NAV.ino for MediaTek:

Code: Select all

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Setup
//
void setup() {

  uint8_t i;

  // GPS setup
  Serial.begin(9600);
  delay(2000);
  Serial.println("$PMTK251,115200*1F");  //speed 115200
  delay(1000);
  Serial.begin(115200);
  Serial.println("$PMTK314,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29"); // CGA, RMC, GSA
  Serial.println("$PMTK220,100*2F"); // 10 Hz


I do not know whether this is really true, but this works OK.

Sorry for my bad english...

tsoumelman
Posts: 4
Joined: Sat Jun 23, 2012 9:05 pm

Re: GPS integration

Post by tsoumelman »

Hello
i have problems while i am trying to compile r33 code.I am not familiar with arduino coding.I've made the extra steps needed to get the code compiled in the arduino IDE. I have copied the libraries that are in the Arduino-PID-libs folder (PI and PID controllers)and pasted them into the libraries folder in arduino folder.
I'm planning to use i2c_gps(MTK3339 from Adafruit). So i copied twi.c and twi.h from the Arduino-twi-lib-patch and pasted them to the libraries\wire\utilities folder(i didn't erase the existing twi.c and twi.h files). Then i tried to compile the code, but i had many errors.What have i done wrong?
Guys i NEED YOUR HELP!!!
Thanks in advance!

BrokenRotor
Posts: 9
Joined: Sat Mar 19, 2011 2:05 pm

Re: GPS integration

Post by BrokenRotor »

tsoumelman wrote:Hello
i have problems while i am trying to compile r33 code.I am not familiar with arduino coding.I've made the extra steps needed to get the code compiled in the arduino IDE. I have copied the libraries that are in the Arduino-PID-libs folder (PI and PID controllers)and pasted them into the libraries folder in arduino folder.
I'm planning to use i2c_gps(MTK3339 from Adafruit). So i copied twi.c and twi.h from the Arduino-twi-lib-patch and pasted them to the libraries\wire\utilities folder(i didn't erase the existing twi.c and twi.h files). Then i tried to compile the code, but i had many errors.What have i done wrong?
Guys i NEED YOUR HELP!!!
Thanks in advance!

I had to remove the original twi code from the wire library, renaming did not work, only removing them would allow it to compile.

User avatar
EOSBandi
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary
Contact:

Re: GPS integration

Post by EOSBandi »

USE Arduino 1.0 not 1.0.1

User avatar
brettwal
Posts: 93
Joined: Mon Jun 18, 2012 4:51 pm
Location: Louisiana

Re: GPS integration

Post by brettwal »

ReM wrote:I set in I2C_GPS_NAV.ino for MediaTek:

Code: Select all

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Setup
//
void setup() {

  uint8_t i;

  // GPS setup
  Serial.begin(9600);
  delay(2000);
  Serial.println("$PMTK251,115200*1F");  //speed 115200
  delay(1000);
  Serial.begin(115200);
  Serial.println("$PMTK314,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29"); // CGA, RMC, GSA
  Serial.println("$PMTK220,100*2F"); // 10 Hz


I do not know whether this is really true, but this works OK.

Sorry for my bad english...



Battery is done for, replace it.

User avatar
EOSBandi
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary
Contact:

UBLOX parser

Post by EOSBandi »

Hi folks,
Here is the Ublox binary parser, I flown a couple of packs with it, and seems to work. BUT since Mw2.1 is feature freezed and the sram footprint is not tested, i'm not commiting it to the current _shared trunk, but keep it for post 2.1. You can easily add it to the current code for testing, just add it to the begining of the gps.ino after the #if defined(GPS_SERIAL)..... define
and change the

Code: Select all

 if (GPS_newFrame(SerialRead(GPS_SERIAL))) {

to

Code: Select all

if (UBLOX_GPS_newFrame((uint8_t)SerialRead(GPS_SERIAL))) {


I also attached the settings file got u-blox to binary mode.

Code: Select all

#if defined(UBLOX)

   struct ubx_header {
      uint8_t preamble1;
      uint8_t preamble2;
      uint8_t msg_class;
      uint8_t msg_id;
      uint16_t length;
   };

    struct ubx_nav_posllh {
        uint32_t   time;            // GPS msToW
        int32_t      longitude;
        int32_t      latitude;
        int32_t      altitude_ellipsoid;
        int32_t      altitude_msl;
        uint32_t   horizontal_accuracy;
        uint32_t   vertical_accuracy;
    };
    struct ubx_nav_status {
        uint32_t   time;            // GPS msToW
        uint8_t      fix_type;
        uint8_t      fix_status;
        uint8_t      differential_status;
        uint8_t      res;
        uint32_t   time_to_first_fix;
        uint32_t   uptime;            // milliseconds
    };
    struct ubx_nav_solution {
        uint32_t   time;
        int32_t      time_nsec;
        int16_t      week;
        uint8_t      fix_type;
        uint8_t      fix_status;
        int32_t      ecef_x;
        int32_t      ecef_y;
        int32_t      ecef_z;
        uint32_t   position_accuracy_3d;
        int32_t      ecef_x_velocity;
        int32_t      ecef_y_velocity;
        int32_t      ecef_z_velocity;
        uint32_t   speed_accuracy;
        uint16_t   position_DOP;
        uint8_t      res;
        uint8_t      satellites;
        uint32_t   res2;
    };
    struct ubx_nav_velned {
        uint32_t   time;            // GPS msToW
        int32_t      ned_north;
        int32_t      ned_east;
        int32_t      ned_down;
        uint32_t   speed_3d;
        uint32_t   speed_2d;
        int32_t      heading_2d;
        uint32_t   speed_accuracy;
        uint32_t   heading_accuracy;
    };

    enum ubs_protocol_bytes {
        PREAMBLE1 = 0xb5,
        PREAMBLE2 = 0x62,
        CLASS_NAV = 0x01,
        CLASS_ACK = 0x05,
        CLASS_CFG = 0x06,
      MSG_ACK_NACK = 0x00,
      MSG_ACK_ACK = 0x01,
        MSG_POSLLH = 0x2,
        MSG_STATUS = 0x3,
        MSG_SOL = 0x6,
        MSG_VELNED = 0x12,
        MSG_CFG_PRT = 0x00,
        MSG_CFG_RATE = 0x08,
        MSG_CFG_SET_RATE = 0x01,
      MSG_CFG_NAV_SETTINGS = 0x24
    };
    enum ubs_nav_fix_type {
        FIX_NONE = 0,
        FIX_DEAD_RECKONING = 1,
        FIX_2D = 2,
        FIX_3D = 3,
        FIX_GPS_DEAD_RECKONING = 4,
        FIX_TIME = 5
    };
    enum ubx_nav_status_bits {
        NAV_STATUS_FIX_VALID = 1
    };

    // Packet checksum accumulators
    static uint8_t      _ck_a;
    static uint8_t      _ck_b;

    // State machine state
    static uint8_t      _step;
    static uint8_t      _msg_id;
    static uint16_t   _payload_length;
    static uint16_t   _payload_counter;

    static bool        next_fix;
   
    static uint8_t     _class;

   // do we have new position information?
   static bool      _new_position;

   // do we have new speed information?
   static bool      _new_speed;

   static uint8_t       _disable_counter;

    // Receive buffer
    static union {
        ubx_nav_posllh      posllh;
        ubx_nav_status      status;
        ubx_nav_solution   solution;
        ubx_nav_velned      velned;
        uint8_t   bytes[];
    } _buffer;

void _update_checksum(uint8_t *data, uint8_t len, uint8_t &ck_a, uint8_t &ck_b)
{
   while (len--) {
      ck_a += *data;
      ck_b += ck_a;
      data++;
   }
}

bool UBLOX_GPS_newFrame(uint8_t data)
{
       bool parsed = false;

        switch(_step) {

        case 1:
            if (PREAMBLE2 == data) {
                _step++;
                break;
            }
            _step = 0;
        case 0:
            if(PREAMBLE1 == data) _step++;
            break;

        case 2:
            _step++;
       _class = data;
       _ck_b = _ck_a = data;         // reset the checksum accumulators
            break;
        case 3:
            _step++;
            _ck_b += (_ck_a += data);         // checksum byte
            _msg_id = data;
            break;
        case 4:
            _step++;
            _ck_b += (_ck_a += data);         // checksum byte
            _payload_length = data;            // payload length low byte
            break;
        case 5:
            _step++;
            _ck_b += (_ck_a += data);         // checksum byte

            _payload_length += (uint16_t)(data<<8);
         if (_payload_length > 512) {
            _payload_length = 0;
            _step = 0;
         }
            _payload_counter = 0;            // prepare to receive payload
            break;
        case 6:
            _ck_b += (_ck_a += data);         // checksum byte
         if (_payload_counter < sizeof(_buffer)) {
            _buffer.bytes[_payload_counter] = data;
         }
            if (++_payload_counter == _payload_length)
                _step++;
            break;
        case 7:
            _step++;
            if (_ck_a != data) _step = 0;                  // bad checksum
            break;
        case 8:
            _step = 0;
            if (_ck_b != data)  break;                      // bad checksum
        if (UBLOX_parse_gps())  { parsed = true; GPS_Present = 1;  }
        } //end switch
   return parsed;
}

bool UBLOX_parse_gps(void)
{

    switch (_msg_id) {
    case MSG_POSLLH:
        //GPS_time   = _buffer.posllh.time;
        GPS_coord[LON]   = _buffer.posllh.longitude;
        GPS_coord[LAT]   = _buffer.posllh.latitude;
        GPS_altitude     = _buffer.posllh.altitude_msl / 10/100;      //alt in m
   f.GPS_FIX         = next_fix;
   _new_position = true;
   break;
    case MSG_STATUS:
        next_fix   = (_buffer.status.fix_status & NAV_STATUS_FIX_VALID) && (_buffer.status.fix_type == FIX_3D);
   if (!next_fix) f.GPS_FIX = false;
        break;
    case MSG_SOL:
        next_fix   = (_buffer.solution.fix_status & NAV_STATUS_FIX_VALID) && (_buffer.solution.fix_type == FIX_3D);
   if (!next_fix) f.GPS_FIX = false;
        GPS_numSat   = _buffer.solution.satellites;
        //GPS_hdop      = _buffer.solution.position_DOP;
        //debug[3] = GPS_hdop;
        break;
    case MSG_VELNED:
        //speed_3d   = _buffer.velned.speed_3d;            // cm/s
        GPS_speed = _buffer.velned.speed_2d;            // cm/s
        GPS_ground_course = (uint16_t)(_buffer.velned.heading_2d / 10000);   // Heading 2D deg * 100000 rescaled to deg * 10
   _new_speed = true;
        break;
    default:
        return false;
    }

   // we only return true when we get new position and speed data
   // this ensures we don't use stale data
   if (_new_position && _new_speed) {
      _new_speed = _new_position = false;
      return true;
   }
   return false;
}

#endif  //UBLOX
Attachments
u-blox-config.ublox.zip
(868 Bytes) Downloaded 257 times

LuFa
Posts: 160
Joined: Fri Jan 27, 2012 7:56 pm

Re: GPS integration

Post by LuFa »

Hi EosBandi ,

Great ! can you tell us how to add it into the I2C Code ?

thanks so mutch

User avatar
EOSBandi
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary
Contact:

Re: GPS integration

Post by EOSBandi »

LuFa wrote:Hi EosBandi ,

Great ! can you tell us how to add it into the I2C Code ?

thanks so mutch


I'll integrate it into the i2c code during the upcoming week.

User avatar
EOSBandi
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary
Contact:

MTK Binary parser

Post by EOSBandi »

And here is the Binary parser for MTK based modules with DIYDrones custom firmware (AXN1.30_2389_3329_384.1151100.1_v16.bin)
Replace the

Code: Select all

 if (GPS_newFrame(SerialRead(GPS_SERIAL))) {

with

Code: Select all

 if (MTK_GPS_newFrame((uint8_t)SerialRead(GPS_SERIAL))) {


Also have to switch the gps module to binary mode since the diydrones firmware start at 38400baud and 1Hz update, so you have to change the speed and the baudrate too.

Code: Select all

  SerialOpen(GPS_SERIAL,38400);
    SerialPrint(GPS_SERIAL,"$PMTK220,200*2C\r\n");
    delay(400);
    SerialPrint(GPS_SERIAL,"$PMTK251,115200*1F\r\n")
    SerialPrint(GPS_SERIAL,"$PGCMD,16,0,0,0,0,0*6A\r\n");
    delay(500);
  SerialEnd(GPS_SERIAL);


Code: Select all


#if defined(MTK)
    struct diyd_mtk_msg {
        int32_t      latitude;
        int32_t      longitude;
        int32_t      altitude;
        int32_t      ground_speed;
        int32_t      ground_course;
        uint8_t      satellites;
        uint8_t      fix_type;
        uint32_t   utc_date;
        uint32_t   utc_time;
        uint16_t   hdop;
    };
// #pragma pack(pop)
    enum diyd_mtk_fix_type {
        FIX_NONE = 1,
        FIX_2D = 2,
        FIX_3D = 3
    };

    enum diyd_mtk_protocol_bytes {
        PREAMBLE1 = 0xd0,
        PREAMBLE2 = 0xdd,
    };

    // Packet checksum accumulators
    uint8_t    _ck_a;
    uint8_t    _ck_b;

    // State machine state
    uint8_t    _step;
    uint8_t      _payload_counter;

    // Time from UNIX Epoch offset
    long      _time_offset;
    bool      _offset_calculated;

    // Receive buffer
    union {
        diyd_mtk_msg   msg;
        uint8_t         bytes[];
    } _buffer;

inline long _swapl(const void *bytes)
{
    const uint8_t   *b = (const uint8_t *)bytes;
    union {
        long   v;
        uint8_t b[4];
    } u;

    u.b[0] = b[3];
    u.b[1] = b[2];
    u.b[2] = b[1];
    u.b[3] = b[0];

    return(u.v);
}

bool MTK_GPS_newFrame(uint8_t data)
{
       bool parsed = false;

restart:
        switch(_step) {

            // Message preamble, class, ID detection
            //
            // If we fail to match any of the expected bytes, we
            // reset the state machine and re-consider the failed
            // byte as the first byte of the preamble.  This
            // improves our chances of recovering from a mismatch
            // and makes it less likely that we will be fooled by
            // the preamble appearing as data in some other message.
            //
        case 0:
            if(PREAMBLE1 == data)
                _step++;
            break;
        case 1:
            if (PREAMBLE2 == data) {
                _step++;
                break;
            }
            _step = 0;
            goto restart;
        case 2:
            if (sizeof(_buffer) == data) {
                _step++;
                _ck_b = _ck_a = data;            // reset the checksum accumulators
                _payload_counter = 0;
            } else {
                _step = 0;                     // reset and wait for a message of the right class
                goto restart;
            }
            break;

            // Receive message data
            //
        case 3:
            _buffer.bytes[_payload_counter++] = data;
            _ck_b += (_ck_a += data);
            if (_payload_counter == sizeof(_buffer))
                _step++;
            break;

            // Checksum and message processing
            //
        case 4:
            _step++;
            if (_ck_a != data) {
                _step = 0;
            }
            break;
        case 5:
            _step = 0;
            if (_ck_b != data) {
                break;
            }

            f.GPS_FIX         = _buffer.msg.fix_type == FIX_3D;
            GPS_coord[LAT]      = _buffer.msg.latitude  * 10;   
            GPS_coord[LON]      = _buffer.msg.longitude * 10;   
            GPS_altitude      = _buffer.msg.altitude;
            GPS_speed                   = _buffer.msg.ground_speed;
            GPS_ground_course           = _buffer.msg.ground_course;
            GPS_numSat              = _buffer.msg.satellites;
            //GPS_hdop         = _buffer.msg.hdop;
            parsed = true;
            GPS_Present = 1;
        }
    return parsed;
}
#endif //MTK

LuFa
Posts: 160
Joined: Fri Jan 27, 2012 7:56 pm

Re: GPS integration

Post by LuFa »

did you have change the PID Parameter for the Ublox Parser ?

User avatar
EOSBandi
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary
Contact:

Re: GPS integration

Post by EOSBandi »

LuFa wrote:did you have change the PID Parameter for the Ublox Parser ?


No, But I tested some more pid's Currently i fly with these settings :
PosHold 0.14 0.00
PosHoldRate 2.8 0.10 0.055

Your mileage may be different.... :D

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

Re: GPS integration

Post by jevermeister »

Andras,
can you sum up the parameters for GPS`? The thread is quit long.
We should update the FAQ ASAP, I will contact Alex for this.

Nils

ReM
Posts: 14
Joined: Sun Jul 08, 2012 12:02 pm
Location: Lithuania

Re: GPS integration

Post by ReM »

brettwal wrote:
ReM wrote:I set in I2C_GPS_NAV.ino for MediaTek:

Code: Select all

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Setup
//
void setup() {

  uint8_t i;

  // GPS setup
  Serial.begin(9600);
  delay(2000);
  Serial.println("$PMTK251,115200*1F");  //speed 115200
  delay(1000);
  Serial.begin(115200);
  Serial.println("$PMTK314,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29"); // CGA, RMC, GSA
  Serial.println("$PMTK220,100*2F"); // 10 Hz


I do not know whether this is really true, but this works OK.

Sorry for my bad english...



Battery is done for, replace it.


No, my GPS module without battery...

User avatar
EOSBandi
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary
Contact:

Re: GPS integration

Post by EOSBandi »

jevermeister wrote:Andras,
can you sum up the parameters for GPS`? The thread is quit long.
We should update the FAQ ASAP, I will contact Alex for this.

Nils

It covers most part... will be updatet along with 2.1 release
http://code.google.com/p/i2c-gps-nav/do ... tation.pdf

tsoumelman
Posts: 4
Joined: Sat Jun 23, 2012 9:05 pm

Re: GPS integration

Post by tsoumelman »

BrokenRotor wrote:
tsoumelman wrote:Hello
i have problems while i am trying to compile r33 code.I am not familiar with arduino coding.I've made the extra steps needed to get the code compiled in the arduino IDE. I have copied the libraries that are in the Arduino-PID-libs folder (PI and PID controllers)and pasted them into the libraries folder in arduino folder.
I'm planning to use i2c_gps(MTK3339 from Adafruit). So i copied twi.c and twi.h from the Arduino-twi-lib-patch and pasted them to the libraries\wire\utilities folder(i didn't erase the existing twi.c and twi.h files). Then i tried to compile the code, but i had many errors.What have i done wrong?
Guys i NEED YOUR HELP!!!
Thanks in advance!

I had to remove the original twi code from the wire library, renaming did not work, only removing them would allow it to compile.

Thanks a lot!
And thanks EOS too!

taka
Posts: 2
Joined: Mon Jul 09, 2012 3:19 am

Re: GPS integration

Post by taka »

I connect a Gstar (3329) serial gps unit into my mega board port 2, i do get the gps data and number of satetille fixed, however the comm baud is only 9600, any higher i changed will not get any gps data on my mega/gui.

How can i find out if my gps is 10 hz or not ? How to increase the comm baud rate?
All others functions is ok as my quad is flying well with the mega board now. Gps dont seems to work, i m on multiwii 2.1_964 currently.

Thanks

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 »

is it a bug ??
arduino 2560, flyduino megaboard
fmp04 10hz,115200 flyduino gpsbob
on gui with r964 when you unplug (by accident) the gps serial wire, informations still appear on gui...
can we guess those informations will also stay in mwc during flight ?
if it does it can crash your copter no ?

I'm not sure about it but it should be also safe to 'reset' gps data when you reset home position no ?
something like this maybe...

Code: Select all

      if (rcData[YAW] < MINCHECK && rcData[PITCH] < MINCHECK && !f.ARMED) {
        if (rcDelayCommand == 20) {
          calibratingG=400;
          #if GPS
            GPS_reset_home_position(); //fr3d
              f.GPS_FIX = 0;
              GPS_numSat = 0;
              GPS_coord[LAT] = 0;
              GPS_coord[LON] = 0;
              GPS_altitude = 0;
              GPS_speed = 0;
          #endif
        }


and maybee to add a counter of good or "always same" GGA & RMC frames
like it is in the failsafe dectection procedure...

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

Re: GPS integration

Post by shikra »

Nervously tested RTH on a big twitchy hexa yesterday. It's very overpowered and is climbing on less than 20% throttle so wasn't sure how it would work.

All default untuned. Only magdec calibrated - worked very well except a little circling at home
Engaged RTH 2m above the ground. Tracked back very well at nice speed. +/-1m on height
Windy day
It flies it better than me.....

Nice Job EOS and the AP crew

User avatar
EOSBandi
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary
Contact:

Re: GPS integration

Post by EOSBandi »

fr3d wrote:is it a bug ??
arduino 2560, flyduino megaboard
fmp04 10hz,115200 flyduino gpsbob
on gui with r964 when you unplug (by accident) the gps serial wire, informations still appear on gui...
can we guess those informations will also stay in mwc during flight ?
if it does it can crash your copter no ?

I'm not sure about it but it should be also safe to 'reset' gps data when you reset home position no ?
something like this maybe...

Code: Select all

      if (rcData[YAW] < MINCHECK && rcData[PITCH] < MINCHECK && !f.ARMED) {
        if (rcDelayCommand == 20) {
          calibratingG=400;
          #if GPS
            GPS_reset_home_position(); //fr3d
              f.GPS_FIX = 0;
              GPS_numSat = 0;
              GPS_coord[LAT] = 0;
              GPS_coord[LON] = 0;
              GPS_altitude = 0;
              GPS_speed = 0;
          #endif
        }


and maybee to add a counter of good or "always same" GGA & RMC frames
like it is in the failsafe dectection procedure...



Resetting gps data on home position reset is meaningless, since you have to have good gps data for setting home position...a failsame timer is a good idea, now if you disconnect the serial GPS, the last pos and fix data remained stalled.... we a simple timer could reset the f.GPS_FIX to zero... all other gps functions are based on the f.GPS fix flag......

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

Re: GPS integration

Post by jevermeister »

Isn't there a heartbeat signal present?

You could definetly include that into I2C GPS

Nils

User avatar
EOSBandi
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary
Contact:

Re: GPS integration

Post by EOSBandi »

jevermeister wrote:Isn't there a heartbeat signal present?

You could definetly include that into I2C GPS

Nils

I2c gps has this feature, when no GPS signal is detected for 1 sec, then it will ouput NO fix... so I just have to port this to MW serial GPS code....

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

Re: GPS integration

Post by jevermeister »

EOSBandi wrote:
jevermeister wrote:Isn't there a heartbeat signal present?

You could definetly include that into I2C GPS

Nils

I2c gps has this feature, when no GPS signal is detected for 1 sec, then it will ouput NO fix... so I just have to port this to MW serial GPS code....


OK - Nice to know you are alway prepared Andras ;-).

I had the weirdest issue today. I tested Coming home again today and hat slight wind from west.
Walking test were okay and plausible - I thought I had a mag issue.

If I switched RTH while the copter was in the west everything was okay.

If I switched it on while it has to fight the wind to rth it was twitchy as hell and flying circles and tries to run away.
I checked again in gui and noticed that, when I tilt the copter the mag goes crazy - so I rechecked the amg orientation, compared it to other boards etc. everything was set up correctly. When I reflasehd MWC2.0 everything was fine. So I thought it was an issue with 2.1pre.

After reflashing MWC2.1pre the issue was gone.


Dafuq? What does that mean?? Is there something wrong with the eeprom and the mag data?
I did some code tests the last days so flashed and reflashed 2.1pre over and over again...

Nils

ps.: Andras, do you need some Buzzercodes for GPS? I have coded a new coded buzzerpattern. Have a lock

crashlander
Posts: 506
Joined: Thu May 05, 2011 8:13 am
Location: Slovenia

Re: GPS integration

Post by crashlander »

jevermeister wrote:I had the weirdest issue today. I tested Coming home again today and hat slight wind from west.
...
f I switched it on while it has to fight the wind to rth it was twitchy as hell and flying circles and tries to run away.


Sounds very much like: viewtopic.php?f=8&t=649&start=1030#p17821
In my case also mag (by itself) works as expected only GPS functions (especialy RTH) in wind are strange.

Post Reply