GPS - Magnetic declination help

Post Reply
luanlmd
Posts: 22
Joined: Mon Jan 23, 2012 8:03 pm

GPS - Magnetic declination help

Post by luanlmd »

My quad isn't getting much stable with the GPS, it pretty much dance in a range about 5m non stoping.
I think it is the magnetic declination calc I'm not getting right

Formula is: Convert the degree+minutes into decimal degree by ==> degree+minutes*(1/60)

Data is: Image
Well since it is negative, I dont really know where the negative part play its role, if I set the degrees to negative or the result of the calc

I've tried:
20+48*(1/60)
-20+48*(1/60)
-(20+48*(1/60))

Nothing looks to make it stable, When using the GUI I notice GPS speed always going from 1 to 10 even when laying the quad on the floor. Even home distance changes.
I have no idea what am I doing wrong, help!!!!

bill516
Posts: 334
Joined: Sun Aug 07, 2011 12:27 pm

Re: GPS - Magnetic declination help

Post by bill516 »

http://www.columbiaweather.com/resource ... direction/ this might help you. The calculation on this site seems different to what you have written and different to what I have been led to believe too.

What you need to enter in the sketch is the numbers where it says Magnetic declination: 20 deg 48' WEST on that pic you posted with a minus sign in front of it.

If you are inside a building or surround by buildings I hav3e been told that signal can bounce around which will give you the movement you are seeing, if you can get outside in a clear space it should settle down.

Dave66
Posts: 16
Joined: Sun Jul 22, 2012 9:25 pm
Location: NH USA

Re: GPS - Magnetic declination help

Post by Dave66 »

luanlmd wrote:My quad isn't getting much stable with the GPS, it pretty much dance in a range about 5m non stoping.
I think it is the magnetic declination calc I'm not getting right

I've tried:
20+48*(1/60)
-20+48*(1/60)
-(20+48*(1/60))

Nothing looks to make it stable, When using the GUI I notice GPS speed always going from 1 to 10 even when laying the quad on the floor. Even home distance changes.
I have no idea what am I doing wrong, help!!!!


I don't think you can just add degs to min and get a correct answer. You have to convert the degs to min then add them together. 20 min x 60 to convert degs to min = 1200, then add remaining min, 1200+48=1248 total min, now multiply by (1/60), so 1248x0.01667=20.8. I would enter -20.8f in the sketch. This works for Budapest Hungary given in the example. Not sure if this would cause a problem in PH because no navigation is being calculated.

luanlmd
Posts: 22
Joined: Mon Jan 23, 2012 8:03 pm

Re: GPS - Magnetic declination help

Post by luanlmd »

I tried bill516 idea and the quad got a little better.
Tested it in a open area and sometimes things were good until I turn on pos hold with the quad in movement or home pos while too far away, the quad speeds up back to the right position but pass it, then starts flying around in a big circle like 20m range and then a smaller circle and smaller until it gets to the right point.
It just doesn't look safe to use at this point.
I'm gonna try Daves calc and report back.

BTW has dev version improved GPS stuff over 2.1 already?

bill516
Posts: 334
Joined: Sun Aug 07, 2011 12:27 pm

Re: GPS - Magnetic declination help

Post by bill516 »

http://diydrones.com/profiles/blogs/ac2 ... -tuner-sim PID tuning simulator. Cant take the credit for it as its from the EOSBandi GPS setup document. I have updated the GPS functions using code from EOSBandi and NEB. SEarch for GPS.zip from EOSBandi on this site and then add the following into the stated places. I found that it improved my GPS even in the house


1. replace gps.ino with gps.zip

2. add to gps.ino some of this code already exists find the first line and add up to and including #define DIGIT_TO_VAL


// This code is used for parsing NMEA data
#if defined(GPS_SERIAL)

#if !defined(UBLOX)

