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
msev
Posts: 186
Joined: Thu Apr 14, 2011 11:49 am

Re: GPS integration

Post by msev »

I2C GPS module according to EOSBandi
Where can I find the connection diagram between the GPS and secondary arduino? To see how sensei EOSBandi made it :D..
Is it like this rx on arduino -> rx on gps, tx on arduino -> tx on gps, and off course, powering both units?

Alexinparis wrote:Hi,

GPS RTH and PH is now fully implemented for Serial GPS (not I2C) in the current code


Wait so this means no more secondary arduino board? Or am I missunderstanding?

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

Re: GPS integration

Post by Alexinparis »

Hi,
there are 2 options right now:

1) I2C GPS
This is one solution from EOSBandi with a second arduino:

MW Board <-I2C-> arduino board with EOSBandi code <-Serial-> GPS device

main advantage: it can be use on any MW compatible board as it's just an I2C extension to add, and it offloads also some costly computations.

2) Serial GPS:

MW Board <-Serial-> GPS device

But it requires at the moment an arduino MEGA because you need a free Serial port.

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

Re: GPS integration

Post by LuFa »

great Alex !

Did you plan also to add GPS PosHold for i2c GPS ?

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

Re: GPS integration

Post by rbirdie001 »

Hi Alex,
sorry, now I'm completely confused. :? Is RTH and PH for I2C GPS currently working in the Dev_0120225 or not?
Today I was testing it and I felt it doesn't work but due to limited place I wasn't sure.
If not, is there a plan to add it also for I2C GPS?
Thanks!
Roman

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

Re: GPS integration

Post by Alexinparis »

For I2C GPS: there is currently a special hack to reset the home position for GPS (AUX4 > 1800), and allow PH via the use of RTH.

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

Re: GPS integration

Post by karsten j. »

Hello.

I´ve read this complete thread and now there´re a lot of questions.
First: the link to Eosbandi Software for the second arduino (http://code.google.com/p/i2c-gps-nav/) doesn´t work. I cannot found the software on this page.
second: Could anybody tell me how to connect the second arduino pro mini to the main arduino..
is it correct, that I have to solder like this: from GPS to 2nd Arduino : Rx->RX, Tx->Tx, ? Where must I connect GND and 12V ?
How do I have to connect (what cables) the 2nd Arduino to the 1st Arduino ???

greets Karsten

Kayle
Posts: 141
Joined: Sun Feb 13, 2011 6:45 pm

Re: GPS integration

Post by Kayle »

@Karsten J.

The Software is already on the page. Look at source -> than browse and then Trunk. Or take this:

http://code.google.com/p/i2c-gps-nav/source/browse/trunk/I2C_GPS_NAV/I2C_GPS_NAV.ino

You must connect SCA and SCL not RX and TX because it´s I2C and not serial. And of course your second Arduino needs Power. 5V and GND.

greetings
Kayle
(bin auch in der FPV Community :D )

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

Re: GPS integration

Post by rbirdie001 »

Alexinparis wrote:For I2C GPS: there is currently a special hack to reset the home position for GPS (AUX4 > 1800), and allow PH via the use of RTH.


Thanks!
I was already pointed to "set home position" code for I2C GPS, adjusted it for me and tested it, this works for me.
As I can't understand the code good enough, please one more "buletproof" (germans say "idiotenfest" :) ) answer:
Do I understand correctly, that for I2C GPS the RTH function works REGULAR WAY using ANY checkbox (i.e. not one e.g. AUX4 firmly assigned in the code) from GUI and PH currently doesn't work? (PH then can be of course hacked by setting new home where I need to fix the copter and activating RTH. OK?)
Thanks and sorry if I'm sometimes not very comprehensive.
Roman

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

Re: GPS integration

Post by mbrak »

hi roman

the german says "idiotensicher" :)

the "aux(4)" is only for setting a new homepostion during flight.
imho the return-positon is not always there where you arm the copter. original the copter or better the software stores your postion after arming the copter. thats the return ore home-point.
with the aux(4)-mod you can reassign the homepoint during flight. this also works with serial gps!

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

Re: GPS integration

Post by rbirdie001 »

mbrak wrote:hi roman

the german says "idiotensicher" :)

