コード例 #1
0
 def set_head_position(toy: Toy,
                       head_position: float,
                       not_supported_handler: Callable[[], None] = None):
     if toy.implements(Animatronic.set_head_position):
         toy.set_head_position(head_position)
     elif not_supported_handler:
         not_supported_handler()
コード例 #2
0
 def stop_robot_to_robot_infrared_evading(toy: Toy,
                                          not_supported_handler: Callable[
                                              [], None] = None):
     if toy.implements(Sensor.stop_robot_to_robot_infrared_evading):
         toy.stop_robot_to_robot_infrared_evading()
     elif not_supported_handler:
         not_supported_handler()
コード例 #3
0
 def set_locator_flags(toy: Toy,
                       flag: bool,
                       not_supported_handler: Callable[[], None] = None):
     if toy.implements(Sensor.set_locator_flags):
         toy.set_locator_flags(flag)
     elif not_supported_handler:
         not_supported_handler()
コード例 #4
0
 def set_color_detection(toy: Toy,
                         enable: bool,
                         not_supported_handler: Callable[[], None] = None):
     if toy.implements(Sensor.enable_color_detection):
         toy.enable_color_detection(enable)
     elif not_supported_handler:
         not_supported_handler()
コード例 #5
0
 def perform_leg_action(toy: Toy,
                        leg_action: R2LegActions,
                        not_supported_handler: Callable[[], None] = None):
     if toy.implements(Animatronic.perform_leg_action):
         toy.perform_leg_action(leg_action)
     elif not_supported_handler:
         not_supported_handler()
コード例 #6
0
 def play_animation(toy: Toy,
                    animation: IntEnum,
                    wait: bool = False,
                    not_supported_handler: Callable[[], None] = None):
     if toy.implements(Animatronic.play_animation):
         toy.play_animation(animation, wait)
     elif not_supported_handler:
         not_supported_handler()
コード例 #7
0
 def start_robot_to_robot_infrared_evading(
         toy: Toy,
         far: int,
         near: int,
         not_supported_handler: Callable[[], None] = None):
     if toy.implements(Sensor.start_robot_to_robot_infrared_evading):
         toy.start_robot_to_robot_infrared_evading(far, near)
     elif not_supported_handler:
         not_supported_handler()
コード例 #8
0
 def listen_for_robot_to_robot_infrared_message(
         toy: Toy,
         channels: Iterable[int],
         duration: int,
         not_supported_handler: Callable[[], None] = None):
     # TODO: BOLT
     if toy.implements(Sensor.enable_robot_infrared_message_notify):
         toy.enable_robot_infrared_message_notify(True)
     elif not_supported_handler:
         not_supported_handler()
コード例 #9
0
 def set_led_matrix_one_colour(
         toy: Toy,
         r: int,
         g: int,
         b: int,
         not_supported_handler: Callable[[], None] = None):
     if toy.implements(IO.set_compressed_frame_player_one_color):
         toy.set_compressed_frame_player_one_color(r, g, b)
     elif not_supported_handler:
         not_supported_handler()
コード例 #10
0
 def play_sound(toy: Toy,
                sound: IntEnum,
                force_play: bool,
                not_supported_handler: Callable[[], None] = None):
     if toy.implements(IO.play_audio_file):
         toy.play_audio_file(
             sound, AudioPlaybackModes.PLAY_IMMEDIATELY
             if force_play else AudioPlaybackModes.PLAY_ONLY_IF_NOT_PLAYING)
     elif not_supported_handler:
         not_supported_handler()
コード例 #11
0
 def send_robot_to_robot_infrared_message(
         toy: Toy,
         channel: int,
         intensity: int,
         not_supported_handler: Callable[[], None] = None):
     # if toy.implements(Sensor.send_robot_to_robot_infrared_message): TODO: BOLT
     #     toy.send_robot_to_robot_infrared_message(channel, intensity, intensity, intensity, intensity)
     if toy.implements(Sensor.send_infrared_message):
         toy.send_infrared_message(channel, intensity, intensity, intensity,
                                   intensity)
     elif not_supported_handler:
         not_supported_handler()
コード例 #12
0
 def ping(toy: Toy, not_supported_handler: Callable[[], None] = None):
     if toy.implements(Core.ping):
         toy.ping()
     elif toy.implements(ApiAndShell.ping):
         toy.ping(None)
     elif toy.implements(ApiAndShell.ping, True):
         toy.ping(None, Processors.PRIMARY)
     elif not_supported_handler:
         not_supported_handler()
