Cov txheej txheem:

GPS System: 7 Kauj Ruam
GPS System: 7 Kauj Ruam

Video: GPS System: 7 Kauj Ruam

Video: GPS System: 7 Kauj Ruam
Video: nyiag nkag koj tus hluas nkauj tus messenger ua koj twb g paub password 2024, Kaum ib hlis
Anonim
GPS System
GPS System
GPS System
GPS System
GPS System
GPS System

Tus Tsim Txoj Haujlwm: Carlos Gomez

Muaj txoj hauv kev txhim kho kev ntseeg tau yog qhov tseem ceeb rau txhua tus neeg sim taug kev thiab tshawb nrhiav lub ntiaj teb.

Qhov tseem ceeb tshaj plaws uas tso cai rau txoj hauv kev ua haujlwm yog GPS muaj peev xwm ua rau sab hauv ntawm qhov system. Lub kaw lus GPS tso cai rau leej twg los taug qab lawv qhov chaw nyob thiab nrawm txhawm rau nthuav qhia cov ntaub ntawv raug tseeb txog tus neeg siv thiab muab tus neeg siv sawv cev raug qhov tseeb ntawm qhov chaw lawv nyob thiab nyob deb npaum li cas los ntawm lawv qhov chaw.

Lub Ntiaj Teb Txoj Haujlwm Tso Npe (GPS) yog lub network ntawm cov hnub qub ya ncig lub ntiaj teb ntawm qhov siab txog 20, 000 km. Txhua tus neeg uas muaj lub cuab yeej GPS tuaj yeem tau txais xov tooj cua qhia tias lub xov tooj cua tshaj tawm thiab muaj peev xwm siv tau lawv raws txoj kev xav tau. Txhua qhov chaw koj nyob ntawm lub ntiaj teb tsawg kawg plaub GPS yuav tsum muaj rau koj txhua lub sijhawm. Siv txoj hauv kev hu ua 3-D trilateration, lub cuab yeej GPS tuaj yeem siv peb lub hnub qub txhawm rau txiav txim siab lub cuab yeej qhov chaw nyob ntawm Lub Ntiaj Teb. Txhua ntawm peb lub hnub qub xa lub teeb liab mus rau lub cuab yeej thiab lub cuab yeej txiav txim siab nws nyob deb ntawm lub hnub qub. Siv txhua ntawm peb qhov kev suav nrug deb lub cuab yeej tam sim no tuaj yeem taw qhia nws qhov chaw nyob hauv Ntiaj Teb thiab nws rov qab los rau tus neeg siv.

GPS qhov peb yuav tsim yuav muaj peev xwm taug qab tus neeg siv qhov chaw los ntawm kev tau txais tus neeg siv kev tswj hwm ntawm lub Ntiaj Teb thiab ua qee qhov kev xam kom rov qab siv tus neeg siv nrawm, qhov chaw, thiab qhov deb tau them.

Kauj ruam 1: Pib

Pib Pib
Pib Pib
Pib Pib
Pib Pib
Pib Pib
Pib Pib
Pib Pib
Pib Pib

Txhawm rau kom pib txoj haujlwm no, thawj zaug peb yuav tsum sau tag nrho cov ntaub ntawv raug

1: Raspberry Pi Zero W.

2: GPS Txais

3: 1.8 TFT 128 x 160 LCD SPI Screen

4: ~ 11 xov hlau

5: 2 nub

6: 2x 1k thiab 2x 10k resistors rau rub khawm

7: Lub khob cij board

Txoj haujlwm no yuav siv Raspberry Pi's GPIO pins thiab zoo li no peb yuav xav txuas txhua yam nrog lub rooj mov ci txhawm rau txhawm rau txhim kho peb txoj haujlwm. Nws kuj tseem xav tias yog siv cov laug ntawm txhua tus pins tau ua tiav thiab ua tiav ua ntej txav mus thiab txuas txhua yam ntawm peb cov khoom.

Kauj Ruam 2: Txuas GPS Module rau Raspberry Pi

