当前位置: 首页>>代码示例>>Python>>正文


Python utime.ticks_us方法代码示例

本文整理汇总了Python中utime.ticks_us方法的典型用法代码示例。如果您正苦于以下问题:Python utime.ticks_us方法的具体用法?Python utime.ticks_us怎么用?Python utime.ticks_us使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utime的用法示例。


在下文中一共展示了utime.ticks_us方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update

# 需要导入模块: import utime [as 别名]
# 或者: from utime import ticks_us [as 别名]
def update(self):
        if time.ticks_us() >= self.interval:
            self.interval = time.ticks_us() + 10000

            if not self.angle_point == None:
                self.input_value = self.encoder_read() - self.enc_zero
                output_value = self.angle_pid.get_pid(self.input_value, self.angle_point)
                self.set_pwm(output_value)

            if not self.speed_point == None:
                # Encoder filter
                self.input_value *= 0.75
                self.input_value += self.encoder_incr() * 0.25
                # self.input_value = constrain(self.input_value, -30, 30)
                # Output pwm
                output_value = self.speed_pid.get_pid(self.input_value, self.speed_point)
                self.set_pwm(output_value)
                # print("in:%0.2f, out:%0.2f\r\n" % (self.input_value, output_value)) 
开发者ID:m5stack,项目名称:UIFlow-Code,代码行数:20,代码来源:_legoBoard.py

示例2: test

# 需要导入模块: import utime [as 别名]
# 或者: from utime import ticks_us [as 别名]
def test():
    """Bouncing sprite."""
    try:
        # Baud rate of 14500000 seems about the max
        spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23))
        display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16))
        display.clear()

        # Load sprite
        logo = BouncingSprite('images/Python41x49.raw',
                              41, 49, 128, 128, 1, display)

        while True:
            timer = ticks_us()
            logo.update_pos()
            logo.draw()
            # Attempt to set framerate to 30 FPS
            timer_dif = 33333 - ticks_diff(ticks_us(), timer)
            if timer_dif > 0:
                sleep_us(timer_dif)

    except KeyboardInterrupt:
        display.cleanup() 
开发者ID:rdagger,项目名称:micropython-ssd1351,代码行数:25,代码来源:demo_sprite.py

示例3: run