コード例 #13
0
 def set_power_notifications(toy: Toy,
                             enable: bool,
                             not_supported_handler: Callable[[],
                                                             None] = None):
     if toy.implements(Power.enable_charger_state_changed_notify):
         toy.enable_charger_state_changed_notify(enable)
     elif toy.implements(Power.enable_battery_state_changed_notify):
         toy.enable_battery_state_changed_notify(enable)
     elif toy.implements(Power.enable_battery_voltage_state_change_notify):
         toy.enable_battery_voltage_state_change_notify(enable)
     elif not_supported_handler:
         not_supported_handler()
コード例 #14
0
 def set_robot_state_on_start(toy: Toy):
     # TODO setUserColour
     ToyUtil.set_head_position(toy, 0)
     ToyUtil.perform_leg_action(toy, R2LegActions.THREE_LEGS)
     ToyUtil.set_locator_flags(toy, False)
     ToyUtil.configure_collision_detection(toy)
     ToyUtil.set_power_notifications(toy, True)
     if toy.implements(Sensor.enable_gyro_max_notify):
         toy.enable_gyro_max_notify(True)
     if hasattr(toy, 'sensor_control'):
         toy.sensor_control.set_interval(150)
     ToyUtil.turn_off_leds(toy)
     if isinstance(toy, RVR):
         ToyUtil.set_color_detection(toy, True)
         ToyUtil.reset_heading(toy)
     ToyUtil.reset_locator(toy)
コード例 #15
0
 def sleep(toy: Toy, not_supported_handler: Callable[[], None] = None):
     if toy.implements(Core.sleep):
         toy.sleep(IntervalOptions.NONE, 0, 0)
     elif toy.implements(Power.sleep):
         toy.sleep()
     elif not_supported_handler:
         not_supported_handler()
コード例 #16
0
 def configure_collision_detection(toy: Toy,
                                   not_supported_handler: Callable[
                                       [], None] = None):
     x, y, t = 90, 130, 1
     if toy.implements(Sensor.configure_collision_detection):
         toy.configure_collision_detection(
             CollisionDetectionMethods.ACCELEROMETER_BASED_DETECTION, x, y,
             x, y, t)
     elif toy.implements(Sphero.configure_collision_detection):
         toy.configure_collision_detection(
             SpheroCollisionDetectionMethods.DEFAULT, x, y, x, y, t)
     elif toy.implements(
             Sensor.configure_sensitivity_based_collision_detection):
         toy.configure_sensitivity_based_collision_detection(
             SensitivityBasedCollisionDetectionMethods.
             ACCELEROMETER_BASED_DETECTION, SensitivityLevels.VERY_HIGH, t)
     elif not_supported_handler:
         not_supported_handler()
コード例 #17
0
 def reset_locator(toy: Toy,
                   not_supported_handler: Callable[[], None] = None):
     if toy.implements(Sphero.configure_locator):
         toy.configure_locator(0, 0, 0, 0)
     elif toy.implements(Sensor.reset_locator_x_and_y):
         toy.reset_locator_x_and_y()
     elif not_supported_handler:
         not_supported_handler()
コード例 #18
0
 def add_listeners(toy: Toy, manager):
     if hasattr(toy, 'sensor_control') and hasattr(manager,
                                                   '_sensor_data_listener'):
         toy.sensor_control.add_sensor_data_listener(
             manager._sensor_data_listener)
     if hasattr(toy, 'add_collision_detected_notify_listener') and hasattr(
             manager, '_collision_detected_notify'):
         toy.add_collision_detected_notify_listener(
             manager._collision_detected_notify)
     if hasattr(toy, 'add_battery_state_changed_notify_listener') and \
             hasattr(manager, '_battery_state_changed_notify'):
         toy.add_battery_state_changed_notify_listener(
             manager._battery_state_changed_notify)
     if hasattr(toy, 'add_gyro_max_notify_listener') and hasattr(
             manager, '_gyro_max_notify'):
         toy.add_gyro_max_notify_listener(manager._gyro_max_notify)
     if hasattr(toy, 'add_will_sleep_notify_listener') and hasattr(
             manager, '_will_sleep_notify'):
         toy.add_will_sleep_notify_listener(manager._will_sleep_notify)
     if hasattr(toy, 'add_robot_to_robot_infrared_message_received_notify_listener') and \
             hasattr(manager, '_robot_to_robot_infrared_message_received_notify'):
         toy.add_robot_to_robot_infrared_message_received_notify_listener(
             manager._robot_to_robot_infrared_message_received_notify)