Txuas GPS Module rau Raspberry Pi
Txuas GPS Module rau Raspberry Pi
Txuas GPS Module rau Raspberry Pi
Txuas GPS Module rau Raspberry Pi

Txhawm rau siv peb qhov GPS koj yuav tsum txuas Tx thiab Rx pins los ntawm GPS module mus rau GPIO tus pin 14 thiab 15 ntawm Raspberry Pi. Tx tus pin ntawm GPS tus txais mus rau Rx tus pin ntawm Pi thiab Rx tus lej ntawm GPS tus txais mus rau Tx tus pin ntawm Raspberry pi.

Tus txais GPS qhia hauv cov duab xav kom siv 3.3V thiab koj tuaj yeem txuas 3.3V tus pin rau qhov ntsuas hluav taws xob raug, thaum txuas Ground pin rau hauv av.

Kauj Ruam 3: Tau Txais Cov Ntaub Ntawv Los Ntawm GPS Tus Qauv Txais

Tau txais cov ntaub ntawv los ntawm GPS Tus Qauv Txais
Tau txais cov ntaub ntawv los ntawm GPS Tus Qauv Txais

Txhawm rau kom tau txais cov ntaub ntawv los ntawm GPS tus txais mus rau Raspberry Pi peb yuav tsum tau tso cai qhov nyob kom nyeem tau los ntawm UART cov chaw nres nkoj. Nyeem cov ntaub ntawv nyoos yuav xav kom peb tsim peb tus kheej lub tsev qiv ntawv cais, tab sis hauv qhov xwm txheej no peb tuaj yeem ua kom zoo dua ntawm GPS daemon uas khiav hauv keeb kwm yav dhau los los pab siv cais cov ntaub ntawv thiab xa mus rau Raspberry Pi

Txhawm rau ua kom tiav qhov no peb tuaj yeem qhib lub davhlau ya nyob twg ntawm Raspberry Pi thiab ua raws txoj cai:

sudo apt-tau hloov tshiab

sudo apt-tau nruab gpsd gpsd-cov neeg siv sej-gps

Qhov no yuav tsum saib xyuas qhov rub tawm rau peb.

Thaum nws ua tiav, peb yuav tsum tau xiam qhov kev pabcuam gpsd system los ntawm kev ua cov lus txib hauv qab no:

sudo systemctl nres gpsd.socket

sudo systemctl lov tes taw gpsd.socket

Yog tias koj ib txwm xav kom qhib qhov kev pabcuam gpsd lub neej ntawd, koj tuaj yeem ua raws cov lus txib hauv qab no los kho nws:

sudo systemctl pab gpsd.socket

sudo systemctl pib gpsd.socket

Tam sim no peb yuav tsum pib gpsd daemon thiab taw tes rau UART cov chaw nres nkoj los ntawm kev nkag mus

sudo gpsd/dev/ttyAMA0 -F /var/run/gpsd.sock

Tam sim no peb tuaj yeem ua cov lus txib hauv qab no thiab pom txhua cov ntaub ntawv ntab hauv!

cgps ua

Kauj Ruam 4: Txuas Zaub rau Raspberry Pi

Txuas Zaub rau Raspberry Pi
Txuas Zaub rau Raspberry Pi
Txuas Zaub rau Raspberry Pi
Txuas Zaub rau Raspberry Pi

Thaum peb muaj peb lub GPS txais thiab ua haujlwm nrog Raspberry Pi, peb tuaj yeem txuas cov zaub rau Raspberry Pi. Peb yuav siv 5 xov txuas los txuas peb lub LCD zaub rau Raspberry Pi thiab lwm 4 tus pin txuas lub zog tseem ceeb thiab LED ntawm qhov screen.

Kuv tau suav nrog daim duab ntawm lub vijtsam TFT kuv tab tom siv, tab sis qhov no yuav tsum ua haujlwm nrog cov ntxaij vab tshaus uas zoo ib yam thiab tsim.

Txuas LED- thiab GND rau hauv av thiab txuas LED+ thiab VCC rau 3.3V.