/* Alex optimization
The latitude or longitude is coded this way in NMEA frames
.....
This function converts this format in a unique unsigned long where 1 degree = 10 000 000

EOS increased the precision here, even if we think that the gps is not precise enough, with 10e5 precision it has 76cm resolution
with 10e7 it's around 1 cm now. Increasing it further is irrelevant, since even 1cm resolution is unrealistic, however increased
resolution also increased precision of nav calculations
*/
/////////////// NEB (Carlonb) from Eosbandi idea
// Autosetup for serial GPS MTK 3329 chipset
// The strange think is that the new serial speed update will be accepted only if the GSP chiset is in default state at 9600 bps ???!!!
// My GPS will go back in default setttings after 2 days unpowered.
// With this, if GPS is in default state, OK, will be updated with new param, if not, no problem, will not accept these commands and nothig happens,
// simply means that already has these new parameters (115200bps, 10Hz, GGA and RMC NMEA strings).
void NMEA_MTK_NEB_init(void) // NEB
{
const unsigned long baudrates[5] = {9600U, 19200U, 38400U, 57600U, 115200U};
//const unsigned long baudrates[4] = {9600U, 19200U, 38400U, 57600U};

//#define NMEA_MTK_RESET "$PMTK104*37\r\n" // Reset to factory default
#define NMEA_MTK_STRING "$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28\r\n" // Command for only GGA & RMC NMEA strings

#define NMEA_MTK_SET_SPEED "$PMTK251,115200*1F\r\n" // 115200 bps
//#define NMEA_MTK_SET_SPEED "$PMTK251,57600*2C\r\n" // 57600 bps
//#define NMEA_MTK_SET_SPEED "$PMTK251,9600*17\r\n" // 9600 bps

#define NMEA_MTK_SET_HZ "$PMTK300,100,0,0,0,0*2C\r\n" // 10Hz
//#define NMEA_MTK_SET_HZ "$PMTK300,200,0,0,0,0*2F\r\n" // 5Hz
//#define NMEA_MTK_SET_HZ "$PMTK300,1000,0,0,0,0*1C\r\n" // 1Hz

for (uint8_t i=0; i<6; i++) { // Carlonb from idea of EOSBANDI (autosearch of default baud rate)
SerialOpen(GPS_SERIAL,baudrates[i]);
delay(200);
SerialWriteBuffer(GPS_SERIAL, (uint8_t *)NMEA_MTK_SET_SPEED, sizeof(NMEA_MTK_SET_SPEED)-1); // NEB set GPS serial speed
delay(200);
SerialEnd(GPS_SERIAL);
delay(200);
}

SerialOpen(GPS_SERIAL,GPS_BAUD); // NEB changed 57600 with GPS_BAUD
delay(200);
SerialWriteBuffer(GPS_SERIAL, (uint8_t *)NMEA_MTK_SET_HZ, sizeof(NMEA_MTK_SET_HZ)-1); // NEB set GPS refresh rate (Hz)
delay(200);
SerialWriteBuffer(GPS_SERIAL, (uint8_t *)NMEA_MTK_STRING, sizeof(NMEA_MTK_STRING)-1); // NEB set GPS for GGA & RMC NMEA strings only
delay(200);
SerialEnd(GPS_SERIAL);
delay(100);
}

void SerialWriteBuffer(uint8_t port, uint8_t *buffer, uint8_t size)
{
uint8_t i;
uint8_t *ptr;

ptr = buffer;

for (i=0;i<size;i++) {
SerialWrite(port,*ptr);
ptr++;
}
}
/////////////// NEB mod end

#define DIGIT_TO_VAL(_x) (_x - '0')
.........................................................................

3. add to multiwii.ino

#if defined(GPS_SERIAL)

///////////// EOSBANDI
#if defined(UBLOX)
UBLOX_init();
delay(200);
#endif

#if defined(MTK)
MTK_init();
delay(200);
#endif

