简体   繁体   English

与Micropython配合使用时间Mac OSX Python2.7

[英]Using Time with Micropython Mac OSX Python2.7

Setup 设定

I am using a sensor fusing python module base off of the Madwick Algorithm. 我正在使用基于Madwick算法的传感器融合python模块。 The source code can be found here https://github.com/micropython-IMU/micropython-fusion/blob/master/fusion.py. 可以在这里找到源代码https://github.com/micropython-IMU/micropython-fusion/blob/master/fusion.py。

Problem 问题

Is there any way I could implement the function below pyb.elapsed_micro() and pyb.micros() without using the import pyb library with python2.7? 有什么办法可以实现pyb.elapsed_micro()pyb.micros()下面的功能,而无需在python2.7中使用导入pyb库?

    import pyb
   # Integrate to yield quaternion
    deltat = pyb.elapsed_micros(self.start_time) / 1000000
    self.start_time = pyb.micros()
    q1 += qDot1 * deltat
    q2 += qDot2 * deltat
    q3 += qDot3 * deltat
    q4 += qDot4 * deltat 
     # normalise quaternion
    norm = 1 / sqrt(q1 * q1 + q2 * q2 + q3 * q3 + q4 * q4)   
    self.q = q1 * norm, q2 * norm, q3 * norm, q4 * norm

pyb.micros() - sets starting in microseconds pyb.micros()-设置以微秒为单位

pyb.elapsed_time(start_time) - determines the elapsed time between startime and the time it took to call this function pyb.elapsed_time(start_time)-确定从开始时间到调用此函数所花费的时间之间的经过时间

Solution

import time
def micros():
    return time.time() * 1000000  ##turns seconds into microseconds

def elapsed_micros(start_time):
    return start_time - time.time()*1000000

For more support check github link to issue - https://github.com/micropython-IMU/micropython-fusion/issues/1 要获得更多支持,请检查发出的github链接-https: //github.com/micropython-IMU/micropython-fusion/issues/1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Mac OSX Lion 10.7.5 上将 python3.2 设置为默认值而不是 python2.7 - Setting python3.2 as default instead of python2.7 on Mac OSX Lion 10.7.5 尝试重新安装python2.7 mac - trying to reinstall python2.7 mac 如何在Mac OSX中使用Python 2.7更改代理设置 - How to change proxy settings using Python 2.7 in Mac OSX 使用自制软件从python2.7 Mac升级到python3.3 - Upgrading to python3.3 from python2.7 Mac using homebrew MAC OS 上的 root 用户将 python2.7 更改为 python3.7 - Change python2.7 to python3.7 for root on MAC OS 在Mac上使用Python2.7安装OpenCV 3.0.0 Beta - Installing OpenCV 3.0.0 Beta with Python2.7 on Mac 在 mac monterey 上为 python2.7 链接 uWSGI 时出错 - Error linking uWSGI for python2.7 on mac monterey Python 2.7 IDLE在Mac OSX上不断崩溃 - Python 2.7 IDLE keeps crashing on Mac OSX osx-/ usr / bin / python和/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7有什么区别? - osx - What's the difference between /usr/bin/python and /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7? pySerial 2.7,“ SyntaxError:语法无效”:在Python 3.5中导入串行错误(使用Mac OSX 10.10-优胜美地) - pySerial 2.7, 'SyntaxError: invalid syntax' : Import serial error in Python 3.5 (using Mac OSX 10.10 - Yosemite)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM