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) 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) 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_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) 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) 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)
async def main(): script_args = parse_args() sphero = Sphero() await sphero.connect(num_retry_attempts=3, use_ble=script_args.use_ble) await test_set_rgb_led(sphero) await test_ping(sphero)