the "aux(4)" is only for setting a new homepostion during flight.
imho the return-positon is not always there where you arm the copter. original the copter or better the software stores your postion after arming the copter. thats the return ore home-point.
with the aux(4)-mod you can reassign the homepoint during flight. this also works with serial gps!


Sorry, don't remember German words exactly ;) , thanks for correcting.
Setting home position is clean to me and works, but as I noticed some posts regarding RTH and PH discussing that something works on serial GPS but not on I2C yet and additionally this "hardwired" AUX4 "SET HOME" is obviously just temp solution, I'm simply asking what is current functionality for RTH and PH with I2C GPS to know what to expect during testing.
I already did some tests and I got feeling that activating PH and RTH by GUI checkbox and assigned switch does nothing so I want to be sure before another testing...
Roman

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

Re: GPS integration

Post by mbrak »

hi roman

i thing you have to contact EOSBandi ! He is the man behind I2C GPS and he can answer your questions exactly.

Alex wrote that the funktionality of both variants will be the same in some time. in the past POS Hold was only possible with the I2C solution not with serial GPS. The only hack to do this was setting a new homeposition during flight and turn on RTH!
now alex has implemented the Pos Hold to serial GPS code so the aux(4)hack is not needed. But i implemented it to reassign a possible new landing point during flight.

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

Re: GPS integration

Post by EOSBandi »

Quick note,
Sorry guys, but I'm definitely offline till 15th march... time to move to a new home.. :D

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

Re: GPS integration

Post by jevermeister »

Alex,
since andras is moving to a new home,
can you give some info about the direction to home?
what is the relation of the arrow i am not shure...
I did some walking test with copter, notebook and gui but the arrow seems npt plausible to me, but the distance was right, also the copter seems to try to return to home or hold position.

nils

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

Re: GPS integration

Post by nhadrian »

Oh, the same result as for me!
I'm quite sure the GPS code calculates the direction from home to current position and not the current position to home.
If I'll have some time at weekend, I'll try to understand the GPS calculation and find the origin of this problem. But it'd be much easier for someone who knows the GPS calculations..... :S

BR
Adrian

update: I think I found the origin of the direction problem:

Code: Select all

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)));
  if (lat1 != lat2)
    *bearing = 180/PI*(atan2(dLon,dLat));


Code: Select all

        //Get distance and direction to _target location
        GPS_distance(_target.lat,_target.lon,i2c_dataset.gps_loc.lat,i2c_dataset.gps_loc.lon, &i2c_dataset.distance, &i2c_dataset.direction


As you can see, lat,lon1 is the target (home) and lat,lon2 is the current position. So ie. dxx is the current position - target position, so this value points from home to target.

I think this should be:

Code: Select all

void GPS_distance(int32_t lat1, int32_t lon1, int32_t lat2, int32_t lon2, uint16_t* dist, int16_t* bearing) {
  float dLat = ((lat1 - lat2));                                    // difference of latitude in 1/100000 degrees
  float dLon = ((lon1 - lon2)) * cos(lat1*(PI/180/100000.0));      // difference of longitude in 1/100000 degrees
  *dist = 6372795 / 100000.0 * PI/180*(sqrt(sq(dLat) + sq(dLon)));
  if (lat1 != lat2)
    *bearing = 180/PI*(atan2(dLon,dLat));


and in multiwii.ino go back to this:

Code: Select all

      errorAngle = constrain(2*rcCommand[axis] - GPS_angle[axis],-500,+500) - angle[axis] + accTrim[axis]; //16 bits is ok here


Could someone confirm my idea?
I'll try this way at weekend!!!!!
Last edited by nhadrian on Mon Mar 05, 2012 9:42 pm, edited 1 time in total.

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

Re: GPS integration

Post by Wayne »

On my MEGA 2560 controller I have wired in my HK/Apache GPS antenna to 3.3V, Gnd, and Serial 2.
When I set the Baud rate to 38400 I can see ‘PKT’ flash in the new GUI so I’m thinking its working. No other baud rate makes the ‘PKT’ flash.
I cannot hook it to a computer outside but when the stops flashing indicating a lock. (it just keeps flashing in the house)
The moment it stops flashing everything freezes. If unarmed it wont arm, if armed it wont throttle up or disarm.
With my good DVM I can see that it is not a V supply problem.
Ant. and Ard. spec sheets say mA are ok too.
Could it be that I need a pullup resister or LLC to get the antennas data up to 5V?
Anyone tried the HK/Apache antenna on 5V? (without letting the magic smoke out)

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

Re: GPS integration

Post by jevermeister »

You are right if you say, the distance is measured from target to copter.
But the arguments of the atan2 function are swapped so this error is if you want to call it that is being corrected there. one could correct this for the sake of readability bit the behavior should not change.
Right alex?
nhadrian wrote:Oh, the same result as for me!
I'm quite sure the GPS code calculates the direction from home to current position and not the current position to home.
If I'll have some time at weekend, I'll try to understand the GPS calculation and find the origin of this problem. But it'd be much easier for someone who knows the GPS calculations..... :S

BR
Adrian

update: I think I found the origin of the direction problem:

Code: Select all

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)));
  if (lat1 != lat2)
    *bearing = 180/PI*(atan2(dLon,dLat));