# 需要导入模块: import utime [as 别名]
# 或者: from utime import ticks_us [as 别名]
def run(self, conversion):          # Uses assembler for speed
        if self.popfunc is not None:
            self.popfunc(self)          # Populate the data (for fwd transfers, just the real data)
        if conversion != REVERSE:       # Forward transform: real data assumed
            setarray(self.im, 0, self._length)# Fast zero imaginary data
            if self.windata is not None:  # Fast apply the window function
                winapply(self.re, self.windata, self._length)
        start = utime.ticks_us()
        fft(self.ctrl, conversion)
        delta = utime.ticks_diff(utime.ticks_us(), start)
        if (conversion & POLAR) == POLAR: # Ignore complex conjugates, convert 1st half of arrays
            topolar(self.re, self.im, self._length//2) # Fast
            if conversion == DB:        # Ignore conjugates: convert 1st half only
                for idx, val in enumerate(self.re[0:self._length//2]):
                    self.re[idx] = -80.0 if val <= 0.0 else 20*math.log10(val) - self.dboffset
        return delta
# Subclass for acquiring data from Pyboard ADC using read_timed() method. 
开发者ID:peterhinch,项目名称:micropython-fourier,代码行数:19,代码来源:dftclass.py

示例4: __call__

# 需要导入模块: import utime [as 别名]
# 或者: from utime import ticks_us [as 别名]
def __call__(self, ts):
        if self.expect_ts:
            if ts is None:
                raise ValueError('Timestamp expected but not supplied.')
        else:
            if is_micropython:
                ts = time.ticks_us()
            else:
                raise RuntimeError('Not MicroPython: provide timestamps and a timediff function')
        # ts is now valid
        if self.start_time is None:  # 1st call: self.start_time is invalid
            self.start_time = ts
            return 0.0001  # 100μs notional delay. 1st reading is invalid in any case

        dt = self.timediff(ts, self.start_time)
        self.start_time = ts
        return dt 
开发者ID:micropython-IMU,项目名称:micropython-fusion,代码行数:19,代码来源:deltat.py

示例5: timed_function

# 需要导入模块: import utime [as 别名]
# 或者: from utime import ticks_us [as 别名]
def timed_function(f, *args, **kwargs):
        #myname = str(f).split(' ')[1]

        def new_func(*args, **kwargs):
            #t = utime.ticks_us()
            result = f(*args, **kwargs)

            #if myname not in profile_stats_time_including_children:
            #    profile_stats_time_including_children[myname] = 0
            #    profile_stats_calls[myname] = 0

            #profile_stats_time_including_children[myname] += utime.ticks_diff(utime.ticks_us(), t)
            #profile_stats_calls[myname] += 1

            return result

        return new_func 
开发者ID:dwalton76,项目名称:rubiks-color-resolver,代码行数:19,代码来源:profile.py

示例6: get_t_split

# 需要导入模块: import utime [as 别名]
# 或者: from utime import ticks_us [as 别名]
def get_t_split(self):
        state = machine.disable_irq()
        t = self.t_ms
        acquired = self.acquired
        machine.enable_irq(state)
        isecs, ims = divmod(t, 1000)  # Get integer secs and ms
        x, secs = divmod(isecs, 60)
        hrs, mins = divmod(x, 60)
        dt = utime.ticks_diff(utime.ticks_us(), acquired)  # μs to time now
        ds, us = divmod(dt, 1000000)
        # If dt > 1e6 can add to secs without risk of rollover: see above.
        self._time[0] = hrs
        self._time[1] = mins
        self._time[2] = secs + ds
        self._time[3] = us + ims*1000
        return self._time 
开发者ID:peterhinch,项目名称:micropython-async,代码行数:18,代码来源:as_tGPS.py

示例7: __init__

# 需要导入模块: import utime [as 别名]
# 或者: from utime import ticks_us [as 别名]
def __init__(self, i2c=None):
        if i2c is None:
            self.i2c = i2c_bus.get(i2c_bus.M_BUS)
        else:
            self.i2c = i2c
        self.imu = MPU6050(self.i2c)

        if self.i2c.is_ready(M5GO_WHEEL_ADDR) or self.i2c.is_ready(M5GO_WHEEL_ADDR):
            pass
        else:
            raise ImportError("Bala Motor not connect")

        self.id = self.imu.whoami
        # self.set_motor(0, 0)
        self.imu.setGyroOffsets(-2.71, -0.01, -0.04)
        self.loop_interval = time.ticks_us()
        self.dt = time.ticks_us()
        self.angleX = 0
        self.angleX_offset = 0
        self.last_angle = 0.0
        self.last_wheel = 0.0
        self.in_speed0 = 0
        self.in_speed1 = 0
        self.left = 0
        self.right = 0
        self.K1 = 40
        self.K2 = 40
        self.K3 = 6.5
        self.K4 = 5.5
        self.K5 = 0
        self.enc_filter = 0.90 
开发者ID:m5stack,项目名称:UIFlow-Code,代码行数:33,代码来源:_m5bala.py

示例8: ypr

# 需要导入模块: import utime [as 别名]
# 或者: from utime import ticks_us [as 别名]
def ypr(self):
        """
        yaw, pitch, roll as floats.
        """
        accX, accY, accZ = self.acceleration

        angleAccX = math.atan2(accY, accZ + abs(accX)) * SF_RAD_S
        angleAccY = math.atan2(accX, accZ + abs(accY)) * (-SF_RAD_S);

        gyroX, gyroY, gyroZ = self.gyro
        gyroX -= self.gyroXoffset
        gyroY -= self.gyroYoffset
        gyroZ -= self.gyroZoffset

        interval = (time.ticks_us() - self.preInterval) / 1000000
        self.preInterval = time.ticks_us()

        self.angleGyroX += gyroX * interval
        self.angleGyroY += gyroY * interval
        self.angleGyroZ += gyroZ * interval

        self.angleX = (self.gyroCoef * (self.angleX + gyroX * interval)) + (self.accCoef * angleAccX);
        self.angleY = (self.gyroCoef * (self.angleY + gyroY * interval)) + (self.accCoef * angleAccY);
        self.angleZ = self.angleGyroZ

        return tuple([round(self.angleZ, 3), round(self.angleX, 3), round(self.angleY, 3)]) 
开发者ID:m5stack,项目名称:UIFlow-Code,代码行数:28,代码来源:mpu6050.py

示例9: _run

# 需要导入模块: import utime [as 别名]
# 或者: from utime import ticks_us [as 别名]
def _run(self):
        while True:
            # If hardware link exists reboot Responder
            await self.reboot()
            self.txbyt = b''
            self.rxbyt = b''
            await self._sync()
            await asyncio.sleep(1)  # Ensure Responder is ready
            if self.cr_go:
                asyncio.create_task(self.cr_go(*self.go_args))
            while True:
                gc.collect()
                try:
                    tstart = utime.ticks_us()
                    self._sendrx()
                    t = utime.ticks_diff(utime.ticks_us(), tstart)
                except OSError:  # Reboot remote.
                    break
                await asyncio.sleep_ms(Initiator.t_poll)
                self.block_max = max(self.block_max, t)  # self measurement
                self.block_cnt += 1
                self.block_sum += t
            self.nboots += 1
            if self.cr_fail:
                await self.cr_fail(*self.f_args)
            if self.reset is None:  # No means of recovery
                raise OSError('Responder fail.') 
开发者ID:peterhinch,项目名称:micropython-iot,代码行数:29,代码来源:asi2c_i.py

示例10: test

# 需要导入模块: import utime [as 别名]
# 或者: from utime import ticks_us [as 别名]
def test():
    """Bouncing box."""
    try:
        # Baud rate of 14500000 seems about the max
        spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23))
        display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16))
        display.clear()

        colors = [color565(255, 0, 0),
                  color565(0, 255, 0),
                  color565(0, 0, 255),
                  color565(255, 255, 0),
                  color565(0, 255, 255),
                  color565(255, 0, 255)]
        sizes = [12, 11, 10, 9, 8, 7]
        boxes = [Box(128, 128, sizes[i], display,
                 colors[i]) for i in range(6)]

        while True:
            timer = ticks_us()
            for b in boxes:
                b.update_pos()
                b.draw()
            # Attempt to set framerate to 30 FPS
            timer_dif = 33333 - ticks_diff(ticks_us(), timer)
            if timer_dif > 0:
                sleep_us(timer_dif)

    except KeyboardInterrupt:
        display.cleanup() 
