资源简介

实现 MPU6050 DMP解算欧拉角后的姿态显示上位机。

资源截图

代码片段和文件信息

#!/usr/bin/python



# eMPL_client.py

# A PC application for use with embedded MotionApps.

# Copyright 2012 InvenSense Inc. All Rights Reserved.



import serial sys time string pygame

from ponycube import *



class eMPL_packet_reader:

    def __init__(self port quat_delegate=None debug_delegate=None data_delegate=None ):

        self.s = serial.Serial(port115200)

        self.s.setTimeout(0.1)

        self.s.setWriteTimeout(0.2)

# TODO: Will this break anything?

            ##Client attempts to write to eMPL.

            #try:

            #self.s.write(“\n“)

            #except serial.serialutil.SerialTimeoutException:

            #pass # write will timeout if umpl app is already started.



        if quat_delegate:

            self.quat_delegate = quat_delegate

        else:

            self.quat_delegate = empty_packet_delegate()



        if debug_delegate:

            self.debug_delegate = debug_delegate

        else:

            self.debug_delegate = empty_packet_delegate()



        if data_delegate:

            self.data_delegate = data_delegate

        else:

            self.data_delegate = empty_packet_delegate()



        self.packets = []

        self.length = 0

        self.previous = None



    def read(self):

        NUM_BYTES = 23

        p = None

        while self.s.inWaiting() >= NUM_BYTES:

            rs = self.s.read(NUM_BYTES)

            if ord(rs[0]) == ord(‘$‘):

                pkt_code = ord(rs[1])

                if pkt_code == 1:

                    d = debug_packet(rs)

                    self.debug_delegate.dispatch(d)

                elif pkt_code == 2:

                    p = quat_packet(rs)

                    self.quat_delegate.dispatch(p) 

                elif pkt_code == 3:

                    d = data_packet(rs)

                    self.data_delegate.dispatch(d)

                else:

                    print “no handler for pkt_code“pkt_code

            else:

                c = ‘ ‘

                print “serial misaligned!“

                while not ord(c) == ord(‘$‘):

                    c = self.s.read(1)

                self.s.read(NUM_BYTES-1)



    def write(selfa):

        self.s.write(a)



    def close(self):

        self.s.close()



    def write_log(selffname):

        f = open(fname‘w‘)

        for p in self.packets:

            f.write(p.logfile_line())

        f.close()



# ===========  PACKET DELEGATES  ==========



class packet_delegate(object):

    def loop(selfevent):

        print “generic packet_delegate loop w/event“event

    def dispatch(selfp):

        print “generic packet_delegate dispatched“p



class empty_packet_delegate(packet_delegate):

    def loop(selfevent):

        pass

    def dispatch(selfp):

        pass



class cube_packet_viewer (packet_delegate):

    def __init__(self):

        self.sc

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件       10846  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\eMPL-client.py
     文件       71651  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\euclid.py
     文件       94360  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\euclid.pyc
     文件        5921  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\ponycube.py
     文件        9815  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\ponycube.pyc
     文件          76  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\python╔╧╬╗╗·╦╡├≈.txt
     文件     6438912  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pygame-1.9.2a0.win32-py2.7.msi
     文件      116289  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6.tar.gz
     文件         521  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\python░ⁿ╦╡├≈.txt
     文件       13700  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6\CHANGES.txt
     文件        2850  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6\LICENSE.txt
     文件         968  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6\MANIFEST.in
     文件        1399  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6\PKG-INFO
     文件        1237  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6\README.txt
     文件        3215  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6\setup.py
     文件        5896  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6\documentation\appendix.rst
     文件        6524  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6\documentation\conf.py
     文件       14262  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6\documentation\examples.rst
     文件         979  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6\documentation\index.rst
     文件        2997  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6\documentation\Makefile
     文件        4310  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6\documentation\pyparallel.rst
     文件        7050  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6\documentation\pyserial.png
     文件        3803  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6\documentation\pyserial.rst
     文件       29114  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6\documentation\pyserial_api.rst
     文件        3353  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6\documentation\shortintro.rst
     文件        2169  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6\examples\enhancedserial.py
     文件       16973  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6\examples\port_publisher.py
     文件        1054  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6\examples\port_publisher.sh
     文件        6685  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6\examples\rfc2217_server.py
     文件         762  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6\examples\scan.py
     文件         481  2020-07-29 10:47  ╣┘╖╜Python╔╧╬╗╗·\╨Φ╥¬░▓╫░╡─python░ⁿ\pyserial-2.6\examples\scanlinux.py
............此处省略37个文件信息

评论

共有 条评论