Вы находитесь на странице: 1из 4

Software

section
electroni cs for you December 2010 113 www. e f y ma g . c o m
Manuj arora
GPS deMo in C
SAN THEO
T
he global positioning system
(GPS) is a satellite-based navi-
gation and positioning system
that was designed by the United
States Department of Defense to allow
a single soldier or group of soldiers to
autonomously determine their posi-
tion to within 10 to 20 metres of truth.
It sends and receives radio signals
through satellites (refer Fig. 1) located
above the earth. A GPS receiver on
the earth receives the transmitted sig-
nals and provides location and time
information to the user. It provides
reliable information in all weather
conditions, at all times and anywhere
in the world.
Fig. 2 shows the GPS communica-
tion system. Fig. 3 shows a typical GPS
receiver.
GPS, formally known as the NAVS-
TAR (navigation satellite timing and
ranging), was originally developed for
the US Military. Because of its navi-
gation capabilities and access to the
technology using small, inexpensive
equipment, the government made the
system available for civilian use. The
system is maintained by the United
States government and is freely acces-
sible by anyone with the GPS receiver.
GPS technology
The GPS consists of three major seg-
ments: control, space and user. Of
these, control and space segments are
operated by the US Military.
Control segment. The control seg-
ment is responsible for constantly
monitoring the satellite health, signal
integrity and orbital configuration
from the ground. It includes a master
control system (MCS), ground anten-
nae and monitor stations.
Space segment. The space segment
consists of the constellation of GPS
satellites that are currently in orbit,
including operational, backup and
inoperable units. The satellites orbit
at an altitude of around 20,000 kilo-
metres from ground. A GPS satellite
completes orbit once every 11 hours
and 58 minutes.
User segment. The user segment
consists of the commercially available
GPS receiver purchased by the user.
How does a GPS receiver
work?
GPS operates on the principle of tri-
lateration, i.e., using information from
three known satellites. To fnd the sat-
ellites positions, its possible to create
imaginary or virtual spheres around
each of the satellites.
For the GPS receiver to locate it-
self, it must fnd the distance to three
satellites of known positions. After
detecting a satellite, the receiver as-
sumes that it is located somewhere
on the surface of an imaginary sphere
centered at the satellite. Let us examine
four cases as described below.
When only one satellite is consid-
ered. If the GPS receiver calculates only
one virtual sphere, the surface of that
sphere will intersect the surface of the
earth. Because the distance from the
satellite to the surface of the sphere is
the same all along the circles circum-
ference, the receiver could theoretically
be anywhere on that imaginary sphere
(refer Fig. 5).
When two satellites are considered.
If the receiver considers two satellites,
the second spheres circle intersects
the frst spheres circle and touches
the earth at two points. The possible
position of the receiver will be in the
overlapping region of the two imagi-
nary spheres (refer Fig. 6).
When three or more satellites are
considered. A sphere from a third
satellite resolves the ambiguity. There
Fig. 1: GPS satellites
Fig. 3: Typical GPS receiver
Fig. 2: GPS communication system
Fig. 4: GPS segments
Software
section
114 December 2010 electroni cs for you www. e f y ma g . c o m
is only one pointred in the program
illustrationwhere the surfaces of the
three virtual spheres meet on the sur-
face of the earth.
The receiver generally looks to four
or more satellites, for improved accu-
racy and precise altitude information
(refer Fig. 7).
Software program
This software program demonstrates
the concepts of GPS segments and
3-D trilateration. The coding is written
in C language and compiled using
Turbo C. Turbo C has a good col-
lection of graphics libraries that has
been utilised for graphics program-
ming using basics of C. The program
uses various C graphic fles such as
egavga.bgi, scri.chr, trip.chr, lcom.chr
and tsr.chr.
GPS segments display. The frst
part of the program displays the three
major segments (control, space and
user) of the GPS system. The segments
are displayed one by one with one-
second delay between two consecutive
segments (refer Fig. 8).
Demonstration of 3-D trilat-
eration. The second part of the project
demonstrates the principle of 3-D
trilateration. First, it displays in a win-
dow screen the symbol of the satellite
used in the program. Then the pro-
Fig. 7: More than three satellites
Fig. 8: Program output screenshot of GPS system
Fig. 5: One satellite along with its imaginary
sphere
Fig. 9: Program output screenshot of two
imaginary spheres
Fig. 10: Program output screenshot of more than
three imaginary spheres
Fig. 6: Two satellites above the earth
gram starts displaying the above-men-
tioned four cases sequentially one by
one. In every display, corresponding to
the number of the satellites considered,
the region covered by the sphere is also
indicated:
When one satellite is considered. A
satellite with the imaginary sphere is
displayed as shown in Fig. 5.
When two satellites are considered.
In this case, two displays are shown:
The frst display shows two spheres
corresponding to the two satellites (as
shown in Fig. 6). The second display
shows better understanding of the
concept with a ring in blue colour
(refer Fig. 9).
When three or four satellites are con-
sidered. In the third and fourth cases,
the point of intersection of the spheres
is made to blink in order to create
a better presentation. The program
output of more than three imaginary
spheres is shown in Fig. 10.
role of various functions
Initgraph(&gd,&gm,c:\\turboc3\\
bgi). Initialises the graphics system
by loading a graphics driver from
the disk and then putting the system
into graphics mode. It also resets all
graphics settings like colour, palette
and current position to their defaults.
gd specifies the graphics driver
to be used and gm specifies the
initial graphics mode (unless gd =
DETECT). When gd = DETECT, the
initgraph sets the graphics mode to
the highest resolution available for the
detected driver.
Closegraph( ). Switches back the
screen from graphics mode to text
mode. It is called after getch( ) so that
the screen does not clear until the user
hits the key.
Void segments( ). Displays the three
major segments (control, space and
user) of the GPS.
Void Satellite_symbol( ). Displays
the symbol of the satellite used in the
program.
Void projectwork( ). Demonstrates
how the GPS receiver works using the
principle of trilateration.
Software
section
electroni cs for you December 2010 115 www. e f y ma g . c o m
GPS.C
Setbkcolor(number). Sets the back-
ground colour of choice from 16 colour
options (0 through 15). Instead of
specifying the number, the respective
colour name can also be used in block
letters from the specifed set.
Setcolor(number). Selects a fore-
ground or drawing colour from the
same set of 16 colours.
Settextstyle(font,direction,charac
ter size). Sets the values for text char-
acteristics to be used for displaying
the text.
Outtextxy(x,y,Literal expres-
sion). Displays the string in graphics
mode. (x, y) denotes the starting coor-
dinate of the string on the screen.
Setfllstyle(pattern,color). Used to
fll the colour. It enables an additional
feature of flling the colours with spe-
cifc pattern of colouring as well.
Floodfll( ). Used for flling the
required colour in geometrical fgures.
Geometrical figures can be drawn
using the inbuilt functions of shapes
(rectangle, circle, etc).
EFY note. The source code of
this article has been included in this
months EFY-CD and is also available
on www.efymag.com website.
// HEADER FILES USED
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
// FUNCTIONS USED
void introduction();
void segments();
void satellite_symbol();
void projectwork();
void proj1();
void proj2();
void proj3();
void proj4();
void closing();
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,c:\\turboc3\\bgi);
introduction();
segments();
satellite_symbol();
projectwork();
closing();
getch();
closegraph();
restorecrtmode();
}
/* TO DISPLAY THE NAME OF THE PROGRAM-
MER */
void introduction()
{
setbkcolor(RED);
setcolor(YELLOW);
delay(1000);
settextstyle(7,0,6);
outtextxy(90,50,GPS System Demo);
delay(1000);
setcolor(WHITE);
outtextxy(240,150,Project);
delay(1000);
outtextxy(270,250,in C);
setcolor(YELLOW);
delay(1000);
settextstyle(7,0,2);
outtextxy(100,350,By : Manuj Arora);
delay(2000);
cleardevice();
}
/* TO DISPLAY MAJOR SEGMENTS OF GPS */
void segments()
{
setbkcolor(BLUE);
setcolor(YELLOW);
settextstyle(7,0,6);
delay(1000);
outtextxy(100,100,Major Segments);
delay(500);
outtextxy(280,200,Of);
delay(1000);
outtextxy(230,300,G P S );
delay(3000);
cleardevice();
setcolor(WHITE);
settextstyle(8,0,4);
outtextxy(100,40,GPS Segments);
delay(1000);
circle(450,120,75);
setfllstyle(1,LIGHTGREEN);
foodfll(450,120,WHITE);
setcolor(RED);
settextstyle(8,0,2);
outtextxy(405,100,CONTROL);
setcolor(WHITE);
delay(1000);
setcolor(YELLOW);
moveto(375,120);
lineto(225,225);
moveto(225,225);
lineto(245,205);
moveto(225,225);
lineto(250,215);
delay(1000);
setcolor(WHITE);
circle(150,250,75);
setfllstyle(1,CYAN);
foodfll(175,275,WHITE);
setcolor(RED);
settextstyle(8,0,3);
outtextxy(115,225,SPACE);
delay(1000);
setcolor(YELLOW);
moveto(222,272);
lineto(370,365);
moveto(370,365);
lineto(350,345);
moveto(370,365);
lineto(347,359);
delay(1000);
circle(450,370,75);
setfllstyle(1,LIGHTRED);
foodfll(450,370,YELLOW);
setcolor(RED);
outtextxy(420,350,USER);
delay(5000);
cleardevice();
}
/* SYMBOL USED FOR SATELLITE IN THE
PROGRAM */
void satellite_symbol()
{
setbkcolor(CYAN);
setcolor(RED);
delay(1000);
settextstyle(7,0,4);
outtextxy(170,40,SYMBOL USED);
delay(500);
outtextxy(275,80,FOR);
delay(1000);
settextstyle(7,0,4);
outtextxy(215,120,SATELLITE);
delay(1000);
setcolor(BLUE);
circle(305,250,20);
setfllstyle(9,RED);
foodfll(305,250,BLUE);
setfllstyle(9,BROWN);
rectangle(255,200,285,300);
foodfll(260,250,BLUE);
rectangle(325,200,355,300);
foodfll(350,250,BLUE);
delay(2000);
cleardevice();
}
/* TO DEMO - How GPS WORKS ?( 3D TRI-
LATERATION ) */
void projectwork()
{
setbkcolor(BLUE);
setcolor(WHITE);
settextstyle(7,0,6);
delay(1000);
outtextxy(80,150,How GPS Works ?);
delay(2000);
setcolor(YELLOW);
outtextxy(80,250,3D TRILATERATION
);
delay(2000);
cleardevice();
proj1();
proj2();
proj3();
proj4();
}
/* TO DISPLAY REGION WHEN 1 SATELLITE
IS CONSIDERED */
void proj1()
{
setbkcolor(BLUE);
setcolor(YELLOW);
settextstyle(7,0,4);
outtextxy(130,30,No. of Satellites
Used : 1);
delay(1000);
setcolor(WHITE);
circle(320,240,150);
setfllstyle(1,YELLOW);
foodfll(320,240,WHITE);
setcolor(GREEN);
setfllstyle(9,BROWN);
circle(320,240,10);
foodfll(320,240,GREEN);
rectangle(290,220,310,260);
foodfll(300,240,GREEN);
rectangle(330,220,350,260);
foodfll(340,240,GREEN);
moveto(320,240);
lineto(350,387);
moveto(350,387);
lineto(345,376);
moveto(350,387);
lineto(350,375);
delay(1000);
setcolor(YELLOW);
outtextxy(100,400,Region : Imaginary
Sphere);
delay(3000);
cleardevice();
}
/* TO DISPLAY REGION WHEN 2 SATELLITES
ARE CONSIDERED */
void proj2()
{
setbkcolor(BLUE);
setcolor(YELLOW);
Software
section
116 December 2010 electroni cs for you www. e f y ma g . c o m
settextstyle(7,0,4);
outtextxy(110,30,No. of Satellites
Used : 2);
delay(1000);
setcolor(YELLOW);
circle(250,220,100);
circle(370,220,100);
setfllstyle(1,GREEN);
foodfll(252,222,YELLOW);
foodfll(372,220,YELLOW);
setcolor(YELLOW);
circle(250,220,5);
rectangle(235,205,245,235);
rectangle(255,205,265,235);
setfllstyle(9,RED);
foodfll(252,222,YELLOW);
foodfll(240,210,YELLOW);
foodfll(260,210,YELLOW);
circle(370,220,5);
rectangle(355,205,365,235);
rectangle(375,205,385,235);
foodfll(372,222,YELLOW);
foodfll(357,207,YELLOW);
foodfll(377,207,YELLOW);
ellipse(310,220,90,89,10,81);
setfllstyle(1,LIGHTBLUE);
foodfll(315,230,YELLOW);
setfllstyle(1,GREEN);
foodfll(340,220,YELLOW);
foodfll(280,220,YELLOW);
delay(1000);
setcolor(YELLOW);
outtextxy(100,400,Region : Common
Circular);
delay(1000);
setcolor(WHITE);
moveto(350,410);
lineto(315,290);
moveto(315,290);
lineto(320,300);
moveto(315,290);
lineto(317,305);
delay(3000);
cleardevice();
setbkcolor(BLACK);
setcolor(YELLOW);
settextstyle(7,0,4);
delay(1000);
outtextxy(110,20,Another View of Two
Satellites);
delay(1000);
setcolor(RED);
arc(250,180,53,307,100);
arc(370,180,233,127,100);
setcolor(BLUE);
ellipse(310,181,90,89,10,81);
setcolor(RED);
setfllstyle(9,LIGHTGREEN);
circle(250,180,5);
foodfll(252,182,RED);
rectangle(235,165,245,195);
foodfll(240,170,RED);
rectangle(255,165,265,195);
foodfll(260,170,RED);
circle(370,180,5);
foodfll(372,182,RED);
rectangle(355,165,365,195);
foodfll(360,170,RED);
rectangle(375,165,385,195);
foodfll(380,170,RED);
setcolor(YELLOW);
delay(1000);
outtextxy(110,330,No. of Satellites
Used : 2);
delay(1000);
outtextxy(160,400,Region : Blue
Ring);
delay(2000);
cleardevice();
}
/* TO DISPLAY REGION WHEN 3 SATELLITES
ARE CONSIDERED */
void proj3()
{
setbkcolor(BLACK);
setcolor(YELLOW);
settextstyle(7,0,4);
delay(1000);
outtextxy(110,20,No. of Satellites
Used : 3);
delay(1000);
setcolor(RED);
arc(250,180,53,307,100);
arc(370,180,233,127,100);
setcolor(BLUE);
ellipse(310,181,90,89,10,81);
ellipse(310,240,0,359,75,10);
setcolor(RED);
arc(310,305,138,42,100);
setfllstyle(9,LIGHTGREEN);
circle(250,180,5);
foodfll(252,182,RED);
rectangle(235,165,245,195);
foodfll(240,170,RED);
rectangle(255,165,265,195);
foodfll(260,170,RED);
circle(370,180,5);
foodfll(372,182,RED);
rectangle(355,165,365,195);
foodfll(360,170,RED);
rectangle(375,165,385,195);
foodfll(380,170,RED);
circle(310,305,5);
foodfll(312,307,RED);
rectangle(295,290,305,320);
foodfll(300,295,RED);
rectangle(315,290,325,320);
foodfll(320,295,RED);
circle(318,230,3);
setfllstyle(1,YELLOW);
foodfll(319,231,RED);
circle(305,250,3);
foodfll(306,251,RED);
delay(1000);
setcolor(YELLOW);
outtextxy(130,410,Region : Two Points
);
delay(500);
setcolor(RED);
setfllstyle(1,BLUE);
foodfll(319,231,RED);
foodfll(306,251,RED);
delay(500);
setfllstyle(1,YELLOW);
foodfll(319,231,RED);
foodfll(306,251,RED);
delay(500);
setfllstyle(1,BLUE);
foodfll(319,231,RED);
foodfll(306,251,RED);
delay(500);
setfllstyle(1,YELLOW);
foodfll(319,231,RED);
foodfll(306,251,RED);
delay(500);
setfllstyle(1,BLUE);
foodfll(319,231,RED);
foodfll(306,251,RED);
delay(500);
setfllstyle(1,YELLOW);
foodfll(319,231,RED);
foodfll(306,251,RED);
delay(500);
setfllstyle(1,BLUE);
foodfll(319,231,RED);
foodfll(306,251,RED);
delay(500);
setfllstyle(1,YELLOW);
foodfll(319,231,RED);
foodfll(306,251,RED);
delay(3000);
cleardevice();
}
/* TO DISPLAY REGION WHEN 4 SATELLITES
ARE CONSIDERED */
void proj4()
{
setbkcolor(BLACK);
delay(1000);
setcolor(YELLOW);
settextstyle(7,0,4);
outtextxy(130,30,No. of Satellites
Used : 4 );
delay(1000);
setcolor(RED);
circle(230,220,100);
circle(230,220,5);
rectangle(215,205,225,235);
rectangle(235,205,245,235);
setfllstyle(9,LIGHTGREEN);
foodfll(232,222,RED);
foodfll(220,210,RED);
foodfll(240,210,RED);
circle(350,170,100);
circle(350,170,5);
rectangle(335,155,345,185);
rectangle(355,155,365,185);
foodfll(352,172,RED);
foodfll(340,160,RED);
foodfll(360,160,RED);
circle(220,270,100);
circle(220,270,5);
rectangle(205,255,215,285);
rectangle(225,255,235,285);
foodfll(222,272,RED);
foodfll(210,260,RED);
foodfll(230,260,RED);
circle(402,320,100);
circle(402,320,5);
rectangle(387,305,397,335);
rectangle(407,305,417,335);
foodfll(404,322,RED);
foodfll(390,310,RED);
foodfll(410,310,RED);
delay(1000);
setcolor(YELLOW);
settextstyle(7,0,4);
outtextxy(100,420,Region : Precisely
One Point);
setcolor(BLUE);
circle(320,265,4);
setfllstyle(1,YELLOW);
foodfll(322,267,BLUE);
delay(500);
setfllstyle(1,RED);
foodfll(322,267,BLUE);
delay(500);
setfllstyle(1,YELLOW);
foodfll(322,267,BLUE);
delay(500);
setfllstyle(1,RED);
foodfll(322,267,BLUE);
delay(500);
setfllstyle(1,YELLOW);
foodfll(322,267,BLUE);
delay(500);
setfllstyle(1,RED);
foodfll(322,267,BLUE);
delay(500);
setfllstyle(1,YELLOW);
foodfll(322,267,BLUE);
delay(500);
setfllstyle(1,RED);
foodfll(322,267,BLUE);
delay(500);
setfllstyle(1,YELLOW);
foodfll(322,267,BLUE);
delay(3000);
cleardevice();
}
/* TO DISPLAY EXIT OPTION */
void closing()
{
setbkcolor(RED);
setcolor(YELLOW);
settextstyle(7,0,4);
delay(1000);
outtextxy(150,180,!!! Thank You
!!!);
outtextxy(110,270,Press any Key to
EXIT );
}

Вам также может понравиться