![MATLAB解析GPS數(shù)據(jù)程序[共14頁]_第1頁](http://file2.renrendoc.com/fileroot_temp3/2021-8/18/ffa4a53d-2d90-451e-9a4c-9dfbcd31872c/ffa4a53d-2d90-451e-9a4c-9dfbcd31872c1.gif)
![MATLAB解析GPS數(shù)據(jù)程序[共14頁]_第2頁](http://file2.renrendoc.com/fileroot_temp3/2021-8/18/ffa4a53d-2d90-451e-9a4c-9dfbcd31872c/ffa4a53d-2d90-451e-9a4c-9dfbcd31872c2.gif)
![MATLAB解析GPS數(shù)據(jù)程序[共14頁]_第3頁](http://file2.renrendoc.com/fileroot_temp3/2021-8/18/ffa4a53d-2d90-451e-9a4c-9dfbcd31872c/ffa4a53d-2d90-451e-9a4c-9dfbcd31872c3.gif)
![MATLAB解析GPS數(shù)據(jù)程序[共14頁]_第4頁](http://file2.renrendoc.com/fileroot_temp3/2021-8/18/ffa4a53d-2d90-451e-9a4c-9dfbcd31872c/ffa4a53d-2d90-451e-9a4c-9dfbcd31872c4.gif)
![MATLAB解析GPS數(shù)據(jù)程序[共14頁]_第5頁](http://file2.renrendoc.com/fileroot_temp3/2021-8/18/ffa4a53d-2d90-451e-9a4c-9dfbcd31872c/ffa4a53d-2d90-451e-9a4c-9dfbcd31872c5.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
1、 % 注:本程序可直接在 MATLAB 2017a 中運行% 該腳本文件用于學(xué)習(xí) GPS數(shù)據(jù)的讀取,需要做其他用途請自行修改代碼% 本腳本文件的前面幾行代碼是要設(shè)置的一些參數(shù)% 默認(rèn)使用 COM3(需視情況修改)% 波特率設(shè)為 GPS模塊默認(rèn)的 38400% 下面為程序源碼clearnum_execute = 100; % 執(zhí)行次數(shù)num_SingleRead = 150; % 單次從串口讀取的字節(jié)數(shù) (最好設(shè)置足夠大(最低大概設(shè)為80),保證單次讀取的數(shù)據(jù)包含一條完整的GPS數(shù)據(jù))Timedelay = 0.2; % 用于延時讀取串口數(shù)據(jù)BaudRate = 38400; % 讀取數(shù)據(jù)的波特
2、率Terminator = CR;num_MaxTry = 5; % 打開串口的最多嘗試次數(shù)BytesAvailableFcnCount = 1000;% 設(shè)置參數(shù)% delete(instrfindall); % 串口打開失敗時使用此句% delete(s);clear s % 串口打開失敗時使用此句serial3 = serial(COM3);% 串口設(shè)置serial3.BytesAvailableFcnMode = byte;% serial3.InputBufferSize = 38400; % 輸出波特率serial3.BaudRate = BaudRate; % 讀入波特率% se
3、rial3.OutputBufferSize = 1024;serial3.BytesAvailableFcnCount = BytesAvailableFcnCount;serial3.ReadAsyncMode = continuous; serial3.Terminator = Terminator;% 打開串口count_opentimes = 1;while contains(serial3.status,closed) 0 & count_opentimes num_MaxTryfopen(serial3); % 打開串口count_opentimes = count_openti
4、mes+1;endif contains(serial3.status,open) 0)GPS_DataStrs = fread(serial3,num_SingleRead,char); %一次讀出 10 個字符GPS_DataStrs = reshape(GPS_DataStrs,1,);GPS_DataStrs = split_str2strs(GPS_DataStrs);GPS_Data_tmp = get_GPS_specificData(GPS_DataStrs);GPS_Data = Updata_GPU_Data(GPS_Data,GPS_Data_tmp);show_GPS_
5、Data(GPS_Data);pause(Timedelay); % 延時num_execute = num_execute-1;end% fprintf(s,abcd);% fscanf(s);% 給串口的發(fā)送數(shù)據(jù)% 從串口的接收緩存讀數(shù)據(jù)% 關(guān)閉串口并刪除相關(guān)數(shù)據(jù)fclose(serial3); % 關(guān)閉串口 delete(serial3);clear serial3% 將字符串根據(jù) rn 劃分成多個子字符串 ,同時去掉首尾無用的殘余字符串function out_strs = split_str2strs(StrData)if contains(class(StrData),char)u
6、int8(StrData);endrecord = get_pos_enterflag(StrData);if StrData(1) = uint8($) % 開頭為 $的情況flag_start = 1;elseif size(record,2) 0flag_start = record(1)+2;elseout_strs = cell(0,0);returnendendif StrData(end) = 13flag_end = length(StrData)-1;elseif size(record,2) 0flag_end = record(end)-1;endendif flag_s
7、tart = flag_endout_strs = cell(0,0);return endStrData = StrData(flag_start:flag_end); %截取有效數(shù)據(jù),方便下面劃分子字符串record = get_pos_enterflag(StrData);num_strs = size(record,2)+1;out_strs = cell(num_strs,1);if num_strs 1out_strs1,1 = char(StrData(1:record(1)-1);if num_strs = 2out_strsnum_strs,1 = char(StrData(
8、record(1)+2:end);elsefor i = 2 : num_strs-1out_strsi,1 = char(StrData(record(i-1)+2:record(i)-1);endout_strsnum_strs,1 = char(StrData(record(i)+2:end);endelseout_strs1,1 = char(StrData);end% 得到字符串中 rn 在字符串中的位置 (實際為 r 的位置 )function record = get_pos_enterflag(data)record = ; % 記錄回車符號位置for ii = 1 : len
9、gth(data)-1if data(ii) = 13if data(ii+1) = 10record = record,ii;ii = ii+1;endendend endend% 得到具體 GPS結(jié)構(gòu)體數(shù)據(jù)function GPS_Data_tmp = get_GPS_specificData(StrsData)GPS_Data_tmp = ;num_str = size(StrsData,1);for i = 1 : num_strstr_tab = StrsDatai,1;if contains(str_tab,GGA) 0GPS_Data_tmp = GNGGA(str_tab);e
10、lseif contains(str_tab,GSA) 0GPS_Data_tmp = GNGSA(str_tab);elseif contains(str_tab,GSV) 0GPS_Data_tmp = GNGSV(str_tab);elseif contains(str_tab,RMC) 0GPS_Data_tmp = GNRMC(str_tab);elseif contains(str_tab,VTG) 0GPS_Data_tmp = GNVTG(str_tab);elseif contains(str_tab,GLL) 0GPS_Data_tmp = GNGLL(str_tab);e
11、ndendend% GPS 字符串解析function GPS_Data_tmp = GNGGA(str_tab)index = strfind(str_tab,);count = 1;Time= str_tab(index(count)+1:index(count+1)-1);count=count+1;= str_tab(index(count)+1:index(count+1)-1);count=count+1;Latitude GPS_Data_tmp.LatitudeDir = str_tab(index(count)+1:index(count+1)-1);count=count+
12、1;Longitude= str_tab(index(count)+1:index(count+1)-1);count=count+1;GPS_Data_tmp.LongitudeDir = str_tab(index(count)+1:index(count+1)-1);count=count+1;GPS_Data_tmp.GPSState = str_tab(index(count)+1:index(count+1)-1);count=count+1;GPS_Data_tmp.SatelliteNum = str_tab(index(count)+1:index(count+1)-1);c
13、ount=count+1;GPS_Data_tmp.HDOP1);count=count+1;= str_tab(index(count)+1:index(count+1)-GPS_Data_tmp.altitude = str_tab(index(count)+1:index(count+1)-1);count=count+1;% other= str_tab(index(count)+1:end);% 進一步處理GPS_Data_tmp.Time.hour = Time(1:2);GPS_Data_tmp.Time.min = Time(3:4);GPS_Data_tmp.Time.sec
14、 = Time(5:6);GPS_Data_tmp.Tlisec = Time(8:10);GPS_Data_tmp.Latitude.degree = Latitude(1:2); %緯度GPS_Data_tmp.Latitude.min = Latitude(3:4);tmp = str2double(Latitude(6:9);tmp = tmp*6/1000; % tmp = tmp/10000*60;GPS_Data_tmp.Latitude.sec = num2str(floor(tmp);GPS_Data_tmp.Llisec = num2st
15、r(tmp-floor(tmp)*10000);GPS_Data_tmp.Longitude.degree = Longitude(1:3); %經(jīng)度GPS_Data_tmp.Longitude.min = Longitude(4:5);tmp = str2double(Longitude(7:10);tmp = tmp*6/1000; % tmp = tmp/10000*60;GPS_Data_tmp.Longitude.sec = num2str(floor(tmp);GPS_Data_tmp.Llisec = num2str(tmp-floor(tmp)*1000
16、0); % UTC 時間轉(zhuǎn)換為北京時間hour = GPS_Data_tmp.Time.hour;if str2num(hour)+8 = 24GPS_Data_tmp.Time.hour = num2str(str2num(hour)+8-24);elseGPS_Data_tmp.Time.hour = num2str(str2num(hour)+8);endendfunction GPS_Data_tmp = GNGSA(str_tab)index = strfind(str_tab,);count = 1;GPS_Data_tmp.LocationMode = str_tab(index
17、(count)+1:index(count+1)-1);count=count+1;GPS_Data_tmp.CurState = str_tab(index(count)+1:index(count+1)-1);count=count+1;GPS_Data_tmp.PRN1);count=count+1;= str_tab(index(count)+1:index(count+1)-= str_tab(index(count)+1:index(count+1)-= str_tab(index(count)+1:index(count+1)-= str_tab(index(count)+1:i
18、ndex(count+1)-GPS_Data_tmp.PDOP1);count=count+1;GPS_Data_tmp.HDOP1);count=count+1;GPS_Data_tmp.VDOP1);count=count+1;% otherend= str_tab(index(count)+1:end);function GPS_Data_tmp = GNGSV(str_tab)% 此語句為與衛(wèi)星有關(guān)的信息(包括衛(wèi)星方位,衛(wèi)星編號)% 暫時用不著,不處理GPS_Data_tmp = ;endfunction GPS_Data_tmp = GNRMC(str_tab)index = str
19、find(str_tab,); count = 1;Time= str_tab(index(count)+1:index(count+1)-1);count=count+1;GPS_Data_tmp.LocationState = str_tab(index(count)+1:index(count+1)-1);count=count+1;Latitude= str_tab(index(count)+1:index(count+1)-1);count=count+1;GPS_Data_tmp.LatitudeDir = str_tab(index(count)+1:index(count+1)
20、-1);count=count+1;Longitude= str_tab(index(count)+1:index(count+1)-1);count=count+1;GPS_Data_tmp.LongitudeDir = str_tab(index(count)+1:index(count+1)-1);count=count+1;GPS_Data_tmp.speed1);count=count+1;= str_tab(index(count)+1:index(count+1)-GPS_Data_tmp.TrueDir1);count=count+1;= str_tab(index(count
21、)+1:index(count+1)-Date= str_tab(index(count)+1:index(count+1)-1);count=count+1;GPS_Data_tmp.MagneticAngle = str_tab(index(count)+1:index(count+1)-1);count=count+1;GPS_Data_tmp.MagneticDir = str_tab(index(count)+1:index(count+1)-1);count=count+1;% other= str_tab(index(count)+1:end);% 進一步處理GPS_Data_t
22、mp.Time.hour = Time(1:2);GPS_Data_tmp.Time.min = Time(3:4);GPS_Data_tmp.Time.sec = Time(5:6);GPS_Data_tmp.Tlisec = Time(8:10);GPS_Data_tmp.Latitude.degree = Latitude(1:2); %緯度GPS_Data_tmp.Latitude.min = Latitude(3:4);tmp = str2double(Latitude(6:9);tmp = tmp*6/1000; % tmp = tmp/10000*60;GPS_Da
23、ta_tmp.Latitude.sec = num2str(floor(tmp);GPS_Data_tmp.Llisec = num2str(tmp-floor(tmp)*10000); GPS_Data_tmp.Longitude.degree = Longitude(1:3); %經(jīng)度GPS_Data_tmp.Longitude.min = Longitude(4:5);tmp = str2double(Longitude(7:10);tmp = tmp*6/1000; % tmp = tmp/10000*60;GPS_Data_tmp.Longitude.sec =
24、 num2str(floor(tmp);GPS_Data_tmp.Llisec = num2str(tmp-floor(tmp)*10000);GPS_Data_tmp.DATE.day = Date(1:2);GPS_Data_tmp.DATE.month = Date(3:4);GPS_Data_tmp.DATE.year = Date(5:6);% UTC 時間轉(zhuǎn)換為北京時間hour = GPS_Data_tmp.Time.hour;if str2num(hour)+8 = 24GPS_Data_tmp.Time.hour = num2str(str2num(ho
25、ur)+8-24);elseGPS_Data_tmp.Time.hour = num2str(str2num(hour)+8);endendfunction GPS_Data_tmp = GNVTG(str_tab)index = strfind(str_tab,);count = 1;GPS_Data_tmp.TrueDir1);count=count+1;= str_tab(index(count)+1:index(count+1)-GPS_Data_tmp.ReferenceTrueDir = str_tab(index(count)+1:index(count+1)-1);count=
26、count+1;GPS_Data_tmp.RelativeDir1);count=count+1;= str_tab(index(count)+1:index(count+1)-GPS_Data_tmp.ReferenceRelativeDir = str_tab(index(count)+1:index(count+1)-1);count=count+1;GPS_Data_tmp.step1);count=count+1;= str_tab(index(count)+1:index(count+1)-GPS_Data_tmp.stepflag1);count=count+1;= str_ta
27、b(index(count)+1:index(count+1)- GPS_Data_tmp.velocity1);count=count+1;= str_tab(index(count)+1:index(count+1)-= str_tab(index(count)+1:end);% otherendfunction GPS_Data_tmp = GNGLL(str_tab)index = strfind(str_tab,);count = 1;Latitude= str_tab(index(count)+1:index(count+1)-1);count=count+1;GPS_Data_t
28、mp.LatitudeDir = str_tab(index(count)+1:index(count+1)-1);count=count+1;Longitude= str_tab(index(count)+1:index(count+1)-1);count=count+1;GPS_Data_tmp.LongitudeDir = str_tab(index(count)+1:index(count+1)-1);count=count+1;Date= str_tab(index(count)+1:index(count+1)-1);count=count+1;GPS_Data_tmp.Locat
29、ionState = str_tab(index(count)+1:index(count+1)-1);count=count+1;% other= str_tab(index(count)+1:end);% 進一步處理GPS_Data_tmp.Latitude.degree = Latitude(1:2); %緯度GPS_Data_tmp.Latitude.min = Latitude(3:4);tmp = str2double(Latitude(6:9);tmp = tmp*6/1000; % tmp = tmp/10000*60;GPS_Data_tmp.Latitude.sec = n
30、um2str(floor(tmp);GPS_Data_tmp.Llisec = num2str(tmp-floor(tmp)*10000);GPS_Data_tmp.Longitude.degree = Longitude(1:3); %經(jīng)度GPS_Data_tmp.Longitude.min = Longitude(4:5);tmp = str2double(Longitude(7:10);tmp = tmp*6/1000; % tmp = tmp/10000*60;GPS_Data_tmp.Longitude.sec = num2str(floor(tmp); GPS
31、_Data_tmp.Llisec = num2str(tmp-floor(tmp)*10000);GPS_Data_tmp.DATE.day = Date(1:2);GPS_Data_tmp.DATE.month = Date(3:4);GPS_Data_tmp.DATE.year = Date(5:6);end% 更新獲取到的相關(guān)數(shù)據(jù)function GPS_Data = Updata_GPU_Data(GPS_Data,GPS_Data_tmp)% 用不到的數(shù)據(jù)可以注釋掉if isfield(GPS_Data_tmp,Time) = 1GPS_Data.Time.h
32、our = GPS_Data_tmp.Time.hour;GPS_Data.Time.min = GPS_Data_tmp.Time.min;GPS_Data.Time.sec = GPS_Data_tmp.Time.sec;GPS_Data.Tlisec = GPS_Data_tmp.Tlisec;endif isfield(GPS_Data_tmp,DATE) = 1GPS_Data.DATE.day = GPS_Data_tmp.DATE.day;GPS_Data.DATE.month = GPS_Data_tmp.DATE.month;GPS_Data.DA
33、TE.year = GPS_Data_tmp.DATE.year;endif isfield(GPS_Data_tmp,Latitude) = 1GPS_Data.Latitude.degree = GPS_Data_tmp.Latitude.degree;GPS_Data.Latitude.min = GPS_Data_tmp.Latitude.min;GPS_Data.Latitude.sec = GPS_Data_tmp.Latitude.sec;GPS_Data.Llisec = GPS_Data_tmp.Llisec;endif isfie
34、ld(GPS_Data_tmp,LatitudeDir) = 1GPS_Data.LatitudeDir = GPS_Data_tmp.LatitudeDir;endif isfield(GPS_Data_tmp,Longitude) = 1 GPS_Data.Longitude.degree = GPS_Data_tmp.Longitude.degree;GPS_Data.Longitude.min = GPS_Data_tmp.Longitude.min;GPS_Data.Longitude.sec = GPS_Data_tmp.Longitude.sec;GPS_Data.Longitu
35、lisec = GPS_Data_tmp.Llisec;endif isfield(GPS_Data_tmp,LongitudeDir) = 1GPS_Data.LongitudeDir = GPS_Data_tmp.LongitudeDir;endif isfield(GPS_Data_tmp,GPSState) = 1GPS_Data.GPSState = GPS_Data_tmp.GPSState;endif isfield(GPS_Data_tmp,SatelliteNum) = 1GPS_Data.SatelliteNum = GPS_Data_t
36、mp.SatelliteNum;endif isfield(GPS_Data_tmp,speed) = 1GPS_Data.speed = GPS_Data_tmp.speed;endif isfield(GPS_Data_tmp,velocity) = 1GPS_Data.velocity = GPS_Data_tmp.velocity;endif isfield(GPS_Data_tmp,LocationState) = 1GPS_Data.LocationState = GPS_Data_tmp.LocationState;endif isfield(GPS_Data_tmp,altit
37、ude) = 1GPS_Data.altitude = GPS_Data_tmp.altitude;endif isfield(GPS_Data_tmp,CurState) = 1GPS_Data.CurState = GPS_Data_tmp.CurState;endif isfield(GPS_Data_tmp,LocationMode) = 1 GPS_Data.LocationMode = GPS_Data_tmp.LocationMode;endif isfield(GPS_Data_tmp,HDOP) = 1GPS_Data.HDOP = GPS_Data_tmp.HDOP;end
38、if isfield(GPS_Data_tmp,VDOP) = 1GPS_Data.VDOP = GPS_Data_tmp.VDOP;endif isfield(GPS_Data_tmp,PDOP) = 1GPS_Data.PDOP = GPS_Data_tmp.PDOP;endif isfield(GPS_Data_tmp,TrueDir) = 1GPS_Data.TrueDir = GPS_Data_tmp.TrueDir;endif isfield(GPS_Data_tmp,MagneticAngle) = 1GPS_Data.MagneticAngle = GPS_Data_tmp.MagneticAngle;endif isfield(GPS_Data_tmp,MagneticDir) = 1GPS_Data.MagneticDir = GPS_Data_tmp.MagneticDir;endif isfield(GPS_Data_tmp,ReferenceTrueDir) = 1GPS_Data.ReferenceTrueDir = GPS_Data_tmp.ReferenceTrueDir;endif isfield(GPS_Data_tmp,Relati
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 院內(nèi)美化合同協(xié)議書5篇
- 2025年榆林普通貨運從業(yè)資格證模擬考試
- 2025年大理貨運員初級考試題庫
- 2025年高中化學(xué)新教材同步 必修第一冊 第4章 第3節(jié) 第2課時 化學(xué)鍵 分子間作用力
- 107-廣播對講系統(tǒng)
- 空間環(huán)境監(jiān)測系統(tǒng)產(chǎn)業(yè)分析報告
- 個人汽車公用租賃合同范本
- 勞務(wù)派遣住宿合同范本
- 中學(xué)化學(xué)教學(xué)工作總結(jié)
- 個人自查自糾整改報告
- (人教PEP2024版)英語一年級上冊Unit 1 教學(xué)課件(新教材)
- 凝中國心鑄中華魂鑄牢中華民族共同體意識-小學(xué)民族團結(jié)愛國主題班會課件
- 2024義務(wù)教育2022版《道德與法治課程標(biāo)準(zhǔn)》真題庫與答案
- 全國職業(yè)院校技能大賽高職組(市政管線(道)數(shù)字化施工賽項)考試題庫(含答案)
- DL∕T 1711-2017 電網(wǎng)短期和超短期負(fù)荷預(yù)測技術(shù)規(guī)范
- 醫(yī)療機構(gòu)消毒記錄表清潔消毒日檢查記錄表
- 2024年北京大學(xué)強基計劃數(shù)學(xué)試卷試題真題(含答案詳解)
- 2024年二級建造師繼續(xù)教育題庫及答案(500題)
- 企業(yè)所得稅匯算清繳申報表電子表格版(帶公式-自動計算)
- 2024年巴西脈沖灌洗系統(tǒng)市場機會及渠道調(diào)研報告
- 新媒體營銷:營銷方式+推廣技巧+案例實訓(xùn) 微課版 第2版 教案全套
評論
0/150
提交評論