Code: Select all

        //Get distance and direction to _target location
        GPS_distance(_target.lat,_target.lon,i2c_dataset.gps_loc.lat,i2c_dataset.gps_loc.lon, &i2c_dataset.distance, &i2c_dataset.direction


As you can see, lat,lon1 is the target (home) and lat,lon2 is the current position. So ie. dxx is the current position - target position, so this value points from home to target.

I think this should be:

Code: Select all

void GPS_distance(int32_t lat1, int32_t lon1, int32_t lat2, int32_t lon2, uint16_t* dist, int16_t* bearing) {
  float dLat = ((lat1 - lat2));                                    // difference of latitude in 1/100000 degrees
  float dLon = ((lon1 - lon2)) * cos(lat1*(PI/180/100000.0));      // difference of longitude in 1/100000 degrees
  *dist = 6372795 / 100000.0 * PI/180*(sqrt(sq(dLat) + sq(dLon)));
  if (lat1 != lat2)
    *bearing = 180/PI*(atan2(dLon,dLat));


and in multiwii.ino go back to this:

Code: Select all

      errorAngle = constrain(2*rcCommand[axis] - GPS_angle[axis],-500,+500) - angle[axis] + accTrim[axis]; //16 bits is ok here


Could someone confirm my idea?
I'll try this way at weekend!!!!!

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

Re: GPS integration

Post by mbrak »

hi

just tested MW2.0pre1 with the new funktions. normal flying, mag-mode and acc mode working super soft and smooth. mega 11 bit pwm?

the gps pos hold is the problem still now. setting a new home position, lift up the copter to about 5 meters and activating gps pos hold the copter comes backwards to me. more than 10 meters and no stop!
whats the problem? 3d fix was set! i will have to test after charging lipo.

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

Re: GPS integration

Post by jevermeister »

There seems to be a bad mistake in the formula that computes the angle to the target coordinates. the behavior seems to ne opposite of what it shoild be. i computed it on paper and it does not seem right.

Nils

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

Re: GPS integration

Post by Wayne »

Update…
I have reloaded a fresh copy of 2.0.PV1.
Mega still freezes at the moment GSP lock is acquired.

Loaded MWWinGUI into a friends laptop this morning.
I can see that it is finding satellites, 3, 4, 5 once.
The moment the GUI satellite turns green everything freezes.

I’m now going to wire up a 3.3v regulator and get the GPS antenna off the MEGAs 3.3v supply.

Edit: Its not a power supply problem. Freezes even with its own 3.3V supply.
Anyone else have SpekSat and GPS working?

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

Re: GPS integration

Post by jevermeister »

Code: Select all

 if (lat1 != lat2)
    *bearing = 180/PI*(atan2(dLon,dLat));
  else
    *bearing = 0;


The else clause is not correct I believe.
If I have a longitude difference and no lat difference the correct bearing would be 90° not 0°.

Alex, correct me If I am wrong but I think this is a mistake, although, it is very unlikely that you hit exactly this point.

Also bearing to hom e is more a bearing from home. It seems to be used correctly but wouldn't it be more logical to use the bearing from the copters nose to home?`

bearing_from_home-180-copter_bearing, this is the bearing from copters nose to home. What do you think!?

I just did the math in theory so I might be absolutely wrong.

Nils

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

Re: GPS integration

Post by Wayne »

That’s it. I have been flying SpekSat from day one. I know SpekSat works.
I (MEGA) freezes after GPS Lock only when I uncomment ‘//#define SPEKTRUM 1024’.
Its not the hardware as I left SpekSat plugged in.

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

Re: GPS integration

Post by mbrak »

hi wayne

seems to be your gps.
my flyduino gps works great.......except that it does not find the way back home. but that is another story :)

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

Re: GPS integration

Post by Wayne »

It may be my HK/Apache GPS....
Before it freezes, on the WinGui I can see the number of satellites change.
Just after it turns green it has 3 or four sats. fixed and shows dist. to home, once 5M, once 0M.

I’m going to go and barrow the laptop again and see if GPS is working without SpekSat defined.

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

Re: GPS integration

Post by Wayne »

OK it only freezes when the HK/Apache GPS is plugged in.
I did let HK/Apache stop flashing outside while serial two was unplugged.
Then I ran inside hooked MEGA to WinGUI and see that everything was working UNTILL I plugged in serial 2. When plugged in the satellite in WinGUI went from red to green, # of satts. went from 0 to 3 then it froze.

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

Re: GPS integration

Post by Alexinparis »

nhadrian wrote:Oh, the same result as for me!
I'm quite sure the GPS code calculates the direction from home to current position and not the current position to home.
If I'll have some time at weekend, I'll try to understand the GPS calculation and find the origin of this problem. But it'd be much easier for someone who knows the GPS calculations..... :S

BR
Adrian

update: I think I found the origin of the direction problem:

Code: Select all

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)));
  if (lat1 != lat2)
    *bearing = 180/PI*(atan2(dLon,dLat));


