Example #1
0
def lcd_thread(mylcd, imu, sw):
    if sw.value() == 1:
        mylcd[0] = "Calibrate. Push switch"
        mylcd[1] = "when done"
        yield from wait(0.1)
        fuse.calibrate(imu.mag.xyz, lambda : not sw.value(), waitfunc)
        print(fuse.magbias)
    mylcd[0] = "{:5s}{:5s} {:5s}".format("Yaw","Pitch","Roll")
    count = 0
    while True:
        yield from wait(0.02) # imu updates at 50Hz
        count += 1
        if count % 25 == 0:
            mylcd[1] = "{:4.0f} {:4.0f}  {:4.0f}".format(fuse.heading, fuse.pitch, fuse.roll)
        fuse.update(imu.accel.xyz, imu.gyro.xyz, imu.mag.xyz)
Example #2
0
def _future(objSched, time_to_run, callback, callback_args):
    yield  # No initialisation to do
    yield from wait(time_to_run)
    t = type(callback)
    if t is FunctionType or t is MethodType:
        callback(*callback_args)
    elif t is ThreadType:  # Generator function (thread)
        objSched.add_thread(callback(*callback_args))
    else:
        raise ValueError('future() received an invalid callback')
def lcd_thread(mylcd,mpu9150):
    k = mpu9150.mag_correction
    mylcd[1] = "x {:5.3f} y {:5.3f} z {:5.3f}".format(k[0],k[1],k[2])
    while True:
        reason = (yield Poller(pollfunc, (mpu9150,)))       # Scheduler returns when pollfunc
        if reason[1] == 1:                                  # returns something other than None. 1 indicates ready.
            xyz = mpu9150.mag.xyz
            mylcd[0] = "x {:5.1f} y {:5.1f} z {:5.1f}".format(xyz[0], xyz[1], xyz[2])
        elif reason[1] == 2:
            mylcd[0] = "Mag read failure"
        yield from wait(0.5)
def accelthread():
    accelhw = pyb.Accel()                                   # Instantiate accelerometer hardware
    yield from wait(0.03)                                   # Allow accelerometer to settle
    accel = Accelerometer(accelhw)
    wf = Poller(accel.poll, (4,), 2)                        # Instantiate a Poller with 2 second timeout.
    while True:
        reason = (yield wf())
        if reason[1]:                                       # Value has changed
            print("Value x:{:3d} y:{:3d} z:{:3d}".format(accel.x, accel.y, accel.z))
        if reason[2]:
            print("Timeout waiting for accelerometer change")
Example #5
0
def lcd_thread(mylcd, mpu9150):
    k = mpu9150.mag_correction
    mylcd[1] = "x {:5.3f} y {:5.3f} z {:5.3f}".format(k[0], k[1], k[2])
    while True:
        reason = (yield Poller(pollfunc,
                               (mpu9150, )))  # Scheduler returns when pollfunc
        if reason[
                1] == 1:  # returns something other than None. 1 indicates ready.
            xyz = mpu9150.mag.xyz
            mylcd[0] = "x {:5.1f} y {:5.1f} z {:5.1f}".format(
                xyz[0], xyz[1], xyz[2])
        elif reason[1] == 2:
            mylcd[0] = "Mag read failure"
        yield from wait(0.5)
Example #6
0
def master(lcd):
    yield Roundrobin()
    m = rf.Master(testbox_config)
    send_msg = FromMaster()
    while True:
        start = pyb.millis()
        result = m.exchange(send_msg)
        t = pyb.elapsed_millis(start)
        lcd[1] = 't = {}mS'.format(t)
        if result is not None:
            lcd[0] = str(result.i0)
        else:
            lcd[0] = 'Timeout'
        yield from wait(1.0)
        send_msg.i0 += 1
Example #7
0
def master(lcd):
    yield Roundrobin()
    m = rf.Master(testbox_config)
    send_msg = FromMaster()
    while True:
        start = pyb.millis()
        result = m.exchange(send_msg)
        t = pyb.elapsed_millis(start)
        lcd[1] = "t = {}mS".format(t)
        if result is not None:
            lcd[0] = str(result.i0)
        else:
            lcd[0] = "Timeout"
        yield from wait(1.0)
        send_msg.i0 += 1
Example #8
0
def master(lcd):
    yield Roundrobin()
    m = rp.Master(config_master)
    obj = [0, '']
    x = ord('a')
    while True:
        start = pyb.millis()
        try:
            result = m.exchange(obj)
            t = pyb.elapsed_millis(start)
        except OSError:
            t = pyb.elapsed_millis(start)
            lcd[0] = 'Timeout'
        else:
            lcd[0] = str(result)
        finally:
            lcd[1] = 't = {}mS'.format(t)
        yield from wait(1.0)
        obj[0] += 1
Example #9
0
def master(lcd):
    yield Roundrobin()
    m = rp.Master(config_master)
    obj = [0, '']
    x = ord('a')
    while True:
        start = pyb.millis()
        try:
            result = m.exchange(obj)
            t = pyb.elapsed_millis(start)
        except OSError:
            t = pyb.elapsed_millis(start)
            lcd[0] = 'Timeout'
        else:
            lcd[0] = str(result)
        finally:
            lcd[1] = 't = {}mS'.format(t)
        yield from wait(1.0)
        obj[0] += 1
def stop(fTim, objSch):                                     # Stop the scheduler after fTim seconds
    yield from wait(fTim)
    objSch.stop()
def toggle(objLED, time):
    while True:
        yield from wait(time)
        objLED.toggle()
Example #12
0
def lcd_thread(mylcd):
    mylcd[0] = "MicroPython"
    while True:
        mylcd[1] = "{:11d}uS".format(pyb.micros())
        yield from wait(1)
def subthread(lstResult):                                   # Gets a list for returning result(s) to caller
    yield Roundrobin()
    print("Subthread started")                              # In this test list simply contains a boolean
    yield from wait(1)
    print("Subthread end")
    lstResult[0] = True
def toggle(objLED, time):
    while True:
        yield from wait(time)
        objLED.toggle()
Example #15
0
def lcd_thread(mylcd):
    mylcd[0] = "MicroPython"
    while True:
        mylcd[1] = "{:11d}uS".format(pyb.micros())
        yield from wait(1)
Example #16
0
def subthread(lstResult):  # Gets a list for returning result(s) to caller
    yield Roundrobin()
    print("Subthread started")  # In this test list simply contains a boolean
    yield from wait(1)
    print("Subthread end")
    lstResult[0] = True
def stop(fTim, objSch):                                     # Stop the scheduler after fTim seconds
    yield from wait(fTim)
    objSch.stop()
Example #18
0
def waitfunc():
    yield from wait(0.1)