#if defined(NMEA) // NEB added for NMEA MTK setup
NMEA_MTK_NEB_init();
delay(200);
#endif
///////////// EOSBANDI

SerialOpen(GPS_SERIAL,GPS_BAUD);

#endif

....................................................................................
4. add to config.h

#define GPS_SERIAL 2 // should be 2 for flyduino v2. It's the serial port number on arduino MEGA
#define GPS_BAUD 115200 // 57600

#define NMEA
//#define UBLOX
//#define MTK

#define GPS_LEAD_FILTER

//#define GPS_FILTERING
//#define NAV_SLEW_RATE 30

Dave66
Posts: 16
Joined: Sun Jul 22, 2012 9:25 pm
Location: NH USA

Re: GPS - Magnetic declination help

Post by Dave66 »

bill516 wrote:http://diydrones.com/profiles/blogs/ac2-loiter-tuner-sim PID tuning simulator. Cant take the credit for it as its from the EOSBandi GPS setup document. I have updated the GPS functions using code from EOSBandi and NEB. SEarch for GPS.zip from EOSBandi on this site and then add the following into the stated places. I found that it improved my GPS even in the house


1. replace gps.ino with gps.zip

2. add to gps.ino some of this code already exists find the first line and add up to and including #define DIGIT_TO_VAL


I am using a Crius SE with the I2C GPS NAV Module/UBLOX CN-06 Receiver and my GPS works pretty well, but always looking for improvement. I have searched this site but cannot locate EOSbandi's GPS.zip, any help? I have found many references to it but can't find the actual file.
In my post above I offered a way to get proper Mag declination, in the example given (EOSbandi's home, Budapest Hungry) it seams to work, if it's not correct let me know. I have read many of your posts about diff subjects and you have been very helpful, thanks for that.

bill516
Posts: 334
Joined: Sun Aug 07, 2011 12:27 pm

Re: GPS - Magnetic declination help

Post by bill516 »

GPS.zip
(13.96 KiB) Downloaded 334 times


Sorry I havnt replied before but I've been to Scotland (inlaws) but I've added the gps.zip should have done that before.

Dave66
Posts: 16
Joined: Sun Jul 22, 2012 9:25 pm
Location: NH USA

Re: GPS - Magnetic declination help

Post by Dave66 »

Thanks bill, I"ll try it this weekend.

rotary65
Posts: 30
Joined: Mon Jun 25, 2012 11:27 am

GPS - Magnetic declination help

Post by rotary65 »

@luanlmd: MAG shouldn't make it "dance around", just maybe point in the wrong direction. Sounds like tuning to me. EOSBandi wrote a nice explanation of the GPS parameters. It's a good read.

Dave66
Posts: 16
Joined: Sun Jul 22, 2012 9:25 pm
Location: NH USA

Re: GPS - Magnetic declination help

Post by Dave66 »

bill516 wrote:
GPS.zip


I know very little about software. After replacing the GPSino with the zip do I make all of these changes in GPSino even though I am using a UBLOX hooked up through the i2c connector? The additional code mostly refers to MTK and serial stuff. And in step 4 do I leave "define UBLOX" commented and "#define NMEA" uncommented ?

Thanks for your help.

bill516
Posts: 334
Joined: Sun Aug 07, 2011 12:27 pm

Re: GPS - Magnetic declination help

Post by bill516 »

Ha i2c that means I have sent you up the wrong path, I didnt realise you were using i2c. The info I gave is for serial GPS so it wont work for you, you need to search for the i2c stuff which is not easy as it is all mixed in with the serial stuff. May be easier to search for UBLOX than i2c at least you will get the right info for your sensor.

Dave66
Posts: 16
Joined: Sun Jul 22, 2012 9:25 pm
Location: NH USA

Re: GPS - Magnetic declination help

Post by Dave66 »

Like I said in earlier post, my GPS works fine but always looking for improvement. Thanks again.

Post Reply