Code: Select all

        //Get distance and direction to _target location
        GPS_distance(_target.lat,_target.lon,i2c_dataset.gps_loc.lat,i2c_dataset.gps_loc.lon, &i2c_dataset.distance, &i2c_dataset.direction


As you can see, lat,lon1 is the target (home) and lat,lon2 is the current position. So ie. dxx is the current position - target position, so this value points from home to target.

I think this should be:

Code: Select all

void GPS_distance(int32_t lat1, int32_t lon1, int32_t lat2, int32_t lon2, uint16_t* dist, int16_t* bearing) {
  float dLat = ((lat1 - lat2));                                    // difference of latitude in 1/100000 degrees
  float dLon = ((lon1 - lon2)) * cos(lat1*(PI/180/100000.0));      // difference of longitude in 1/100000 degrees
  *dist = 6372795 / 100000.0 * PI/180*(sqrt(sq(dLat) + sq(dLon)));
  if (lat1 != lat2)
    *bearing = 180/PI*(atan2(dLon,dLat));


and in multiwii.ino go back to this:

Code: Select all

      errorAngle = constrain(2*rcCommand[axis] - GPS_angle[axis],-500,+500) - angle[axis] + accTrim[axis]; //16 bits is ok here


Could someone confirm my idea?
I'll try this way at weekend!!!!!


Hi,
I think you are probably right somewhere.
target and current position are inverted in the calculation.
But if you invert things here, the correction should be:
errorAngle = constrain(2*rcCommand[axis] + GPS_angle[axis],-500,+500) - angle[axis] + accTrim[axis]; //16 bits is ok here

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

Re: GPS integration

Post by Alexinparis »

Wayne wrote:OK it only freezes when the HK/Apache GPS is plugged in.
I did let HK/Apache stop flashing outside while serial two was unplugged.
Then I ran inside hooked MEGA to WinGUI and see that everything was working UNTILL I plugged in serial 2. When plugged in the satellite in WinGUI went from red to green, # of satts. went from 0 to 3 then it froze.


It's possible also that the code is not robust enough and don't like the NMEA frame of your GPS once the sats are ok, causing a code crash.

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

Re: GPS integration

Post by Alexinparis »

jevermeister wrote:

Code: Select all

 if (lat1 != lat2)
    *bearing = 180/PI*(atan2(dLon,dLat));
  else
    *bearing = 0;


The else clause is not correct I believe.
If I have a longitude difference and no lat difference the correct bearing would be 90° not 0°.

I don't understand your point.
dLon = something and dLat = 0 => bearing = +/-90, normal situation if the reference is the north

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

Re: GPS integration

Post by Alexinparis »

jevermeister wrote:...But the arguments of the atan2 function are swapped so this error is if you want to call it that is being corrected there...

I don't think they are swapped.
make a scheme

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

Re: GPS integration

Post by Alexinparis »

mbrak wrote:hi

just tested MW2.0pre1 with the new funktions. normal flying, mag-mode and acc mode working super soft and smooth. mega 11 bit pwm?

yes, you can call it super smooth :)
the higher PWM resolution on MEGA is an improvement for stability.
+ the task ordering process allowing a smoothing of the loop time.

the gps pos hold is the problem still now. setting a new home position, lift up the copter to about 5 meters and activating gps pos hold the copter comes backwards to me. more than 10 meters and no stop!
whats the problem? 3d fix was set! i will have to test after charging lipo.

There is probably one error somewhere in the code, but according to my tests it works at least if the multi is pointed in a specific direction (south or west direction, I don't remember)

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

Re: GPS integration

Post by Wayne »

Alexinparis wrote:
Wayne wrote:OK it only freezes when the HK/Apache GPS is plugged in.
I did let HK/Apache stop flashing outside while serial two was unplugged.
Then I ran inside hooked MEGA to WinGUI and see that everything was working UNTILL I plugged in serial 2. When plugged in the satellite in WinGUI went from red to green, # of satts. went from 0 to 3 then it froze.


It's possible also that the code is not robust enough and don't like the NMEA frame of your GPS once the sats are ok, causing a code crash.


I was trying to rule out my setup before I ask for help with the code.
Under the Apache GPS label on top the patch is #GTPA010.
Looking at the data sheet it looks like it could have NMEA output and it may have $GPGGA and the first 8 params, 0-7 in the correct order for MW.
It has other params but it looks like MW only checksums the first 8.
That’s as far as I can take it…
I know there are others with this GPS Module, sure would be nice if it worked.

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

Re: GPS integration

Post by jevermeister »

Alexinparis wrote:
jevermeister wrote:

Code: Select all

 if (lat1 != lat2)
    *bearing = 180/PI*(atan2(dLon,dLat));
  else
    *bearing = 0;


The else clause is not correct I believe.
If I have a longitude difference and no lat difference the correct bearing would be 90° not 0°.

I don't understand your point.
dLon = something and dLat = 0 => bearing = +/-90, normal situation if the reference is the north


Dlon =sowmthing and dlat =0 is +/- 90 but lat1 lat2 are identical and this means the else clause is executed: bearung=0.
nils

I will try some teytwalks today.

didlawowo69
Posts: 38
Joined: Tue Oct 11, 2011 1:42 pm

Re: GPS integration

Post by didlawowo69 »

Hi,
i have a question about GPS integration.

it is possible to add an GPS like : http://www.flytron.com/osd-headtrackers ... odule.html
and use RTH and position hold fonction without an ACC ? (i 'm not able to calibrate my BMA180 correctly).

thx for your response.

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

Re: GPS integration

Post by Alexinparis »

jevermeister wrote:
Alexinparis wrote:
jevermeister wrote:

Code: Select all

 if (lat1 != lat2)
    *bearing = 180/PI*(atan2(dLon,dLat));
  else
    *bearing = 0;


The else clause is not correct I believe.
If I have a longitude difference and no lat difference the correct bearing would be 90° not 0°.

I don't understand your point.
dLon = something and dLat = 0 => bearing = +/-90, normal situation if the reference is the north


Dlon =sowmthing and dlat =0 is +/- 90 but lat1 lat2 are identical and this means the else clause is executed: bearung=0.
nils

I will try some teytwalks today.


Hi,
ok, I understand now.
The if / else test is wrong. we can remove it, atan2 should handle this in fact.
But the order of terms in atan2 is right.

The probability to have lat1==lat2 is however very low in flight, so the current problems are probably not tied to this.

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

Re: GPS integration

Post by jevermeister »

Hi Alex.
From my test I lesrned that the rth and ph seem to work properly but I cannot understand the code yet. I always end up witj wrong conclusions if I calculate it manually.I am working on it.
What problems do you mean?Do you have general problems regarding the functions?

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

Re: GPS integration

Post by Alexinparis »

jevermeister wrote:Hi Alex.
From my test I lesrned that the rth and ph seem to work properly but I cannot understand the code yet. I always end up witj wrong conclusions if I calculate it manually.I am working on it.
What problems do you mean?Do you have general problems regarding the functions?


Hi,
I've no problem on my side, but I didn't test it a lot.
I think about mbrak problem:
the gps pos hold is the problem still now. setting a new home position, lift up the copter to about 5 meters and activating gps pos hold the copter comes backwards to me. more than 10 meters and no stop!
whats the problem? 3d fix was set! i will have to test after charging lipo.


It's difficult to sort out things here, as many factors could explain failures (GPS device, mag disturbtion, sensor orientation, fine level mode,...)

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

Re: GPS integration

Post by jevermeister »

I will test this scenario today. I believe the bearing may be a problem.as stated before: it actually is a bearing FROM home. so you will have to treat it like that later. I think in some cases the copter bearing is treated wrongly this results in a attitude into the opposite direction. i noticed that while calculating your equations on paper. just try it with a few example latitudes and maybe you find something. i woll go olinto detail tonight. tetxting from my phone is a pain in the a$$.
Nils

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

Re: GPS integration

Post by Wayne »

HK/Apache GPS report:
I loaded 1.9.2 into my MEGA2560.
Configured Serial 2 and 38400 Baud.
Calibrated ACCs and MAG, took it outside and in under 30 seconds I had GPS lock and no freeze!
Ran inside plugged into 1.9.2 GUI and can see that I am 40m West of home and the number of sats. is 5!!!!

Now to see if I can spot the difference between 1.9 and 2.0.

Update: dev_20120225 works too.
I downloaded and unzipped and fresh copy of 2.0.1, it freezes.
Last edited by Wayne on Wed Mar 07, 2012 7:59 pm, edited 1 time in total.

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

Re: GPS integration

Post by jevermeister »

So I did some math:

First the 5 Scenarios

Code: Select all

case |dLon |dLat| expected bearing
-----------------------------------
A    | 0   |  3   | 0°         --> Copter is North of target
B    | 1   |  2   | 26,56      --> Copter is NE of target
C    | 2   |  2   | 45         --> Copter is NE of target
D    | 3   |  0     | 0                   --> Copter is E
E    | 0   | -3     | 180           --> Copter is south of target, Copter moves south


Now lets do the equations:

Code: Select all

  if (dlat1 != dlat2)
    *bearing = 180/PI*(atan2(dLon,dLat));
  else
    *bearing = 0;


There are different cases for the behavior of atan2

Code: Select all

for atan2:

atan2 =   arctan(dLon/dLat)   | dLat > 0
   arctan(dLon/dLat)+PI   | dLat < 0, dLon >= 0
   arctan(dLon/dLat)-PI   | dLat < 0, dLon < 0
   PI/2 = 90°      | dLat = 0, dLon > 0
   -PI/2= -90°      | dLat = 0, dLon < 0
   0    = 0°      | dLat = 0, dLon = 0



thies lead us to the following results

Code: Select all

A: *bearing = arctan(dLon/dLat) = arctan(0/3) = 0°
B: *bearing = arctan(dLon/dLat) = arctan(1/2) = 26,56°
C: *bearing = arctan(dLon/dLat) = arctan(2/2) = 45°
D: *bearing = PI/2               =   90° <-- Lat1 == Lat2:  *bearing = 0;
E: *bearing = arctan(dLon/dLat)+PI= 0°+180°   = 180°

You may have integrated the else clause to catch a div by zero I think, but the atan2 function already handles that.
In my opinion the else clause should set the bearing to 90° or -90° as you see above.

it should be:

Code: Select all


*bearing = 180/PI*(atan2(dLon,dLat));

Now lets move on with our results:

Code: Select all

-> GPS_directionToHome =bearing
 -> GPS_dir = GPS_directionToHome;
  -> radDiff = (GPS_dir-heading)            //heading = 0

   GPS_angle[ROLL]  = constrain(P8[PIDGPS] * sin(radDiff) )
   GPS_angle[PITCH] = constrain(P8[PIDGPS] * cos(radDiff) )


A: radDiff = 0° ->GPS_angle[ROLL]= 0 *blabla   ,GPS_angle[PITCH] = 1 *blabla
B:
C: radDiff = 45° ->GPS_angle[ROLL]= 0,7 *blabla   ,GPS_angle[PITCH] = 0,7 *blabla 
D:
E: radDiff = 180° ->GPS_angle[ROLL]= 0 *blabla   ,GPS_angle[PITCH] = -1 *blabla


The computed results will be subtracted from the curren roll and pitch situataion, everything seems to be okay.

Code: Select all

errorAngle = constrain(2*rcCommand[axis] - GPS_angle[axis],-500,+500) - angle[axis] + accTrim[axis]; //16 bits is ok here


My conclusion is, that the function is okay from the amth side, however, some pid tuning is neccesary, and you need to set your sensors correct.
Most important is a working glitchles mag as Alex stated.

However: I would change the arrow by include the current bearing of the copter, this looks very cool and will definetily come in handy for a HUD and is more easy to understand.

Code: Select all

 *bearing = bearing-180°-copter_bearing 


So thats all for now - I need some flying practise to see of it works.

Nils

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

Re: GPS integration

Post by mbrak »

jevermeister wrote: tetxting from my phone is a pain in the a$$.
Nils


hi nils

It is very amusing to read your news today :) has helped me through the day thanks :)

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

Re: GPS integration

Post by mbrak »

hi

sorry no test flights possible today. heavy wind an rain.... is it april already ???? no i dont think so..

for me to pass the boredom, I have a buzzer connected to the flyduino-mega. in hope the final 2.0 will support the buzzer.pde :)


