【Beetle ESP32-C3】GNSS测试
<div class='showpostmsg'><p>今天在 Beetle ESP32-C3 上测试了 GNSS 功能。GNSS是 VK2828,北斗+GPS双模的,定位速度还比较快。</p><p></p>
<p>GNSS的电源直接用Beetle ESP32-C3上的3.3V,为了方便连接,串口使用GPIO0和GPIO1两个引脚。</p>
<p> </p>
<p> </p>
<p> </p>
<p>参考测试程序</p>
<pre>
<code class="language-python">from machine import UART
'''
mini GNSS Data analysis
'''
class uGNSS():
GNSS_DIR = ('N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S',
'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW')
GNSS_VALID = (b'1', b'2')
version = '1.0'
def __init__(self, uart, baudrate = 9600, bufsize = 2048):
self.latitude = 0.0
self.longitude = 0.0
self.latitude_dir = 'N'
self.longitude_dir = 'E'
self.speed = 0.0
self.course = 0.0
self.altitude = 0.0
self.geoid_height = 0.0
self.date =
self.time =
self.datetime =
self.valid = False
self.satellites_in_view = 0
self.satellites_in_use = 0
self.satellites_used = []
self.hdop = 0.0
self.pdop = 0.0
self.vdop = 0.0
self._crc = bytearray(1)
self._buf = bytearray(256)
self._pos = 0
self._seg = []
self._dat = bytearray(bufsize)
self._dat_n = 0
self.uart = uart
self.uart.init(baudrate = 9600, rxbuf = bufsize)
def checksum(self, buf, length):
self._crc = 0
for i in range(1, length):
self._crc ^= buf
try:
d = int(b'0x'+buf)
except:
return False
return self._crc == d
def parse(self):
try:
if not self.checksum(self._buf, self._pos-4):
return False
self._seg = bytes(self._buf).split(b',')
if self._seg in self.GNSS_CMD:
try:
self.GNSS_CMD](self)
return True
except:
return False
return False
finally:
self._pos = 0
def update_char(self, c):
if self._pos:
if self._pos > 250:
self._pos = 0
return False
else:
if type(c) is int:
self._buf = c
elif type(c) is str:
self._buf = ord(c)
else:
self._pos = 0
return False
if self._buf == ord('\n'):
return self.parse()
else:
self._pos += 1
else:
if c == '$' or c == ord(b'$'):
self._buf = 36
self._pos = 1
def _update(self, dat, n=0):
if n == 0:
n = len(dat)
for i in range(n):
self.update_char(dat)
return self.valid
def update(self):
self._dat_n = self.uart.any()
if self._dat_n == 0:
return False
self.uart.readinto(self._dat)
self._update(self._dat, self._dat_n)
return self.valid
def _time(self, dat):
h, m, s = dat, dat, dat
self.time =
self.datetime = self.time
def _date(self, dat):
d, m, y = dat, dat, dat
self.date =
self.datetime = self.date
def _latlon(self, dat):
t = float(dat)
d, m = divmod(t, 100)
return d + m/60
def _GNGGA(self):
self._time(self._seg)
self.latitude = self._latlon(self._seg)
self.latitude_dir = self._seg.decode()
self.longitude = self._latlon(self._seg)
self.longitude_dir = self._seg.decode()
self.valid = self._seg in self.GNSS_VALID
self.satellites_in_use = int(self._seg)
self.hdop = float(self._seg)
self.altitude = float(self._seg)
self.geoid_height = float(self._seg)
def _GNRMC(self):
self._time(self._seg)
self._date(self._seg)
self.valid = (self._seg == b'A')
self.latitude = self._latlon(self._seg)
self.latitude_dir = self._seg.decode()
self.longitude = self._latlon(self._seg)
self.longitude_dir = self._seg.decode()
self.speed = float(self._seg)
self.course = float(self._seg)
def _GNVTG(self):
self.course = float(self._seg)
self.speed = float(self._seg)
def _GNGLL(self):
self.latitude = self._latlon(self._seg)
self.latitude_dir = self._seg
self.longitude = self._latlon(self._seg)
self.longitude_dir = self._seg
self._time(self._seg)
self.valid = (self._seg == b'A')
def _GNGSA(self):
self.pdop = float(self._seg)
self.hdop = float(self._seg)
self.vdop = float(self._seg)
def _GPGSV(self):
self.satellites_in_view = int(self._seg)
GNSS_CMD = {
b'GNGGA': _GNGGA,
b'GNRMC': _GNRMC,
b'GNVTG': _GNVTG,
b'GNGLL': _GNGLL,
b'GPGSV': _GPGSV,
b'GNGSA': _GNGSA
}
def info(self):
print('GNSS valid:', self.valid)
print('lat:', self.latitude, self.latitude_dir)
print('lon:', self.longitude, self.longitude_dir)
print('speed:', self.speed)
print('altitude:', self.altitude, self.geoid_height)
print('hdop:', self.hdop)
print('pdop:', self.pdop)
print('vdop:', self.vdop)
print('UTC:', self.datetime, self.date, self.time)
print('satellites')
print('in view:', self.satellites_in_view)
print('in use: ', self.satellites_in_use)
print('list: ', self.satellites_used)
def test(self, n=60, interval=1000):
from time import sleep_ms
while True:
if n > 0:
n -= 1
else:
return
self.update()
self.info()
sleep_ms(interval)
ug = UART(1, baudrate=9600, tx=0, rx=1, rxbuf=2048)
G=uGNSS(ug)
G.test()</code></pre>
<p> </p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>运行效果</p>
<p> </p>
<p> </p>
看来转换速度是非常快呀。 lugl4313820 发表于 2022-8-17 21:09
看来转换速度是非常快呀。
<p>160MHz的内核,性能还是很不错的</p>
<p>冷启动和热启动定位分别用了多久?</p>
wangerxian 发表于 2022-8-18 15:38
冷启动和热启动定位分别用了多久?
<p>这个与GNSS模块参数和测试环境有关。通常冷启动时间1-5分钟,热启动小于20秒,如果有AGPS功能,定位时间就比较短。</p>
dcexpert 发表于 2022-8-18 16:17
这个与GNSS模块参数和测试环境有关。通常冷启动时间1-5分钟,热启动小于20秒,如果有AGPS功能,定位时间 ...
<p>我之前测试过一款,天晴的情况下,冷启动时间30秒内。也是双频的。</p>
wangerxian 发表于 2022-8-18 16:34
我之前测试过一款,天晴的情况下,冷启动时间30秒内。也是双频的。
<p>与测试环境有关</p>
页:
[1]