You are on page 1of 10

maXbox Starter 34

Start with GPS


1.1 My Position please
Today we run through GPS coding.
Long day ago I did a lot of measures with my Garmin 310 device on the
run and in trains; ut ecause of security glasses! most of the trains
distur the signal. "ne of the #uestions that comes u$ when encoding
those signals is how they can e useful in daily life.
%i&i says' The Gloal Positioning System (GPS) is a s$ace*ased satellite
navigation system that $rovides location and time information in all weat*
her conditions! anywhere on or near the earth where there is an
unostructed line of sight to four or more GPS satellites.
+ach GPS satellite continuously roadcasts a navigation message at a
rate of ,0 its $er second. - message ta&es .,0 seconds to com$lete/
Such a record does have as minimum navi information'
procedure GPSRecord
begin
writeln('time,date,latitude,longitude,altitude,nsat,speed,course');
end
This isn0t very different from a normal cloc&! isn0t it1 2ou0ll notice that the
altitude and s$eed ta&es $art of the record. The s$eed is over ground in
&nots and the altitude means meters aove sea level.
This information on 34+- sentences can e sourced from all over the net
and 34+- is the 3ational 4arine +lectronics -ssociation. It is to e a
worldwide! self*sustaining organi5ation committed to enhancing the
technology and safety of electronics used in marine a$$lications and you
see also a standard for GPS data formats.
6ut garmin li&e others have 7 $ro$rietary sentences with 8 of theme
inter$reted.
9ow it wor&s' The GPS satellites transmit signals to a GPS receiver. These
receivers $assively receive those signals; they do not transmit and re#uire
a clear view of the s&y! so they can only e used effectively outdoors! or
from time to time in trains;*).
Type
TReceive_Func = TGPSSerialR!"#ar(Sender$ TObject);
9ere0s an interesting com$arison. GPS signals are transmitted at a $ower
e#uivalent to a ,0 watt house light ul. Those signal have to $ass
through s$ace and our atmos$here efore reaching your device after a
:ourney of 11,00 miles. ;om$are that with a T< signal! transmitt from a
large tower 10 * =0 miles away at most! at a $ower level of ,*10000 watts.
-ll GPS satellites have atomic cloc&s. The signal that is sent out is a
random se#uence! each $art of which is different from every other! called
$seudo*random code (see $ic elow). This random se#uence is re$eated
continuously. GPS receivers &now this se# and re$eat it internally.
So! satelites and the receivers must e in synch. The receiver $ic&s u$ the
satellite0s transmission and com$ares the incoming signal to its own
internal signal. In com$are how much the satellite signal is lagging! the
travel time ecomes &nown.
1.1.1 Time to Code
"viously the most im$ortant device re#uired for this software to wor&! is
the GPS receiver. -ll GPS devices with a 34+-01>3 com$atile connection
are su$$orted.
2
The GPS is used to get $osition! course! s$eed and information on 34+-
#uality and ? or $recision.
So I start with the call to the %&e'So(tware tool&it o:ect'