my respect alex and jevermeister for debugging the code! my brain still smokes.... no no i am not smoking :)

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

Re: GPS integration

Post by jevermeister »

Hi,
It is very amusing to read your news today has helped me through the day thanks


OH thank you... you are very very welcome... :-/

my respect alex and jevermeister for debugging the code! my brain still smokes.... no no i am not smoking


It was very interesting ttrying to understand Alex's way of solving this gps thingy, I first thougt to let you guys bring this baby to life but I think this is avery interesting one, I learned a lot in the past two days.

Working with you guys is always a pleasure!

Nils

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

Re: GPS integration

Post by Wayne »

I know that headache too. Last evening and into the night I looked at the code.
I would comment out lines one at a time that had to do with GPS and if it would verify I would upload it. I have yet to find the line that freezes MEGA after GPS lock.
I don’t think it’s the frame decode as it works in dev_20120225 and when I paste 2.0.PV1 decode section into –2025, -2025 keeps working.
I tried ‘if (GPS_fix > 0 && GPS_numSat > 3) {‘ incase there is 2 for a ‘Differential GPS Fix’.
I’m so close and at this point I await the next dev- or 2.0 proper to see if it works itself out.

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

Re: GPS integration

Post by mbrak »

jevermeister wrote:I've a stupid question,
I am about to start GPS testing tomorrow and I wonder what the behaviour of the LED ist.

If I start up there obviously is no fix but what happens to the LED when the fix is optained (regarding to code it should blink, but this is not happening at my flyduino, maybe some other function is i)

I coded a buzzer sound for the event of a first fix and a warning sound if you try to activate GPS without a valid fix.

Is there intereest for introducing this into the code?

Nils



hi nils

i am very interested to learn more about your buzzer extension.
my copter is buzzer-ready :) flyduino mega with buzzer connected to pin 32 (lipo-alarm).

