-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from iRobotEducation/pre_0.5.0
Pre 0.5.0 * Add color sensor support (close #4) * Add docking sensor support (close #11) * Fix logical error causing events to not save state without handlers * Use proper Python enums for most getter types and commands * Update and add examples * General syntax improvements * Add experimental and questionably-documented Turtle _backend_ * Bump minimum Python version to 3.10
- Loading branch information
Showing
44 changed files
with
1,254 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# | ||
# Licensed under 3-Clause BSD license available in the License file. Copyright (c) 2023 iRobot Corporation. All rights reserved. | ||
# | ||
|
||
# This example uses the robot like a wand scanner; see what the robot sees! | ||
|
||
from irobot_edu_sdk.backend.bluetooth import Bluetooth | ||
from irobot_edu_sdk.robots import event, hand_over, Robot, Root | ||
ColorID = Root.ColorID | ||
|
||
try: | ||
import colorama | ||
from colorama import Fore, Back, Style | ||
colorama.init() | ||
colors = {ColorID.WHITE: Fore.WHITE + Back.WHITE + Style.BRIGHT + format(ColorID.WHITE, 'x'), | ||
ColorID.BLACK: Fore.BLACK + Back.WHITE + Style.NORMAL + format(ColorID.BLACK, 'x'), | ||
ColorID.RED: Fore.RED + Back.RED + Style.BRIGHT + format(ColorID.RED, 'x'), | ||
ColorID.GREEN: Fore.GREEN + Back.GREEN + Style.BRIGHT + format(ColorID.GREEN, 'x'), | ||
ColorID.BLUE: Fore.BLUE + Back.BLUE + Style.BRIGHT + format(ColorID.BLUE, 'x'), | ||
ColorID.ORANGE: Fore.YELLOW + Back.BLACK + Style.NORMAL + format(ColorID.ORANGE, 'x'), | ||
ColorID.YELLOW: Fore.YELLOW + Back.YELLOW + Style.BRIGHT + format(ColorID.YELLOW, 'x'), | ||
ColorID.MAGENTA: Fore.MAGENTA + Back.MAGENTA + Style.BRIGHT + format(ColorID.MAGENTA, 'x'), | ||
ColorID.LIME: Fore.GREEN + Back.BLACK + Style.BRIGHT + format(ColorID.LIME, 'x'), | ||
ColorID.CYAN: Fore.CYAN + Back.BLACK + Style.BRIGHT + format(ColorID.CYAN, 'x'), | ||
ColorID.VIOLET: Fore.MAGENTA + Back.BLACK + Style.NORMAL + format(ColorID.VIOLET, 'x'), | ||
ColorID.CERISE: Fore.RED + Back.BLACK + Style.NORMAL + format(ColorID.CERISE, 'x'), | ||
ColorID.LOW_INTENSITY: Fore.BLACK + Back.BLACK + Style.BRIGHT + format(ColorID.LOW_INTENSITY, 'x'), | ||
ColorID.LOW_SATURATION: Fore.WHITE + Back.BLACK + Style.NORMAL + format(ColorID.LOW_SATURATION, 'x'), | ||
'unk': Fore.RED + Back.CYAN + Style.NORMAL + '?', | ||
'eol': Style.RESET_ALL} | ||
except ImportError: | ||
colors = {ColorID.WHITE: '⬜', | ||
ColorID.BLACK: '⬛', | ||
ColorID.RED: '🟥', | ||
ColorID.GREEN: '🟩', | ||
ColorID.BLUE: '🟦', | ||
ColorID.ORANGE: '🟠', | ||
ColorID.YELLOW: '🟨', | ||
ColorID.MAGENTA: '🟪', | ||
ColorID.LIME: '🟢', | ||
ColorID.CYAN: '🔵', | ||
ColorID.VIOLET: '🟣', | ||
ColorID.CERISE: '🔴', | ||
ColorID.LOW_INTENSITY: '🔳', | ||
ColorID.LOW_SATURATION: '🔲', | ||
'unk': '🟤', | ||
'eol': ''} | ||
|
||
robot = Root(Bluetooth()) | ||
|
||
@event(robot.when_play) | ||
async def sense(robot): | ||
await robot.set_wheel_speeds(1, 1) | ||
|
||
while True: | ||
try: | ||
for c in (await robot.get_color_ids())[::-1]: | ||
# Note -- the [::-1] reverses the order of the tuple, | ||
# which is necessary to make it look correct in the console. | ||
if c in ColorID: | ||
print(colors[c], end='') | ||
else: | ||
print(colors['unk'], end='') | ||
print(colors['eol']) | ||
|
||
except TypeError: | ||
print("Waiting for first color sensor event.") | ||
|
||
await robot.wait(0.25) | ||
|
||
robot.play() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# | ||
# Licensed under 3-Clause BSD license available in the License file. Copyright (c) 2023 iRobot Corporation. All rights reserved. | ||
# | ||
|
||
from irobot_edu_sdk.backend.bluetooth import Bluetooth | ||
from irobot_edu_sdk.robots import event, hand_over, Color, Robot, Root | ||
|
||
robot = Root(Bluetooth()) | ||
|
||
@event(robot.when_play) | ||
async def cake(robot): | ||
# Body | ||
await robot.set_marker_down() | ||
for _ in range(4): | ||
await robot.move(16) | ||
await robot.turn_right(90) | ||
|
||
# Icing | ||
await robot.set_marker_and_eraser_up() | ||
await robot.move(12) | ||
await robot.set_marker_down() | ||
for _ in range(2): | ||
await robot.arc_right(-180, 2) | ||
await robot.arc_left(180, 2) | ||
|
||
# Candle | ||
await robot.set_marker_and_eraser_up() | ||
await robot.move(4) | ||
await robot.turn_left(90) | ||
await robot.move(7) | ||
await robot.turn_right(90) | ||
|
||
await robot.set_marker_down() | ||
await robot.move(6) | ||
await robot.turn_left(90) | ||
await robot.move(1) | ||
await robot.turn_right(90) | ||
await robot.move(1) | ||
await robot.turn_right(90) | ||
await robot.arc_left(135, 1) | ||
await robot.move(1) | ||
await robot.turn_left(90) | ||
await robot.move(1) | ||
await robot.arc_left(135, 1) | ||
await robot.turn_right(90) | ||
await robot.move(1) | ||
await robot.turn_right(90) | ||
await robot.move(1) | ||
await robot.turn_left(90) | ||
await robot.move(6) | ||
|
||
# Move away | ||
await robot.set_marker_and_eraser_up() | ||
await robot.turn_right(135) | ||
await robot.move(16) | ||
|
||
@event(robot.when_play) | ||
async def cycle(robot): | ||
while True: | ||
await robot.set_lights_on_rgb(255, 0, 0) | ||
await robot.wait(0.3) | ||
await robot.set_lights_on_rgb(255, 255, 0) | ||
await robot.wait(0.3) | ||
await robot.set_lights_on_rgb(0, 255, 0) | ||
await robot.wait(0.3) | ||
await robot.set_lights_on_rgb(0, 255, 255) | ||
await robot.wait(0.3) | ||
await robot.set_lights_on_rgb(0, 0, 255) | ||
await robot.wait(0.3) | ||
await robot.set_lights_on_rgb(255, 0, 255) | ||
await robot.wait(0.3) | ||
|
||
robot.play() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# | ||
# Licensed under 3-Clause BSD license available in the License file. Copyright (c) 2023 iRobot Corporation. All rights reserved. | ||
# | ||
|
||
from irobot_edu_sdk.backend.bluetooth import Bluetooth | ||
from irobot_edu_sdk.robots import event, hand_over, Color, Robot, Root | ||
|
||
robot = Root(Bluetooth()) | ||
|
||
@event(robot.when_play) | ||
async def easy_as(robot): | ||
# Base | ||
await robot.set_marker_down() | ||
await robot.turn_right(135) | ||
await robot.move(8) | ||
await robot.turn_left(45) | ||
await robot.move(25) | ||
await robot.turn_left(45) | ||
await robot.move(8) | ||
await robot.turn_left(135) | ||
await robot.move(-3) | ||
await robot.move(42) | ||
await robot.turn_right(90) | ||
await robot.move(2.5) | ||
|
||
# Crimps | ||
for _ in range(10): | ||
await robot.arc_right(180, 1.24) | ||
await robot.arc_left(180, 0.75) | ||
|
||
# Top | ||
await robot.arc_right(180, 1.24) | ||
await robot.move(2.5) | ||
await robot.move(-2.5) | ||
await robot.arc_right(-90, 1.24) | ||
await robot.turn_left(120) | ||
await robot.arc_left(120, 23) | ||
|
||
await robot.set_marker_and_eraser_up() | ||
await robot.arc_left(-60, 23) | ||
await robot.turn_left(90) | ||
await robot.move(3) | ||
|
||
# Vents | ||
await robot.set_marker_down() | ||
await robot.move(3) | ||
await robot.move(-1.5) | ||
|
||
await robot.set_marker_and_eraser_up() | ||
await robot.turn_right(90) | ||
await robot.move(6) | ||
await robot.set_marker_down() | ||
await robot.turn_right(135) | ||
await robot.move(3) | ||
|
||
await robot.set_marker_and_eraser_up() | ||
await robot.turn_right(45) | ||
await robot.move(8) | ||
await robot.set_marker_down() | ||
await robot.turn_right(45) | ||
await robot.move(3) | ||
|
||
await robot.set_marker_and_eraser_up() | ||
await robot.move(-9) | ||
await robot.turn_left(135) | ||
await robot.move(4) | ||
|
||
# Steam | ||
await robot.set_marker_down() | ||
await robot.turn_left(60) | ||
await robot.arc_right(120, 2) | ||
await robot.arc_left(120, 2) | ||
|
||
await robot.set_marker_and_eraser_up() | ||
await robot.turn_left(45) | ||
await robot.move(7) | ||
await robot.set_marker_down() | ||
await robot.turn_left(135) | ||
await robot.arc_right(120, 2) | ||
await robot.arc_left(120, 2) | ||
|
||
await robot.set_marker_and_eraser_up() | ||
await robot.turn_left(30) | ||
await robot.move(14) | ||
await robot.set_marker_down() | ||
await robot.turn_left(160) | ||
await robot.arc_right(120, 2) | ||
await robot.arc_left(120, 2) | ||
|
||
# Drive away | ||
await robot.set_marker_and_eraser_up() | ||
await robot.move(24) | ||
|
||
robot.play() |
Oops, something went wrong.