Txuas tus pin RESET ntawm lub vijtsam kom pin 25 ntawm Pi board.

Txuas A0 rau tus pin 24 ntawm Pi board.

Txuas SDA tus pin rau MOSI tus pin ntawm Pi board.

Txuas tus pin SCK ntawm lub vijtsam LCD rau Pi board.

Txuas CS tus pin rau tus pin 8 ntawm Pi board.

Kauj Ruam 5: Teeb Zaub Ua Haujlwm Nrog Raspberry Pi

Teeb Zaub kom Ua Haujlwm Nrog Raspberry Pi
Teeb Zaub kom Ua Haujlwm Nrog Raspberry Pi

Txhawm rau teeb tsa cov zaub peb yuav tsum siv ST7735 lub tsev qiv ntawv pom hauv qhov repo no:

Python ST7735 Screen Library

Thaum peb muaj lub tsev qiv ntawv tso saib no teeb tsa rau peb li Raspberry Pi system, tam sim no peb tuaj yeem npaj teeb tsa cov ntaub ntawv piv txwv kom paub meej tias peb cov xov hlau dhau los ua haujlwm raug.

Tsim cov ntawv uas muaj npe piv txwv.py thiab ntxig cov ntawv hauv qab no nrog rau cov duab piv txwv ntawm koj xaiv hauv tib lub nplaub tshev

ntshuam ST7735 li TFTimport Adafruit_GPIO li GPIO ntshuam Adafruit_GPIO. SPI li SPI

LUAS = 128

Qhov siab = 160 SPEED_HZ = 4000000

# Raspberry Pi teeb tsa.

# Cov no yog cov pins xav tau los txuas lub LCD rau Raspberry Pi

DC = 24 RST = 25 SPI_PORT = 0 SPI_DEVICE = 0

# Tsim TFT LCD zaub chav kawm.

disp = TFT. ST7735 (DC, rst = RST, spi = SPI. SpiDev (SPI_PORT, SPI_DEVICE, max_speed_hz = SPEED_HZ))

# Pib ua zaub.

disp.begin () disp.reset ()

# Thauj duab.

newData = 0x42 disp.command (newData) print ('Loading image …') image = Image.open ('cat.jpg')

# Hloov cov duab thiab tig nws kom phim cov zaub.

duab = image.rotate (270).resize ((WIDTH, HEIGHT))

# Yuav luam tawm mus rau lub davhlau ya nyob twg uas peb qhov program tau kos peb Cov Duab ntawm lub vijtsam

print ('Teeb duab')

# Lub luag haujlwm no yuav tso tawm peb cov duab ntawm lub vijtsam

disp.display (duab)

Cov ntaub ntawv no yuav teeb tsa Raspberry Pi teeb tsa rau lub vijtsam LCD thiab lub tsev qiv ntawv yuav hloov peb cov duab hauv daim nplaub tshev thiab tso tawm ntawm lub vijtsam.

Kauj Ruam 6: Teeb Lub Xeev Machine los tso saib GPS Cov Ntaub Ntawv ntawm Zaub

Teeb Lub Xeev Machine los tso saib GPS Cov Ntaub Ntawv ntawm Zaub
Teeb Lub Xeev Machine los tso saib GPS Cov Ntaub Ntawv ntawm Zaub
Teeb Lub Xeev Machine los tso saib GPS Cov Ntaub Ntawv ntawm Zaub
Teeb Lub Xeev Machine los tso saib GPS Cov Ntaub Ntawv ntawm Zaub
Teeb Lub Xeev Cov Tshuab los tso saib GPS Cov Ntaub Ntawv ntawm Zaub
Teeb Lub Xeev Cov Tshuab los tso saib GPS Cov Ntaub Ntawv ntawm Zaub

Peb yuav siv 5 lub xeev sib txawv tshuab, thaum siv peb daim duab qhia chaw los teeb tsa peb cov gps system.

Zaub Hloov lub xeev tshuab:

Lub xeev lub tshuab no yuav tswj hwm qhov twg los tso saib nyob ntawm peb lub pob nkag. Nws ua qhov no los ntawm kev hloov pauv qhov sib txawv uas tso cai rau nab nab kom ua kom zoo dua ntawm kev ntaus duck thiab hu qhov ua haujlwm raug los tso saib nyob ntawm qhov hu ua haujlwm

Lub xeev ceev tshuab:

Lub xeev lub tshuab no yuav ua kom nrawm nrawm tam sim no nyob ntawm tus neeg qhov chaw nyob. Qhov no yuav ua txhua lub voj voog moos rau GPS system

Lub xeev tshuab tawm:

Lub xeev lub tshuab no yuav txiav txim siab qhov tso tawm raws qhov sib txawv uas lub tshuab hloov pauv lub xeev txiav txim siab los ua cov khoom tam sim no.

Lub xeev nyob deb li cas tshuab

Lub xeev lub tshuab no ua tiav txhua lub voj voog moos thiab txiav txim siab tag nrho cov kev mus los ntawm tus neeg siv thiab thaum lub khawm rov pib dua raug thawb, yuav rov pib dua qhov kev mus tam sim no.

Lub xeev qhov chaw tshuab:

Lub xeev lub tshuab no xa qhov chaw tam sim no ntawm tus neeg siv, siv kev tswj hwm uas GPS module rov qab hais txog tus neeg siv. Lub xeev lub tshuab no yog nyob ntawm cov neeg siv internet txuas.

Kauj Ruam 7: Cia Peb Siv Peb Qhov GPS

Thaum peb muaj peb lub GPS module xa cov ntaub ntawv rau peb Raspberry Pi thiab peb lub vijtsam LCD tso saib cov ntaub ntawv ntawm nws peb tuaj yeem pib ua haujlwm rau peb qhov system GPS. Kuv yuav siv cov txheej txheem yav dhau los lub xeev cov tshuab kawg txhawm rau txhawm rau cim peb li GPS system

## Cov ntaub ntawv tseem ceeb rau Kev Tshawb Fawb # # # #

# Cov tsev qiv ntawv rau kos duab

los ntawm PIL ntshuam duab los ntawm PIL ntshuam ImageDraw los ntawm PIL ntshuam ImageFont

# Lub tsev qiv ntawv rau ST7737 tus tswj hwm

ntshuam ST7735 li TFT

# Lub tsev qiv ntawv rau GPIO rau Raspberry Pi

ntshuam Adafruit_GPIO li GPIO ntshuam Adafruit_GPIO. SPI ua SPI

# Lub tsev qiv ntawv rau GPS

#ntshuam gpsd los ntawm gps3 ntshuam gps3

# Lub tsev qiv ntawv rau sijhawm

lub sij hawm ntshuam

# Lub tsev qiv ntawv txhawm rau nrhiav nrug deb ntawm ob lub ntsiab lus

los ntawm kev ua lej ntshuam kev txhaum, cos, sqrt, atan2, radians

# Ntshuam Rpi lub tsev qiv ntawv los siv cov nyees khawm hloov cov ntawv qhia zaub mov thiab rov pib dua

# ntshuam RPi. GPIO ua bGPIO

# Teeb tus pin rau khawm

bGPIO.setmode (bGPIO. BCM)

bGPIO.setup (18, bGPIO. IN, rub_up_down = bGPIO. PUD_DOWN)

bGPIO.setup (23, bGPIO. IN, rub_up_down = bGPIO. PUD_DOWN)

# ntshuam geopy tsev qiv ntawv rau Geocoding

# # Kev siv Internet yog qhov tsim nyog rau qhov no los ua haujlwm

los ntawm geopy.geocoders ntshuam Nominatim

geolocator = Nominatim ()

# Qhov tsis tu ncua rau qhov system

#################################

LUAS = 128

Qhov siab = 160 SPEED_HZ = 4000000

# Raspberry Pi teeb tsa pins

DC = 24 # A0 ntawm lub vijtsam TFT RST = 25 # Pib dua tus pin ntawm TFT npo SPI_PORT = 0 # SPI chaw nres nkoj ntawm raspberry pi, SPI0 SPI_DEVICE = 0 # Qhev xaiv ntawm rapsberry pi, CE0