i wonder why your activation in config.h is in the arduino micro part?

my goal is to use it like you described with rcOptions. to get a bit more feedback what the copter is doing or not :)

regards michael


p.s. sorry for the post yesterday.

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

Re: GPS integration

Post by Wayne »

To see if the buzzer stuff was making my MEGA freeze I commented in front of the LED and BUZZER under GPS. I put // in front of anything that hung up when verifying.
Loaded it, looked good in GUI but no change, freeze just after GPS lock.
I’m looking now to see if MW might be changing the baud of serial 2 on me.

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: GPS integration

Post by Hamburger »

Out of memory.
To test comment out all sensors but gyro and disable all other unneccessary features.

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

Re: GPS integration

Post by Wayne »

That’s it, I have GPS lock and no freeze.
Now I’ll bring back BARO and MAG one at a time, MAG first.
Thank you Hamburger!

It freezes after a few seconds with only MAG and takes twice as long to freeze with BARO only. To check now I’m going to take them both back out and see if it ever freezes. Then I’ll put them both back in with Serial GPS disabled, although I’m sure this never freezes.
Man, I moved to MEGA so I wouldn’t run out of memory.

Update:
WM+, NK, SpekSat and Serial GPS are all OK together, no Freeze.
Adding MAG or BARO freezes after a few seconds.
Cycle time never over 6025 with GPS lock and with or without MAG/BARO.
I also just got my first indoor GPS lock, who said its a bad day for GPS!

One more update..
Just for kicks and after looking at code for what seams like days now, I sent the numbers MW is using as GPS_ long and GPS_lat to debug 3 and 4. What do you know, its less than 100 seconds off in both long and lat..
Last edited by Wayne on Thu Mar 08, 2012 11:27 pm, edited 1 time in total.

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

Re: GPS integration

Post by jevermeister »

Oh, it is misplaced!
I will fix it tomorrow..
sorry


mbrak wrote:
jevermeister wrote:I've a stupid question,
I am about to start GPS testing tomorrow and I wonder what the behaviour of the LED ist.

If I start up there obviously is no fix but what happens to the LED when the fix is optained (regarding to code it should blink, but this is not happening at my flyduino, maybe some other function is i)

I coded a buzzer sound for the event of a first fix and a warning sound if you try to activate GPS without a valid fix.

Is there intereest for introducing this into the code?

Nils



hi nils

i am very interested to learn more about your buzzer extension.
my copter is buzzer-ready :) flyduino mega with buzzer connected to pin 32 (lipo-alarm).

i wonder why your activation in config.h is in the arduino micro part?

my goal is to use it like you described with rcOptions. to get a bit more feedback what the copter is doing or not :)

regards michael


p.s. sorry for the post yesterday.

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

Re: GPS integration

