本文整理汇总了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))
示例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()
示例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.
示例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
示例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
示例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
示例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
示例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)])
示例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.')
示例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()
示例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.
示例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()
示例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()
示例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
示例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