# Tsim TFT LCD zaub khoom

disp = TFT. ST7735 (DC, rst = RST, spi = SPI. SpiDev (SPI_PORT, SPI_DEVICE, max_speed_hz = SPEED_HZ))

# Pib ua zaub

pib.begin ()

# Cov keeb kwm yav dhau yuav teeb rau ntsuab

#disp.clear ((0, 255, 0))

# Ntshiab qhov screen kom dawb thiab tso saib

#disp.clear ((255, 255, 255)) kos = disp.draw () #kos.rectangle ((0, 10, 127, 150), tus qauv = (255, 0, 0), sau = (0, 0, 255)) #disp.display ()

# Kev nrawm, Kab laum, Longitude hloov pauv qhov hloov pauv

#currentS = "Ceev Tam Sim No:" # Txoj hlua nrawm #totalDis = "Tag Nrho Cov Kab Ke:" # Txoj kab nrug #currentLoc = "Qhov Chaw Nyob Tam Sim No:" # Txoj hlua txoj haujlwm

# Nyob nrug x thiab y tswj hwm

distX = 10 distY = 20

cov ntsiab lus =

# Ceev x thiab y tswj hwm

speedX = 10 speedY = 20

# Qhov chaw x thiab y coordiantes

locX = 10 locY = 20

# Hloov los ntawm m/s rau mph

conversionVal = 2.24

# Kev hloov pauv nrawm, rov ua txoj hlua

SpeedVar = 0

def speedFunc (): thoob ntiaj teb SpeedVar SpeedText = data_stream. TPV ['nrawm'] yog (SpeedText! = "n/a"): SpeedText = ntab (SpeedText) * conversionVal SpeedVar = puag ncig (SpeedText, 1) # rov qab (SpeedText)

def qhov chawFunc ():

latLoc = str (latFunc ()) lonLoc = str (lonFunc ())

reverseString = latLoc + "," + lonLoc

qhov chaw = geolocator.reverse (reverseString)

rov qab (qhov chaw.address)

# Latitude hloov tshiab muaj nuj nqi, rov qab tus nqi ntab

def latFunc (): Latitude = data_stream. TPV ['lat'] yog (Latitude == "n/a"): rov 0 lwm tus: rov ntab (puag ncig (Latitude, 4))

# Longitude hloov tshiab muaj nuj nqi, rov qab txoj hlua

def lonFunc (): Longitude = data_stream. TPV ['lon'] yog (Longitude == "n/a"): rov 0 lwm tus: rov ntab (puag ncig (Longitude, 4))

# Kev ua haujlwm nyob deb rov qab TOTAL qhov kev mus ncig

TotalDistance = 0

def distFunc (): cov

thoob ntiaj teb totalDistance newLat = latFunc () newLon = lonFunc () yog (newLat == 0 lossis newLon == 0): totalDistance = totalDistance # return (totalDistance) else: pointsList.append ((newLat, newLon)) last = len (pointsList)) -1 yog (kawg == 0): xa rov qab: totalDistance += = coorDistance (pointsList [kawg-1], pointsList [kawg]) # rov qab totalDistance

# Pib dua tag nrho nrug

def resDistance (): cov

thoob ntiaj teb totalDistance totalDistance = 0

# Muaj nuj nqi siv los nrhiav qhov deb nruab nrab ntawm ob txoj haujlwm

# siv Haversine tus qauv los nrhiav. # Cov ntsiab lus tawm tswv yim yog tuple

def coorDistance (point1, point2):

# Kwv yees lub vojvoog ntawm Lub Ntiaj Teb hauv kilometers earthRadius = 6373.0

lat1 = point1 [0]

lon1 = point1 [1]

lat2 = point2 [0]

lon2 = point2 [1]

distanceLon = lon2 - lon1

distanceLat = lat2 - lat1

# Haversine ib

a = sin (distanceLat/2) ** 2 + cos (lat1)*cos (lat2)*sin (nrugLon/2) ** 2