Post by Wayne »

Hamburger wrote:Out of memory.
To test comment out all sensors but gyro and disable all other unneccessary features.


Today’s test includes changing from Tri to Quad.
I unplugged the servo, uploaded all sensors/defined QUAD_X.
It ran here inside without GPS lock for over five minutes.
Outside I get freeze after GPS lock. Without unplugging I take it inside hook to computer and if I time it right, pressing reset and GUI connect, I can get it to run long enough to show I have GPS lock/dist/dir home.

I have built my controller around Arduino MEGA 2560 r3.
It includes:
SRAM 8 KB
EEPROM 4 KB

Does other controllers like Flyduino have more memory than this?
Am I the only freezing after GPS lock?

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

Re: GPS integration

Post by jevermeister »

So I did some testing yesterday:
1. Walking tests with copter and notebook. Everything seems plausible, except the bearing to home need to be the other way around, inclusive bearing relative to copter nose. We have a meg, why not use it.

2. Flight test: Amazing!!! It works you flick the switch and it comes back, I have a little problem with the PID it is overshooting the position it should hold, but this is just parameter optimizing.

Walking behind the copter and try to shove it into another direction is funny too, you can feel it wanting to return to home or hold position

I am so happy.

Good work Alex!!

Nils

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

Re: GPS integration

Post by Wayne »

Weather outside today was too good to be inside chasing my freeze issue so…
I unplugged my HK/Apache GSP module so I would never GPS lock/Freeze.
With GPS and all sensors uncommented I flew two sets of batteries.
I rotated the sets in so it did not reset for almost 15 minutes of flight time.
Not one hiccup, not one ‘what was that’ event.
Flew so well I could nose it into the wind, click a little pitch forward trim and take my fingers off for minutes at a time.
I also flew my new Warthox Y copter and one quick flight with the Paris 4 Quad.
All this but…..
Nils, you would not believe how jealous I am.

Post Reply