begin ))var o*+Gps$ variant;
try
o*+Gps$= "reate,le,*+ect('%&e'So(twareGps');
except
writeln('no GPS ,*+$ -nvalid class string');
end
%or&ing with @ree Pascal or Ael$hi you have to include some units to e
ale to use -ctiveB controls in our $ro:ect. %e need to include the
following units'
,leServer, "om,*+, .ctive/
In maBoC those units and many others are $re*com$iled and included on
demand. 3ow we are ready to declare the GPS constants as well.
o*+Gps"onstants$= "reate,le,*+ect('%&e'So(twareGps"onstants');

-fter these ste$s! we can start with $rogramming the rest of the GPS code.
In order to connect a GPS receiver! you need to have at least one availale
serial ;"4 $ort.
If there is no $ort availale! you can add a serial $ort y using an DES6*
to*SerialF converter li&e on -rduino oard availale or a 34+-01>3 data
cominer e#ui$$ed with an ES6 $ort.
"om*o0o!1evice-tems.dd('Garmin 2S0');
for i$= 3 to 34 do begin
"om*o0o!1evice-tems.dd('",5'6 -ntToStr(i));
end;
"om*o0o!1evice-tem-nde!$= 3;
"om*o0o!Speed-tems.dd( ''788' );
"om*o0o!Speed-tems.dd( '9488' );
"om*o0o!Speed-tem-nde!$= :;
%hen using such a converter! ma&e sure it is connected at or efore the
time you are going to configure the GPS. I did also made some tests with
Garmin.nt agent direct calls! ut that0s another story.
%hen you have no control on which sentences are sent y the device! it is
recommended to only select the s$ecific GG- and <TG o$tions in the
34+-01>3 settings.
The default serial aud rate for 34+-01>3 devices is 8>00$s.
9owever! some hardware use other s$eeds (for instance! an -IS receiver
will use 3>800).
3
3ow we discuss the start and sto$ $rocedure'
procedure 0uttonStart"lic;(Sender$ T,*+ect);
begin
o*+Gps1eviceSerialPort$= "om*o0o!1evice-tem-nde!;
o*+Gps1evice0audrate$= StrTo-nt("om*o0o!SpeedTe!t);
o*+Gps,pen;
<a*elStatus"aption$= o*+Gps<ast%rror1escription;
if (o*+Gps<ast%rror = 8) then begin
0uttonStart%na*led$= False;
0uttonStop%na*led$= True;
Timer3%na*led$= True;
end;
end;
The interesting line is the timer which $rovides the incoming data'
procedure Timer3Timer(Sender$ T,*+ect);
begin
%dit<atitudeTe!t$= o*+Gpsgps<atitudeString;
%dit<ongitudeTe!t$= o*+Gpsgps<ongitudeString;
%ditSpeedTe!t$= FloatToStr( o*+GpsgpsSpeed );
%dit"ourseTe!t$= FloatToStr( o*+Gpsgps"ourse );
%dit.ltitudeTe!t$= FloatToStr( o*+Gpsgps.ltitude );
%ditFi!Te!t$= -ntToStr( o*+Gpsgps=ualit& );
%ditSatsTe!t$= -ntToStr( o*+GpsgpsSatellites );
%ditTimeTe!t$= o*+GpsgpsTimeString;
end;
Those data can e used with all GPS receiver that sends 34+- 01>3 data!
and as you &now can e connected to a ;"4 $ort on the com$uter.
This may however vary de$ending on what data sentence the connected
GPS receiver delivers! for eCam$le some low stuff'
%hen the GPS receiver is set to change the A6G fre#uency or aud
rate! the HIH sentence is re$laced (:ust once) y (for eCam$le)'
JPSLI6!3=0.0!=00K,L to set the A6G to 3=0 M95! =00 aud.
The sto$ $rocedure is similar to o$en'
procedure 0uttonStop"lic;(Sender$ T,*+ect);
begin
o*+Gps"lose;
<a*elStatus"aption$= o*+Gps<ast%rror1escription;
if (o*+Gps<ast%rror = 8 ) then begin
0uttonStart%na*led$= True;
0uttonStop%na*led$= False;
Timer3%na*led$= False;
end;
end;
4
So how do we $icture those data1 4ost tool&its also include com$onents
that gives a gra$hical $icture of satellite $ositions and signal strength.
%e do it :ust sim$le from -S;II to a ma$ tool (4a$ 70;SC)'
4a&e your own tests with the whole trac&'
htt$'??www.&leiner.ch?&leiner?garminN$arisNlog.tCt
Paris Trip (Stras*ourg > Paris) wit# Garmin 5ap 48"S!
Geograp#isc#e ?oordinaten (de@imal) Aorld Geodetic S&stem 7' (AGS7')
Br;<Cnge;0reite;DE#e FmG;Heit;%nt( F;mG;?urs FIG;Gesc#w F;m)#G
3;J3'K:J'%;'7J:L''JB;:4LL;3787:889 89$'7$83;8888;8;8
:;J3'8J:7%;'7J:L''4B;:449;3787:889 89$'7$8J;884:;:L7;K8
K;J3K998L%;'7J:LKK'B;:49K;3787:889 89$'7$89;8K38;:44;K3
';J3KL493%;'7J:L3'JB;:J8K;3787:889 89$'7$39;83J9;:73;:9
L;J3KK:97%;'7J:L''8B;:497;3787:889 89$'7$:L;83:J;K83;K3
4;J3K37:K%;'7J:48KKB;:497;3787:889 89$'7$:9;8:9L;K38;:9
J;J3:7JLJ%;'7J:JJL:B;:49K;3787:889 89$'7$K9;88K3;K::;K3
In a$$endiC you see the ma$ and the coordinate in a red circle from which
I started the recording. Those coordinates in the file are decimals and the
longitude is efore latitude! I would eCchange that.
<ariales! records or whole sentences can e assigned the value of the
trac& to made a $rocedure that $icture the tri$ in an image'
Please note that the receiver must e set to transmitting 34+- data.
The default setting for many receivers is a $ro$riarity format/

2ou can also convert coordinates to a ma$ on the internet (-$$endiC).
htt$'??www.g$s*coordinates.net?
2ou can find the address corres$onding to GPS coordinates or latitude!
longitude and address of any $oint on Google 4a$s.
-s more HthingsH on $lanet +arth are converted to the inventory set of
digitally connected devices! the roles and res$onsiilities of we
develo$ers and technology leaders will need to evolve with GPS data.
9o$e you did already wor& with the Starter 1 till 38 e.g. O1, and O1L with
Serial and -rduino to$ics'
htt$'??sourceforge.net?$?maCoC?wi&imaC?main?
5
3eCt we see the whole $icture over a distance of 3>> &m. This image
elow is my sight of a trac&' the yellow line is the s$eed and the lue one
mar&s the altitude $oint.
Sim$lification' 2our units are small and your methods too; youPve said
everything and youPve removed the last $iece of unnecessary code.
1.1.2 Get the Gold Code
I :ust said that concerning sim$lification to made a toast aout the Gold
code and his fascination. 6ecause all of the satellite signals are modulated
onto the same L1 carrier fre#uency! the signals must e se$arated after
demodulation. This is done y assigning each satellite a uni#ue inary
se#uence &nown as a Gold code. %e can im$lement such a $seudo
random routine with a closure.
;losures are reusale loc&s of code that ca$ture the environment and
can e $assed around as method arguments for immediate or deferred
eCecution.
The scope of the GPS signal is missing as I show you now.
Gold se#uences have een $ro$osed y Gold in 1L7. and 1L7>. These are
constructed y +B"G*ing two m*se#uences (4L) of the same length with
each other.
4aCimal Length (4L or m) se#uences or 4L codes are well understood and
have a numer of $ro$erties which are useful in an a$$lication to s$read*
s$ectrum systems.
6
Gold codes have ounded small cross*correlations within a set! which is
useful when multi$le devices are roadcasting in the same fre#uency
range li&e GPS with L1 signal.
- set of Gold codes can e generated with the following ste$s. Pic& two
maCimum length se#uences of the same length =n Q 1 such that a cross*
correlation is minimal'
MMM re(pow_to_B3 = generate_:NB>3 ))ma!imum lengt#
MMM re(pow_to_B: = generate_:NB>3 ))ma!imum lengt#
MMMM 5-B"ross"orrelation( re(pow_to_B3, re(pow_to_B:, O:(n6:)):)
MMM /,R_to_B3B: = generate_/,R(re(pow_to_B3 , re(pow_to_B:)
MMM GoldSet(/,R_to_B3B:))
The image elow declares this conteCt with arguments which a caller can
follow in another conteCt. 2ou see also a P*code (H$recision codeH)! a $art
of the $ositioning system signal.
4odulo = Sum (addition) is the B"G. So now you0re wondering why I :ust
s$ent this time eC$laining com$licated things when it wor&s. Iust to give
you some fascination with a conclusion'
R In or demodulated signals must e se$arated y a Gold ;ode
R - uni#ue inary se#uence &nown as a Gold ;ode is assigned to each
satellite
R The numer attached to each signal ar identifies which satellites it0s
receiving a signal from.
R The $seudo random code is sim$ly an I. A. code that identifies which
satellite is transmitting information
R GPS satellites transmit two radio signals. These are designated as L1 and
L=. ;ivilian GPS uses the L1 signal fre#uency (1,.,.8= 495) in the
E9@ and.
7
7: The GU o! a Gold Code Ge"erator
Almanac data is data that descries the orital courses of the satellites.
+very satellite will roadcast almanac data for +<+G2 satellite. 2our GPS
receiver uses this data to determine which satellites it eC$ects to see in
the local s&y; then it can determine which satellites it should trac&.
-lmanac data is not $recise and can e valid for many months.
#: C$% Port& o! a Serial "ter!a'e
#
1.2 GPS and Arduino Conclusion
I would also recommend the oo& D-rduino ;oo&oo&F y 4ichael
4argolis. 9ere are a few ideas of more com$licated $ro:ects that I have
seen made with an -rduino.
R - oC that will only o$en when it is at a certain location in the world (It
connects a GPS to the -rduino. Search on DGeverse Geo*cacheF to see
some eCam$les.)
R "r a controller for a 3A $rinter to $rint out the landsca$e the GPS has
:ust scanned/ (I0m :ust &idding)
Latency (sometimes called lag) is the time etween a measurement has
een made (for instance a $osition fiC! or de$th) and when the serial data
is received y the a$$lication and -rduino.
(eedba') *
max*)lei"er.'om
+iterat,re:
-lei"er et al., Patter"& )o")ret, 2..3, So!tware / S,00ort
htt0:11www.)lei"er.'h1)lei"er120&max.htm
htt$'??www.softwareschule.ch?eCam$les?8.,NGPSNmB=.tCt
htt0:11www.0o')et20&world.'om1how20&wor)&.0h0
htt0:11e".wi)i0edia.or21wi)i1Global3Po&itio"i"23S4&tem5%e&&a2e3!ormat
6 So!tware %a",al o! GPS 7xam0le.
htt0:11www.e4e4&o!tware.'om1!ile&1h4droma2i'1ma",al.0d!
htt0:11www.&o!tware&'h,le.'h1dow"load18rd,i"o3C32.14363ba&ta3box.0d!
htt0:11&o,r'e!or2e."et10ro9e't&1maxbox
:
1.3 Appendix Map Study
maXma0
;; <de'imal de2ree&=>
+atit,de 4#.725447? <4#.6562#.:635664:5=
+o"2it,de 7.1432747 <6.::1#1364#4:2.:#=
1 @,e d, Ca"al, 574.5 G,"tABiller, (ra"'e
Latitude : 4#.725447 C Longitude : 7.143274 Altitude : 2#7 meter&
Dere an em*edded microcontroller s&stem wit# a Real Time "loc;$
RTClock: Arduino by Silvia Rothen http://www.ecotronics.ch/ecotron/arduinocheatsheet.htm
1.

You might also like