#Hversine c

c = 2 * atan2 (sqrt (a), sqrt (1-a))

# Hloov km mus mais

nrug = (earthRadius * c) * 0.62137

yog (nrug <= 0.01): rov qab 0.00 lwm tus: rov ncig (nrug, 3)

# Muaj nuj nqi los tso saib nrawm ntawm lub vijtsam

def dispSpeed (): ua

thoob ntiaj teb SpeedVar # Qhov nrug deb ntawm qhov sib txawv ntawm qhov screen kos.text ((speedX, speedY), str (SpeedVar), font = ImageFont.truetype ("Lato-Medium.ttf", 72))

# Muaj nuj nqi los tso saib nrug deb ntawm lub vijtsam

def dispDistance (): cov

draw.text ((distX, distY), str (totalDistance), font = ImageFont.truetype ("Lato-Medium.ttf", 60))

# Muaj nuj nqi ti tso saib qhov chaw ntawm lub vijtsam, xav tau internet kom ua haujlwm

def dispocation qhov chaw ():

draw.text ((locX, locY), locationFunc (), font = ImageFont.truetype ("Lato-Medium.ttf", 8))

# Siv phau ntawv txhais lus kom ua raws cov lus hloov pauv

dispOptions = {

0: dispSpeed, 1: dispDistance, 2: dispLocation}

# Kev ua haujlwm ntawm lub vijtsam

def tso tawm ():

# Siv thoob ntiaj teb sib txawv rau displayIndex thoob ntiaj teb displayIndex # Ntxuav lub vijtsam thiab siv keeb kwm yav dhau los tsis meej ((255, 255, 255)) kos.rectangle ((0, 10, 127, 150), tus qauv = (255, 0, 0), sau = (255, 0, 0))

# Hu ua haujlwm nyob ntawm tus nqi displayIndex

dispOptions [displayIndex] ()

# Yuav tshem tawm yog tias lwm txoj hauv kev ua haujlwm

# tso qhov nrug deb ntawm qhov screen

#kos.text ((distX, distY), str (distFunc ()), font = ImageFont.load_default ()) #tso qhov nrawm sib txawv ntawm qhov screen #kos.text ((speedX, speedY), speedFunc (), font = ImageFont.load_default ()) # Zaub hloov tshiab rau screen disp.display ()

displayButton = 18 # BCM Pin ntawm raspberry pi

resetButton = 23 # BCM Pin ntawm raspberry pi

buttonPress = Tsis tseeb

def checkDisplay ():

thoob ntiaj teb khawm Xov xwm thoob ntiaj teb displayIndex yog (bGPIO.input (displayButton) thiab tsis khawm): displayIndex += 1 buttonPress = True if (displayIndex == 2): displayIndex = 0 elif (bGPIO.input (displayButton) thiab buttonPress): print (" Tseem nias ") lwm: buttonPress = False

# Teeb tsa gps

gps_socket = gps3. GPSDSocket () data_stream = gps3. DataStream () gps_socket.connect () gps_socket.watch ()

timerPeriod =.5

# Tus nqi ntsuas rau zaub displayIndex = 0 sim: rau new_data hauv gps_socket: yog new_data: data_stream.unpack (new_data) yog data_stream. TPV ['lat']! = 'N/a': print (data_stream. TPV ['nrawm'], data_stream. TPV ['lat'], data_stream. TPV ['lon']) distFunc () speedFunc () output () checkDisplay () if (bGPIO.input (resetButton)): resDistance () else: output () checkDisplay () yog (bGPIO.input (resetButton)): resDistance () luam tawm ('GPS tsis txuas nrog') time.sleep (.1) time.sleep (.8) tsuas yog KeyboardInterrupt: gps_socket.close () print (' / n Txiav txim los ntawm tus neeg siv ctrl+c ')

Cov cai saum toj no tsuas yog ib qho piv txwv ntawm yuav ua li cas rau npe rau peb cov kab ke thiab kuv tau teeb tsa cov vis dis aus txog qhov kev ua haujlwm no li cas.

Pom zoo: