async def main(): script_args = parse_args() sphero = spheropy.Sphero() await sphero.connect(num_retry_attempts=3, use_ble=script_args.use_ble) await sphero.set_power_notification(True) power_state_change_detected = False def handle_power_state_change(power_state): nonlocal power_state_change_detected power_state_change_detected = True print("Power State Changed To: {}".format(power_state)) sphero.on_power_state_change.append(handle_power_state_change) await sphero.set_rgb_led(green=0xFF) for _ in range(3): await sphero.ping() await asyncio.sleep(10) if power_state_change_detected: break if not power_state_change_detected: print("FAIL: No Power State Change Detected")
async def main(): script_args = parse_args() sphero = spheropy.Sphero() await sphero.connect(num_retry_attempts=3, use_ble=script_args.use_ble) locator_info = await sphero.get_locator_info() print('Original LocatorInfo:') print('X Pos: {}'.format(locator_info.pos_x)) print('Y Pos: {}'.format(locator_info.pos_y)) print('X Velocity: {}'.format(locator_info.vel_x)) print('Y Velocity: {}'.format(locator_info.vel_y)) print('Speed Over Ground: {}'.format(locator_info.speed_over_ground)) print('Simulating aiming the Sphero') # Turn on the aiming LED await sphero.set_back_led(0xFF) # Turn off auto-correction for yaw tare await sphero.configure_locator(False) time.sleep(1) # Adjust the heading by 90 degrees await sphero.set_heading(90) time.sleep(1) # Turn on auto-correction for yay tare await sphero.configure_locator(True) await sphero.set_back_led(0) locator_info = await sphero.get_locator_info() print('New LocatorInfo:') print('X Pos: {}'.format(locator_info.pos_x)) print('Y Pos: {}'.format(locator_info.pos_y)) print('X Velocity: {}'.format(locator_info.vel_x)) print('Y Velocity: {}'.format(locator_info.vel_y)) print('Speed Over Ground: {}'.format(locator_info.speed_over_ground))
async def main(): script_args = parse_args() sphero = spheropy.Sphero() await sphero.connect(num_retry_attempts=3, use_ble=script_args.use_ble) original_bluetooth_info = await sphero.get_bluetooth_info() print("Original Bluetooth Info:") print("Name: {}".format(original_bluetooth_info.name)) print("Bluetooth Address: {}".format( original_bluetooth_info.bluetooth_address)) print("ID Colors: {}".format(original_bluetooth_info.id_colors)) print("") print("Trying to set device name to SwervySwerve.") await sphero.set_device_name("SwervySwerve") print("Completed set device name.") print("") new_bluetooth_info = await sphero.get_bluetooth_info() print("New Bluetooth Info:") print("Name: {}".format(new_bluetooth_info.name)) print("Bluetooth Address: {}".format(new_bluetooth_info.bluetooth_address)) print("ID Colors: {}".format(new_bluetooth_info.id_colors)) # Restore the original setting await sphero.set_device_name(original_bluetooth_info.name)
async def main(): script_args = parse_args() sphero = spheropy.Sphero() await sphero.connect(num_retry_attempts=3, use_ble=script_args.use_ble) original_auto_reconnect_setting = await sphero.get_auto_reconnect() print("Original Auto Reconnect Setting:") print("Is Enabled: {}".format(original_auto_reconnect_setting.is_enabled)) print("Seconds After Boot: {}".format( original_auto_reconnect_setting.seconds_after_boot)) print("") print("Trying to enable auto reconnect with:") print("Is Enabled: True") print("Seconds After Boot: 20") await sphero.set_auto_reconnect(True, 20) print("Completed set auto reconnect.") print("") new_auto_reconnect_info = await sphero.get_auto_reconnect() print("New Auto Reconnect Setting:") print("Is Enabled: {}".format(new_auto_reconnect_info.is_enabled)) print("Seconds After Boot: {}".format( new_auto_reconnect_info.seconds_after_boot)) print("") # Restore the original setting await sphero.set_auto_reconnect( original_auto_reconnect_setting.is_enabled, original_auto_reconnect_setting.seconds_after_boot)
async def main(): script_args = parse_args() sphero = spheropy.Sphero() await sphero.connect(num_retry_attempts=3, use_ble=script_args.use_ble) power_state = await sphero.get_power_state() print("Power State:") print("Record Version: {}".format(power_state.record_version)) battery_state_string = "Unknown" if power_state.battery_state is spheropy.Sphero.BATTERY_STATE_CHARGING: battery_state_string = "Charging" elif power_state.battery_state is spheropy.Sphero.BATTERY_STATE_OK: battery_state_string = "OK" elif power_state.battery_state is spheropy.Sphero.BATTERY_STATE_LOW: battery_state_string = "Low" elif power_state.battery_state is spheropy.Sphero.BATTERY_STATE_CRITICAL: battery_state_string = "Critical" print("Battery State: {}".format(battery_state_string)) print("Battery Voltage: {}".format(power_state.battery_voltage)) print("Lifetime Number of Recharges: {}".format( power_state.total_number_of_recharges)) print("Seconds Since Last Recharge: {}".format( power_state.seconds_awake_since_last_recharge))
async def main(): script_args = parse_args() sphero = spheropy.Sphero() await sphero.connect(num_retry_attempts=3, use_ble=script_args.use_ble) await sphero.set_back_led(255) time.sleep(2) await sphero.set_back_led(0)
async def main(): script_args = parse_args() sphero = spheropy.Sphero() await sphero.connect(num_retry_attempts=3, use_ble=script_args.use_ble) await sphero.set_heading(0) await sphero.set_heading(90) await sphero.set_heading(180) await sphero.set_heading(0)
async def main(): script_args = parse_args() sphero = spheropy.Sphero() await sphero.connect(num_retry_attempts=3, use_ble=script_args.use_ble) locator_info = await sphero.get_locator_info() print('LocatorInfo:') print('X Pos: {}'.format(locator_info.pos_x)) print('Y Pos: {}'.format(locator_info.pos_y)) print('X Velocity: {}'.format(locator_info.vel_x)) print('Y Velocity: {}'.format(locator_info.vel_y)) print('Speed Over Ground: {}'.format(locator_info.speed_over_ground))
async def main(): script_args = parse_args() sphero = spheropy.Sphero() await sphero.connect(num_retry_attempts=3, use_ble=script_args.use_ble) await sphero.set_rgb_led(red=0xFF) time.sleep(2) await sphero.set_rgb_led(green=0xFF) time.sleep(2) await sphero.set_rgb_led(blue=0xFF) time.sleep(2) await sphero.set_rgb_led(red=0xFF, blue=0xFF) time.sleep(2) await sphero.set_rgb_led(0xFF, 0xFF, 0xFF) time.sleep(2)
async def main(): script_args = parse_args() sphero = spheropy.Sphero() await sphero.connect(num_retry_attempts=3, use_ble=script_args.use_ble) original_user_led_color = await sphero.get_rgb_led() await sphero.set_rgb_led(red=0xFF, save_as_user_led_color=True) time.sleep(2) user_led_color = await sphero.get_rgb_led() if user_led_color != [0xFF, 0x00, 0x00]: print( "FAIL: User LED color is not red=0xFF, green=0x00, blue=0x00 as expected. Actual = {}" .format(user_led_color)) await sphero.set_rgb_led(green=0xFF, save_as_user_led_color=True) time.sleep(2) user_led_color = await sphero.get_rgb_led() if user_led_color != [0x00, 0xFF, 0x00]: print( "FAIL: User LED color is not red=0x00, green=0xFF, blue=0x00 as expected. Actual = {}" .format(user_led_color)) await sphero.set_rgb_led(blue=0xFF, save_as_user_led_color=True) time.sleep(2) user_led_color = await sphero.get_rgb_led() if user_led_color != [0x00, 0x00, 0xFF]: print( "FAIL: User LED color is not red=0x00, green=0x00, blue=0xFF as expected. Actual = {}" .format(user_led_color)) await sphero.set_rgb_led(red=0xFF, blue=0xFF, save_as_user_led_color=True) time.sleep(2) user_led_color = await sphero.get_rgb_led() if user_led_color != [0xFF, 0x00, 0xFF]: print( "FAIL: User LED color is not red=0xFF, green=0x00, blue=0xFF as expected. Actual = {}" .format(user_led_color)) # Restore the original setting await sphero.set_rgb_led(original_user_led_color[0], original_user_led_color[1], original_user_led_color[2], save_as_user_led_color=True) time.sleep(2)
async def main(): script_args = parse_args() sphero = spheropy.Sphero() await sphero.connect(num_retry_attempts=3, use_ble=script_args.use_ble) self_level_result_received = False def handle_complete(result): nonlocal self_level_result_received self_level_result_received = True print(f'Result: {result}') sphero.on_self_level_complete.append(handle_complete) await sphero.self_level() await asyncio.sleep(5) if not self_level_result_received: print("FAIL: Result not received.")
async def main(): script_args = parse_args() sphero = spheropy.Sphero() await sphero.connect(num_retry_attempts=3, use_ble=script_args.use_ble) await sphero.roll(127, 0, wait_for_response=False) time.sleep(0.5) await sphero.roll(127, 90) time.sleep(0.5) await sphero.roll(127, 180) time.sleep(0.5) await sphero.roll(127, 270) time.sleep(0.5) await sphero.roll(16, 0) time.sleep(0.5) await sphero.roll(255, 180) time.sleep(0.5) await sphero.roll(0, 0)
async def main(): script_args = parse_args() sphero = spheropy.Sphero() await sphero.connect(num_retry_attempts=3, use_ble=script_args.use_ble) # Ping the sphero and wait for a response. # Do this a few times to validate # sequence_number handling. await sphero.ping() await sphero.ping() await sphero.ping() # Ping the Sphero a few times, # but don't wait until all have been started. await asyncio.gather(sphero.ping(), sphero.ping(), sphero.ping()) # Ping the sphero but don't request/wait for a response await sphero.ping(wait_for_response=False) # Don't reset the inactivity timeout await sphero.ping(wait_for_response=False, reset_inactivity_timeout=False)
async def main(): script_args = parse_args() sphero = spheropy.Sphero() await sphero.connect(num_retry_attempts=3, use_ble=script_args.use_ble) version_info = await sphero.get_version_info() print("Version Info:") print("Record Version: {}".format(version_info.record_version)) print("Model Number: {}".format(version_info.model_number)) print("Hardware Version: {}".format(version_info.hardware_version)) print("Main Sphero Application Version: {}".format( version_info.main_sphero_app_version)) print("Main Sphero Application Revision: {}".format( version_info.main_sphero_app_revision)) print("Bootloader Version: {}".format(version_info.bootloader_version)) print("OrbBasic Version: {}".format(version_info.orb_basic_version)) print("Macro Executive Version: {}".format( version_info.macro_executive_version)) print("Firmware API Major Version: {}".format( version_info.firmware_api_major_revision)) print("Firmware API Minor Version: {}".format( version_info.firmware_api_major_revision))
async def main(): script_args = parse_args() sphero = spheropy.Sphero() await sphero.connect(num_retry_attempts=3, use_ble=script_args.use_ble) await sphero.configure_collision_detection(True, 45, 110, 45, 110, 20) collision_detected = False def handle_collision(collision_data): nonlocal collision_detected collision_detected = True event_loop = asyncio.new_event_loop() event_loop.run_until_complete(sphero.roll(0, 0)) event_loop.run_until_complete(sphero.set_rgb_led(red=0xFF)) print("Collision Data:") print("X Impact: {}".format(collision_data.x_impact)) print("Y Impact: {}".format(collision_data.y_impact)) print("Z Impact: {}".format(collision_data.z_impact)) print("Axis: {}".format(collision_data.axis)) print("X Magnitude: {}".format(collision_data.x_magnitude)) print("Y Magnitude: {}".format(collision_data.y_magnitude)) print("Speed: {}".format(collision_data.speed)) print("Timestamp: {}".format(collision_data.timestamp)) time.sleep(4) sphero.on_collision.append(handle_collision) await sphero.set_rgb_led(green=0xFF) await sphero.roll(127, 0) await asyncio.sleep(10) if not collision_detected: print("FAIL: collision not detected.") await sphero.roll(0, 0) await sphero.set_rgb_led(blue=0xFF) await asyncio.sleep(4)
# Convert it to a numpy.array. input_data = np.array(random_input, dtype=np.uint8) benchmark_time = timeit.timeit( lambda: engine.run_inference(input_data), number=iterations) # Time consumed for each iteration (milliseconds). time_per_inference = (benchmark_time / iterations) * 1000 print(time_per_inference, 'ms (iterations = ', iterations, ')') return time_per_inference if __name__ == '__main__': args = test_utils.parse_args() machine = test_utils.machine_info() test_utils.check_cpu_scaling_governor_status() # Read references from csv file. model_list, reference = test_utils.read_reference( 'basic_engine_reference_%s.csv' % machine) total_models = len(model_list) # Put column names in first row. results = [('MODEL', 'INFERENCE_TIME')] for cnt, model in enumerate(model_list, start=1): print('-------------- Model ', cnt, '/', total_models, ' ---------------') results.append((model, _run_benchmark_for_model(model))) test_utils.save_as_csv( 'basic_engine_benchmarks_%s_%s.csv' % ( machine, time.strftime('%Y%m%d-%H%M%S')), results)
else: raise NotImplementedError @timer def fit_(pca, X, model): pca.fit(X) return pca @timer def transform_(pca, X, model): return pca.transform(X) pca = fit_(pca, X, model=model) Xpca = transform_(pca, X, model=model) pca.transformed_result = lambda: None setattr(pca, 'transformed_result', Xpca) return pca if __name__ == '__main__': args = parse_args() write_log(args) test_pca_mortgage(data_source=args.data, use_assert=args.use_assert, nrows=args.nrows, ncols=args.ncols, quarters=args.quarters, random_state=args.random_state, test_model=args.test_model, threshold=args.threshold)