开发者ID:rdagger,项目名称:micropython-ssd1351,代码行数:32,代码来源:demo_bouncing_boxes.py

示例11: getcal

# 需要导入模块: import utime [as 别名]
# 或者: from utime import ticks_us [as 别名]
def getcal(self, minutes=5, cal=0, verbose=True):
        if d_series:
            return self._getcal_d(minutes, cal, verbose)
        verbose and print('Pyboard 1.x. Waiting {} minutes for calibration factor.'.format(minutes))
        rtc.calibration(cal)  # Clear existing cal
        self.save_time()  # Set DS3231 from RTC
        self.await_transition()  # Wait for DS3231 to change: on a 1 second boundary
        tus = utime.ticks_us()
        st = rtc.datetime()[7]
        while rtc.datetime()[7] == st:  # Wait for RTC to change
            pass
        t1 = utime.ticks_diff(utime.ticks_us(), tus)  # t1 is duration (μs) between DS and RTC change (start)
        rtcstart = get_ms(rtc.datetime())  # RTC start time in mS
        dsstart = utime.mktime(self.convert())  # DS start time in secs as recorded by await_transition

        utime.sleep(minutes * 60)

        self.await_transition()  # DS second boundary
        tus = utime.ticks_us()
        st = rtc.datetime()[7]
        while rtc.datetime()[7] == st:
            pass
        t2 = utime.ticks_diff(utime.ticks_us(), tus)  # t2 is duration (μs) between DS and RTC change (end)
        rtcend = get_ms(rtc.datetime())
        dsend = utime.mktime(self.convert())
        dsdelta = (dsend - dsstart) * 1000000  # Duration (μs) between DS edges as measured by DS3231
        if rtcend < rtcstart:  # It's run past midnight. Assumption: run time < 1 day!
            rtcend += 24 * 3_600_000
        rtcdelta = (rtcend - rtcstart) * 1000 + t1 - t2  # Duration (μs) between DS edges as measured by RTC and corrected
        ppm = (1000000* (rtcdelta - dsdelta))/dsdelta
        if cal:
            verbose and print('Error {:4.1f}ppm {:4.1f}mins/year.'.format(ppm, ppm * 1.903))
            return 0
        cal = int(-ppm / 0.954)
        verbose and print('Error {:4.1f}ppm {:4.1f}mins/year. Cal factor {}'.format(ppm, ppm * 1.903, cal))
        return cal

    # Version for Pyboard D. This has μs resolution. 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:40,代码来源:ds3231_pb.py

示例12: x_callback

# 需要导入模块: import utime [as 别名]
# 或者: from utime import ticks_us [as 别名]
def x_callback(self, line):
        self.forward = self.pin_x.value() ^ self.pin_y.value() ^ self.reverse
        self._pos += 1 if self.forward else -1
        self.tprev = self.tlast
        self.tlast = utime.ticks_us() 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:7,代码来源:encoder_timed.py

示例13: y_callback

# 需要导入模块: import utime [as 别名]
# 或者: from utime import ticks_us [as 别名]
def y_callback(self, line):
        self.forward = self.pin_x.value() ^ self.pin_y.value() ^ self.reverse ^ 1
        self._pos += 1 if self.forward else -1
        self.tprev = self.tlast
        self.tlast = utime.ticks_us() 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:7,代码来源:encoder_timed.py

示例14: rate

# 需要导入模块: import utime [as 别名]
# 或者: from utime import ticks_us [as 别名]
def rate(self):                                         # Return rate in edges per second
        self.x_interrupt.disable()
        self.y_interrupt.disable()
        if ticksdiff(self.tlast, utime.ticks_us) > 2000000: # It's stopped
            result = 0.0
        else:
            result = 1000000.0/(ticksdiff(self.tprev, self.tlast))
        self.x_interrupt.enable()
        self.y_interrupt.enable()
        result *= self.scale
        return result if self.forward else -result 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:13,代码来源:encoder_timed.py

示例15: timed_function

# 需要导入模块: import utime [as 别名]
# 或者: from utime import ticks_us [as 别名]
def timed_function(f, *args, **kwargs):
    def new_func(*args, **kwargs):
        t = utime.ticks_us()
        result = f(*args, **kwargs)
        delta = utime.ticks_diff(utime.ticks_us(), t) 
        print('Function {} Time = {:6.3f}ms'.format(f.__name__, delta/1000))
        return result
    return new_func 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:10,代码来源:timed_func.py


注:本文中的utime.ticks_us方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。