async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) fd = c.ctlr_fd buf = await eeprom_query(fd, 0xA0, 4) print(buf) await eeprom_store(fd, 0xA0, b'0000') buf = await eeprom_query(fd, 0xA0, 4) print(buf) assert buf == b'0000' await eeprom_store(fd, 0xA0, b'1234') buf = await eeprom_query(fd, 0xA1, 3) print(buf) assert buf == b'234' buf = await eeprom_query(fd, 0xA2, 2) print(buf) assert buf == b'34' buf = await eeprom_query(fd, 0xA3, 1) print(buf) assert buf == b'4' buf = await eeprom_query(fd, 0xA0, 4) print(buf) assert buf == b'1234' buf = await eeprom_query(fd, 0x0F, 5) print(buf) await eeprom_store(fd, 0x0F, b'12345') buf = await eeprom_query(fd, 0x10, 4) print(buf) assert buf == b'2345' buf = await eeprom_query(fd, 0x11, 3) print(buf) assert buf == b'345' buf = await eeprom_query(fd, 0x12, 2) print(buf) assert buf == b'45' buf = await eeprom_query(fd, 0x13, 1) print(buf) assert buf == b'5' buf = await eeprom_query(fd, 0x0F, 5) print(buf) assert buf == b'12345'
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) iface = await c.acquire('VersionInfo') name = await iface.name() version = await iface.version() await c.release(iface) await c.close() print(name, version)
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) accel = await c.acquire('Accelerometer') for i in range(1000): fmt(await accel.read()) await asyncio.sleep(0.05) await c.release(accel) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) ahrs = await c.acquire('AHRS') for i in range(10000): fmt(await ahrs.read()) await asyncio.sleep(0.05) await c.release(ahrs) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) p = await c.acquire('Photoresistor') for i in range(1000): millivolts, resistance = await p.read() print(f'{millivolts:.2f} {resistance:.0f}') await asyncio.sleep(0.1) await c.release(p) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) await asyncio.sleep(2) leds = await c.acquire('LEDs') while True: mode_map = await leds.mode_map() print(mode_map) for mode, _ in mode_map.items(): print('Setting to mode', mode) await leds.set_mode(mode) await asyncio.sleep(7) print('Clearing the mode...') await leds.set_mode(None) led_map = await leds.led_map() print(led_map) print('Turning all blue') await leds.set_many_leds([(index, (0, 0, 255)) for index in led_map]) await asyncio.sleep(1) print('Clearning LEDs') await leds.set_many_leds([(index, (0, 0, 0)) for index in led_map]) await asyncio.sleep(1) print('Setting just a few manually...') await leds.set_led(1, (255, 145, 0)) await asyncio.sleep(1) await leds.set_led(3, (0, 255, 0)) await asyncio.sleep(1) await leds.set_led(5, (0, 0, 255)) await asyncio.sleep(1) print('Playing with brightness!') for b in range(5, 255, 5): await leds.set_brightness(b) await asyncio.sleep(0.1) await c.release(leds) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) iface = await c.acquire('Credentials') labs_auth_code = await iface.get_labs_auth_code() print('Labs Auth Code:', labs_auth_code) await iface.set_labs_auth_code('something') labs_auth_code = await iface.get_labs_auth_code() print('Labs Auth Code:', labs_auth_code) await c.release(iface) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) camera = await c.acquire('Camera') prev_time = time.time() for i in range(10): buf, shape = await camera.capture() frame = np.frombuffer(buf, dtype=np.uint8).reshape(shape) time_now = time.time() print(time_now - prev_time, frame.shape) prev_time = time_now await c.release(camera) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) power = await c.acquire('Power') #for i in range(1000): while True: st = await power.state() mv = await power.millivolts() mi = await power.estimate_remaining() sd = await power.should_shut_down() cu = await power.charging_info() print(st, mv, mi, sd, cu) await asyncio.sleep(0.1) await c.release(power) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) gyro = await c.acquire('Gyroscope') gyro_accum = await c.acquire('Gyroscope_accum') for i in range(500): fmt(await gyro.read()) fmt(await gyro_accum.read()) print() if i % 50 == 0: await gyro_accum.reset() await asyncio.sleep(0.1) await c.release(gyro) await c.release(gyro_accum) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) b = await c.acquire('PushButtons') print('There are', await b.num_buttons(), 'buttons.') bi, action = await b.wait_for_action('released') print("Button", bi, "was", action) while True: event = await b.wait_for_event() pprint(event) await c.release(b) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) print('Acquiring PID_steering and CarMotors...') pid = await c.acquire('PID_steering') motors = await c.acquire('CarMotors') p, i, d = 1.0, 0.1, 0.1 await pid.set_pid(p, i, d) await pid.set_point(0.0) print('Enabling PID loop...') await pid.enable() await asyncio.sleep(5) print('Turning on CarMotors and setting throttle...') await motors.on() await motors.set_throttle(25) await asyncio.sleep(10) print('Disabling PID loop...') await pid.disable() await asyncio.sleep(5) print('Turning off CarMotors...') await motors.off() await asyncio.sleep(5) print('Releasing PID_steering and CarMotors...') await c.release(pid) await c.release(motors) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) iface = await c.acquire('VersionInfo') n = 0 start = time.time() while True: _ = await iface.version() n += 1 now = time.time() if (now - start) >= 1.0: print(n) start = now n = 0 await c.release(iface) await c.close()
async def run(): c = controller.CioRoot() caps = await c.init() pprint(caps) motors = await c.acquire('CarMotors') await motors.on() #safe = await motors.get_safe_throttle() #print(safe) #await motors.set_safe_throttle(safe[0] + 1, safe[1] + 1) safe = await motors.get_safe_throttle() print(safe) await asyncio.sleep(1) t = safe[1] for i in range(2): for v in range(-45, 45): #print(v) await motors.set_steering(v) await motors.set_throttle(t) await asyncio.sleep(0.02) for v in range(45, -45, -1): #print(v) await motors.set_steering(v) await motors.set_throttle(t) await asyncio.sleep(0.02) await motors.off() await asyncio.sleep(3) await c.release(motors) await c.close()