gps.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:drone 作者: arunsoman 项目源码 文件源码
def start_recording(self):
        print("inside gps")
        self.port.write(b"$PMTK397,0*23F\r\n")
        self.port.write(b"$PMTK397,0.2*3F\r\n")
        self.port.write(b"$PMTK220,100*2F\r\n")
        while self.shutdown:
            fd = self.port.readline()
            if fd.startswith(b'$GPRMC'):
                # print("*******", fd)
                result = fd.split(b',')
                if result[2] == b'A':
                    now = time.time()
                    self.activated = True

                    try:
                        lat = int(result[3][:2]) + float(result[3][2:].decode('ascii',errors='ignore'))/60
                        lon = int(result[5][:3]) + float(result[5][3:].decode('ascii',errors='ignore')) / 60
                        # if self.long != lon or self.lat != lat:
                        #     dist = vincenty((self.lat, self.long),(lat,lon)).meters
                        #     speed = dist/ (now - self.last_time)
                        #     print("speed from latlong", speed)
                        #     for cb in self.callbacks:
                        #         cb(speed)
                        self.lat, self.long,self.last_time = lat, lon, now
                    except Exception as oops:
                        print(oops)

                else:
                    self.activated = False

                    # now = time.time()
                    # dist = vincenty((self.lat, self.long),(lat,lon)).meters / (current[3] - self.latlong[3])
                    # current[3] = velocity
                    # self.latlong = current
                    # print("latlongg..", self.lat, self.long)
            if fd.startswith(b'$GPVTG'):
                if self.activated:
                    print(fd)
                    result = fd.split(b',')
                    try:
                        gps_speed = float(result[7].decode('ascii',errors='ignore'))
                        print("speed from gps", gps_speed)

                        for cb in self.callbacks:
                            cb(gps_speed)

                    except Exception as oops:
                        print(oops)
            else:
                # print("ignoring..", fd)
                pass
            yield from asyncio.sleep(0.1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号