diff --git a/doc/main/conf.py b/doc/main/conf.py index 6758c85..212f11a 100644 --- a/doc/main/conf.py +++ b/doc/main/conf.py @@ -4,6 +4,7 @@ # Pybricks documentation build configuration file # import os +import sys # General information about the project. project = "pybricks" @@ -50,3 +51,7 @@ if "ide" in tags.tags: # noqa F821 extensions.remove("sphinx.ext.mathjax") # noqa F821 extensions.append("sphinx.ext.imgmath") # noqa F821 html_theme_options["prev_next_buttons_location"] = None # noqa F821 + +# Build hub specific example scripts. +sys.path.append(os.path.abspath("../../examples/pup/hub_common")) +import make_examples # noqa F401, E402 diff --git a/doc/main/hubs/cityhub.rst b/doc/main/hubs/cityhub.rst index e861cae..0e04408 100644 --- a/doc/main/hubs/cityhub.rst +++ b/doc/main/hubs/cityhub.rst @@ -44,25 +44,25 @@ Turning the light on and off **************************** .. literalinclude:: - ../../../examples/pup/hub_cityhub/light_off.py + ../../../examples/pup/hub_common/build/light_off_cityhub.py Changing brightness and using custom colors ******************************************* .. literalinclude:: - ../../../examples/pup/hub_cityhub/light_hsv.py + ../../../examples/pup/hub_common/build/light_hsv_cityhub.py Making the light blink ********************** .. literalinclude:: - ../../../examples/pup/hub_cityhub/light_blink.py + ../../../examples/pup/hub_common/build/light_blink_cityhub.py Creating light animations ************************* .. literalinclude:: - ../../../examples/pup/hub_cityhub/light_animate.py + ../../../examples/pup/hub_common/build/light_animate_cityhub.py Button and system examples ---------------------------------- @@ -71,10 +71,10 @@ Using the stop button during your program ***************************************** .. literalinclude:: - ../../../examples/pup/hub_cityhub/button_single.py + ../../../examples/pup/hub_common/build/button_single_cityhub.py Turning the hub off ***************************************** .. literalinclude:: - ../../../examples/pup/hub_cityhub/system_shutdown.py + ../../../examples/pup/hub_common/build/system_shutdown_cityhub.py diff --git a/doc/main/hubs/essentialhub.rst b/doc/main/hubs/essentialhub.rst index d070059..250555f 100644 --- a/doc/main/hubs/essentialhub.rst +++ b/doc/main/hubs/essentialhub.rst @@ -79,25 +79,25 @@ Turning the light on and off **************************** .. literalinclude:: - ../../../examples/pup/hub_essentialhub/light_off.py + ../../../examples/pup/hub_common/build/light_off_essentialhub.py Changing brightness and using custom colors ******************************************* .. literalinclude:: - ../../../examples/pup/hub_essentialhub/light_hsv.py + ../../../examples/pup/hub_common/build/light_hsv_essentialhub.py Making the light blink ********************** .. literalinclude:: - ../../../examples/pup/hub_essentialhub/light_blink.py + ../../../examples/pup/hub_common/build/light_blink_essentialhub.py Creating light animations ************************* .. literalinclude:: - ../../../examples/pup/hub_essentialhub/light_animate.py + ../../../examples/pup/hub_common/build/light_animate_essentialhub.py Button examples --------------- @@ -106,7 +106,7 @@ Detecting button presses ************************ .. literalinclude:: - ../../../examples/pup/hub_essentialhub/button_single.py + ../../../examples/pup/hub_common/build/button_single_essentialhub.py IMU examples --------------- @@ -115,32 +115,32 @@ Testing which way is up ******************************** .. literalinclude:: - ../../../examples/pup/hub_essentialhub/imu_up.py + ../../../examples/pup/hub_common/build/imu_up_essentialhub.py Reading the tilt value ******************************** .. literalinclude:: - ../../../examples/pup/hub_essentialhub/imu_tilt.py + ../../../examples/pup/hub_common/build/imu_tilt_essentialhub.py Using a custom hub orientation ************************************************** .. literalinclude:: - ../../../examples/pup/hub_essentialhub/imu_tilt_blast.py + ../../../examples/pup/hub_common/build/imu_tilt_blast_essentialhub.py Reading acceleration and angular velocity vectors ************************************************** .. literalinclude:: - ../../../examples/pup/hub_essentialhub/imu_read_vector.py + ../../../examples/pup/hub_common/build/imu_read_vector_essentialhub.py Reading acceleration and angular velocity on one axis ***************************************************** .. literalinclude:: - ../../../examples/pup/hub_essentialhub/imu_read_scalar.py + ../../../examples/pup/hub_common/build/imu_read_scalar_essentialhub.py System examples ---------------------------------- @@ -149,10 +149,10 @@ Using the stop button during your program ***************************************** .. literalinclude:: - ../../../examples/pup/hub_essentialhub/button_single.py + ../../../examples/pup/hub_common/build/button_single_essentialhub.py Turning the hub off ***************************************** .. literalinclude:: - ../../../examples/pup/hub_essentialhub/system_shutdown.py + ../../../examples/pup/hub_common/build/system_shutdown_essentialhub.py diff --git a/doc/main/hubs/movehub.rst b/doc/main/hubs/movehub.rst index 6e6287e..af56454 100644 --- a/doc/main/hubs/movehub.rst +++ b/doc/main/hubs/movehub.rst @@ -56,13 +56,13 @@ Turning the light on and off ****************************** .. literalinclude:: - ../../../examples/pup/hub_movehub/light_off.py + ../../../examples/pup/hub_common/build/light_off_movehub.py Making the light blink ****************************** .. literalinclude:: - ../../../examples/pup/hub_movehub/light_blink.py + ../../../examples/pup/hub_common/build/light_blink_movehub.py IMU examples --------------- @@ -71,7 +71,7 @@ Testing which way is up ******************************** .. literalinclude:: - ../../../examples/pup/hub_movehub/imu_up.py + ../../../examples/pup/hub_common/build/imu_up_movehub.py Reading acceleration ************************************************** @@ -86,10 +86,10 @@ Using the stop button during your program ***************************************** .. literalinclude:: - ../../../examples/pup/hub_movehub/button_single.py + ../../../examples/pup/hub_common/build/button_single_movehub.py Turning the hub off ***************************************** .. literalinclude:: - ../../../examples/pup/hub_movehub/system_shutdown.py + ../../../examples/pup/hub_common/build/system_shutdown_movehub.py diff --git a/doc/main/hubs/primehub.rst b/doc/main/hubs/primehub.rst index 95628b9..c76b85c 100644 --- a/doc/main/hubs/primehub.rst +++ b/doc/main/hubs/primehub.rst @@ -119,25 +119,25 @@ Turning the light on and off **************************** .. literalinclude:: - ../../../examples/pup/hub_primehub/light_off.py + ../../../examples/pup/hub_common/build/light_off_primehub.py Changing brightness and using custom colors ******************************************* .. literalinclude:: - ../../../examples/pup/hub_primehub/light_hsv.py + ../../../examples/pup/hub_common/build/light_hsv_primehub.py Making the light blink ********************** .. literalinclude:: - ../../../examples/pup/hub_primehub/light_blink.py + ../../../examples/pup/hub_common/build/light_blink_primehub.py Creating light animations ************************* .. literalinclude:: - ../../../examples/pup/hub_primehub/light_animate.py + ../../../examples/pup/hub_common/build/light_animate_primehub.py Matrix display examples ----------------------- @@ -209,32 +209,32 @@ Testing which way is up ******************************** .. literalinclude:: - ../../../examples/pup/hub_primehub/imu_up.py + ../../../examples/pup/hub_common/build/imu_up_primehub.py Reading the tilt value ******************************** .. literalinclude:: - ../../../examples/pup/hub_primehub/imu_tilt.py + ../../../examples/pup/hub_common/build/imu_tilt_primehub.py Using a custom hub orientation ************************************************** .. literalinclude:: - ../../../examples/pup/hub_primehub/imu_tilt_blast.py + ../../../examples/pup/hub_common/build/imu_tilt_blast_primehub.py Reading acceleration and angular velocity vectors ************************************************** .. literalinclude:: - ../../../examples/pup/hub_primehub/imu_read_vector.py + ../../../examples/pup/hub_common/build/imu_read_vector_primehub.py Reading acceleration and angular velocity on one axis ***************************************************** .. literalinclude:: - ../../../examples/pup/hub_primehub/imu_read_scalar.py + ../../../examples/pup/hub_common/build/imu_read_scalar_primehub.py System examples ---------------------------------- @@ -249,7 +249,7 @@ Turning the hub off ***************************************** .. literalinclude:: - ../../../examples/pup/hub_primehub/system_shutdown.py + ../../../examples/pup/hub_common/build/system_shutdown_primehub.py .. _installation instructions: https://pybricks.com/install/ diff --git a/doc/main/hubs/technichub.rst b/doc/main/hubs/technichub.rst index 2d721ab..9ac9eb2 100644 --- a/doc/main/hubs/technichub.rst +++ b/doc/main/hubs/technichub.rst @@ -58,25 +58,25 @@ Turning the light on and off **************************** .. literalinclude:: - ../../../examples/pup/hub_technichub/light_off.py + ../../../examples/pup/hub_common/build/light_off_technichub.py Changing brightness and using custom colors ******************************************* .. literalinclude:: - ../../../examples/pup/hub_technichub/light_hsv.py + ../../../examples/pup/hub_common/build/light_hsv_technichub.py Making the light blink ********************** .. literalinclude:: - ../../../examples/pup/hub_technichub/light_blink.py + ../../../examples/pup/hub_common/build/light_blink_technichub.py Creating light animations ************************* .. literalinclude:: - ../../../examples/pup/hub_technichub/light_animate.py + ../../../examples/pup/hub_common/build/light_animate_technichub.py IMU examples --------------- @@ -85,32 +85,32 @@ Testing which way is up ******************************** .. literalinclude:: - ../../../examples/pup/hub_technichub/imu_up.py + ../../../examples/pup/hub_common/build/imu_up_technichub.py Reading the tilt value ******************************** .. literalinclude:: - ../../../examples/pup/hub_technichub/imu_tilt.py + ../../../examples/pup/hub_common/build/imu_tilt_technichub.py Using a custom hub orientation ************************************************** .. literalinclude:: - ../../../examples/pup/hub_technichub/imu_tilt_blast.py + ../../../examples/pup/hub_common/build/imu_tilt_blast_technichub.py Reading acceleration and angular velocity vectors ************************************************** .. literalinclude:: - ../../../examples/pup/hub_technichub/imu_read_vector.py + ../../../examples/pup/hub_common/build/imu_read_vector_technichub.py Reading acceleration and angular velocity on one axis ***************************************************** .. literalinclude:: - ../../../examples/pup/hub_technichub/imu_read_scalar.py + ../../../examples/pup/hub_common/build/imu_read_scalar_technichub.py Button and system examples ---------------------------------- @@ -119,10 +119,10 @@ Using the stop button during your program ***************************************** .. literalinclude:: - ../../../examples/pup/hub_technichub/button_single.py + ../../../examples/pup/hub_common/build/button_single_technichub.py Turning the hub off ***************************************** .. literalinclude:: - ../../../examples/pup/hub_technichub/system_shutdown.py + ../../../examples/pup/hub_common/build/system_shutdown_technichub.py diff --git a/examples/pup/hub_cityhub/light_animate.py b/examples/pup/hub_cityhub/light_animate.py deleted file mode 100644 index c7d0f06..0000000 --- a/examples/pup/hub_cityhub/light_animate.py +++ /dev/null @@ -1,22 +0,0 @@ -from pybricks.hubs import CityHub -from pybricks.parameters import Color -from pybricks.tools import wait -from umath import sin, pi - -# Initialize the hub. -hub = CityHub() - -# Make an animation with multiple colors. -hub.light.animate([Color.RED, Color.GREEN, Color.NONE], interval=500) - -wait(10000) - -# Make the color RED grow faint and bright using a sine pattern. -hub.light.animate([Color.RED * (0.5 * sin(i / 15 * pi) + 0.5) for i in range(30)], 40) - -wait(10000) - -# Cycle through a rainbow of colors. -hub.light.animate([Color(h=i * 8) for i in range(45)], interval=40) - -wait(10000) diff --git a/examples/pup/hub_cityhub/light_blink.py b/examples/pup/hub_cityhub/light_blink.py deleted file mode 100644 index e245665..0000000 --- a/examples/pup/hub_cityhub/light_blink.py +++ /dev/null @@ -1,16 +0,0 @@ -from pybricks.hubs import CityHub -from pybricks.parameters import Color -from pybricks.tools import wait - -# Initialize the hub -hub = CityHub() - -# Keep blinking red on and off. -hub.light.blink(Color.RED, [500, 500]) - -wait(10000) - -# Keep blinking green slowly and then quickly. -hub.light.blink(Color.GREEN, [500, 500, 50, 900]) - -wait(10000) diff --git a/examples/pup/hub_cityhub/light_hsv.py b/examples/pup/hub_cityhub/light_hsv.py deleted file mode 100644 index 38d43ed..0000000 --- a/examples/pup/hub_cityhub/light_hsv.py +++ /dev/null @@ -1,21 +0,0 @@ -from pybricks.hubs import CityHub -from pybricks.parameters import Color -from pybricks.tools import wait - -# Initialize the hub. -hub = CityHub() - -# Show the color at 30% brightness. -hub.light.on(Color.RED * 0.3) - -wait(2000) - -# Use your own custom color. -hub.light.on(Color(h=30, s=100, v=50)) - -wait(2000) - -# Go through all the colors. -for hue in range(360): - hub.light.on(Color(hue)) - wait(10) diff --git a/examples/pup/hub_cityhub/system_shutdown.py b/examples/pup/hub_cityhub/system_shutdown.py deleted file mode 100644 index 5a9a357..0000000 --- a/examples/pup/hub_cityhub/system_shutdown.py +++ /dev/null @@ -1,12 +0,0 @@ -from pybricks.hubs import CityHub -from pybricks.tools import wait - -# Initialize the hub. -hub = CityHub() - -# Say goodbye and give some time to send it. -print("Goodbye!") -wait(100) - -# Shut the hub down. -hub.system.shutdown() diff --git a/examples/pup/hub_cityhub/button_single.py b/examples/pup/hub_common/button_single.py similarity index 84% rename from examples/pup/hub_cityhub/button_single.py rename to examples/pup/hub_common/button_single.py index beee132..24c40a2 100644 --- a/examples/pup/hub_cityhub/button_single.py +++ b/examples/pup/hub_common/button_single.py @@ -1,9 +1,10 @@ -from pybricks.hubs import CityHub +# ThisHub = MoveHub CityHub TechnicHub EssentialHub +from pybricks.hubs import ThisHub from pybricks.parameters import Color, Button from pybricks.tools import wait, StopWatch # Initialize the hub. -hub = CityHub() +hub = ThisHub() # Disable the stop button. hub.system.set_stop_button(None) diff --git a/examples/pup/hub_primehub/imu_read_scalar.py b/examples/pup/hub_common/imu_read_scalar.py similarity index 82% rename from examples/pup/hub_primehub/imu_read_scalar.py rename to examples/pup/hub_common/imu_read_scalar.py index 18e558c..ef94d02 100644 --- a/examples/pup/hub_primehub/imu_read_scalar.py +++ b/examples/pup/hub_common/imu_read_scalar.py @@ -1,9 +1,10 @@ -from pybricks.hubs import PrimeHub +# ThisHub = TechnicHub PrimeHub EssentialHub +from pybricks.hubs import ThisHub from pybricks.tools import wait from pybricks.geometry import Axis # Initialize the hub. -hub = PrimeHub() +hub = ThisHub() # Get the acceleration or angular_velocity along a single axis. # If you need only one value, this is more memory efficient. diff --git a/examples/pup/hub_primehub/imu_read_vector.py b/examples/pup/hub_common/imu_read_vector.py similarity index 72% rename from examples/pup/hub_primehub/imu_read_vector.py rename to examples/pup/hub_common/imu_read_vector.py index d25692a..9ee6d6d 100644 --- a/examples/pup/hub_primehub/imu_read_vector.py +++ b/examples/pup/hub_common/imu_read_vector.py @@ -1,8 +1,9 @@ -from pybricks.hubs import PrimeHub +# ThisHub = TechnicHub PrimeHub EssentialHub +from pybricks.hubs import ThisHub from pybricks.tools import wait # Initialize the hub. -hub = PrimeHub() +hub = ThisHub() # Get the acceleration vector in g's. print(hub.imu.acceleration() / 9810) diff --git a/examples/pup/hub_primehub/imu_tilt.py b/examples/pup/hub_common/imu_tilt.py similarity index 66% rename from examples/pup/hub_primehub/imu_tilt.py rename to examples/pup/hub_common/imu_tilt.py index 8bdfb49..325cffb 100644 --- a/examples/pup/hub_primehub/imu_tilt.py +++ b/examples/pup/hub_common/imu_tilt.py @@ -1,8 +1,9 @@ -from pybricks.hubs import PrimeHub +# ThisHub = TechnicHub PrimeHub EssentialHub +from pybricks.hubs import ThisHub from pybricks.tools import wait # Initialize the hub. -hub = PrimeHub() +hub = ThisHub() while True: # Read the tilt values. diff --git a/examples/pup/hub_technichub/imu_tilt_blast.py b/examples/pup/hub_common/imu_tilt_blast.py similarity index 80% rename from examples/pup/hub_technichub/imu_tilt_blast.py rename to examples/pup/hub_common/imu_tilt_blast.py index a85b612..8abe06b 100644 --- a/examples/pup/hub_technichub/imu_tilt_blast.py +++ b/examples/pup/hub_common/imu_tilt_blast.py @@ -1,11 +1,12 @@ -from pybricks.hubs import TechnicHub +# ThisHub = TechnicHub PrimeHub EssentialHub +from pybricks.hubs import ThisHub from pybricks.tools import wait from pybricks.geometry import Axis # Initialize the hub. In this case, specify that the hub is mounted with the # top side facing forward and the front side facing to the right. # For example, this is how the hub is mounted in BLAST in the 51515 set. -hub = TechnicHub(top_side=Axis.X, front_side=-Axis.Y) +hub = ThisHub(top_side=Axis.X, front_side=-Axis.Y) while True: # Read the tilt values. Now, the values are 0 when BLAST stands upright. diff --git a/examples/pup/hub_primehub/imu_up.py b/examples/pup/hub_common/imu_up.py similarity index 85% rename from examples/pup/hub_primehub/imu_up.py rename to examples/pup/hub_common/imu_up.py index 0222626..2b55329 100644 --- a/examples/pup/hub_primehub/imu_up.py +++ b/examples/pup/hub_common/imu_up.py @@ -1,9 +1,10 @@ -from pybricks.hubs import PrimeHub +# ThisHub = TechnicHub PrimeHub MoveHub EssentialHub +from pybricks.hubs import ThisHub from pybricks.parameters import Color, Side from pybricks.tools import wait # Initialize the hub. -hub = PrimeHub() +hub = ThisHub() # Define colors for each side in a dictionary. SIDE_COLORS = { diff --git a/examples/pup/hub_essentialhub/light_animate.py b/examples/pup/hub_common/light_animate.py similarity index 83% rename from examples/pup/hub_essentialhub/light_animate.py rename to examples/pup/hub_common/light_animate.py index 15e8fef..5bc5fe3 100644 --- a/examples/pup/hub_essentialhub/light_animate.py +++ b/examples/pup/hub_common/light_animate.py @@ -1,10 +1,11 @@ -from pybricks.hubs import EssentialHub +# ThisHub = CityHub TechnicHub PrimeHub EssentialHub +from pybricks.hubs import ThisHub from pybricks.parameters import Color from pybricks.tools import wait from umath import sin, pi # Initialize the hub. -hub = EssentialHub() +hub = ThisHub() # Make an animation with multiple colors. hub.light.animate([Color.RED, Color.GREEN, Color.NONE], interval=500) diff --git a/examples/pup/hub_movehub/light_blink.py b/examples/pup/hub_common/light_blink.py similarity index 72% rename from examples/pup/hub_movehub/light_blink.py rename to examples/pup/hub_common/light_blink.py index 0e31f46..9be37c5 100644 --- a/examples/pup/hub_movehub/light_blink.py +++ b/examples/pup/hub_common/light_blink.py @@ -1,9 +1,10 @@ -from pybricks.hubs import MoveHub +# ThisHub = MoveHub CityHub TechnicHub PrimeHub EssentialHub +from pybricks.hubs import ThisHub from pybricks.parameters import Color from pybricks.tools import wait # Initialize the hub -hub = MoveHub() +hub = ThisHub() # Keep blinking red on and off. hub.light.blink(Color.RED, [500, 500]) diff --git a/examples/pup/hub_primehub/light_hsv.py b/examples/pup/hub_common/light_hsv.py similarity index 77% rename from examples/pup/hub_primehub/light_hsv.py rename to examples/pup/hub_common/light_hsv.py index 7812ec5..161d454 100644 --- a/examples/pup/hub_primehub/light_hsv.py +++ b/examples/pup/hub_common/light_hsv.py @@ -1,9 +1,10 @@ -from pybricks.hubs import PrimeHub +# ThisHub = CityHub TechnicHub PrimeHub EssentialHub +from pybricks.hubs import ThisHub from pybricks.parameters import Color from pybricks.tools import wait # Initialize the hub. -hub = PrimeHub() +hub = ThisHub() # Show the color at 30% brightness. hub.light.on(Color.RED * 0.3) diff --git a/examples/pup/hub_cityhub/light_off.py b/examples/pup/hub_common/light_off.py similarity index 67% rename from examples/pup/hub_cityhub/light_off.py rename to examples/pup/hub_common/light_off.py index 2ca8f20..6b4ef33 100644 --- a/examples/pup/hub_cityhub/light_off.py +++ b/examples/pup/hub_common/light_off.py @@ -1,9 +1,10 @@ -from pybricks.hubs import CityHub +# ThisHub = MoveHub CityHub TechnicHub PrimeHub EssentialHub +from pybricks.hubs import ThisHub from pybricks.parameters import Color from pybricks.tools import wait # Initialize the hub. -hub = CityHub() +hub = ThisHub() # Turn the light on and off 5 times. for i in range(5): diff --git a/examples/pup/hub_common/make_examples.py b/examples/pup/hub_common/make_examples.py new file mode 100755 index 0000000..bf4e9e7 --- /dev/null +++ b/examples/pup/hub_common/make_examples.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +"""Generates hub-specific examples from common template script.""" + +import pathlib + +# Make build directory. +dir_path = pathlib.Path(__file__).parent +build_path = dir_path / "build" +build_path.mkdir(exist_ok=True) + +# Get list of scripts to be parsed. +file_paths = [f for f in dir_path.glob("*.py") if f.stem != "make_examples"] + +# Go through all template scripts +for file_path in file_paths: + + with open(file_path) as template: + + # First line contains hub info + hubs = template.readline().strip().split()[3:] + + print("Converting", template.name, "to", hubs) + + for hub in hubs: + # Path to hub-specific output script. + gen_path = build_path / (file_path.stem + "_" + hub.lower() + ".py") + + # Reset source script and skip over header. + template.seek(0) + template.readline() + + # Open destination script: + with open(gen_path, "w") as dest_file: + + # Read script line by line. + for line in template.readlines(): + + # Replace hub name if present. + dest_file.writelines(line.replace("ThisHub", hub)) diff --git a/examples/pup/hub_movehub/system_shutdown.py b/examples/pup/hub_common/system_shutdown.py similarity index 60% rename from examples/pup/hub_movehub/system_shutdown.py rename to examples/pup/hub_common/system_shutdown.py index d00f190..5d27624 100644 --- a/examples/pup/hub_movehub/system_shutdown.py +++ b/examples/pup/hub_common/system_shutdown.py @@ -1,8 +1,9 @@ -from pybricks.hubs import MoveHub +# ThisHub = MoveHub CityHub TechnicHub PrimeHub EssentialHub +from pybricks.hubs import ThisHub from pybricks.tools import wait # Initialize the hub. -hub = MoveHub() +hub = ThisHub() # Say goodbye and give some time to send it. print("Goodbye!") diff --git a/examples/pup/hub_essentialhub/button_single.py b/examples/pup/hub_essentialhub/button_single.py deleted file mode 100644 index 969214d..0000000 --- a/examples/pup/hub_essentialhub/button_single.py +++ /dev/null @@ -1,25 +0,0 @@ -from pybricks.hubs import EssentialHub -from pybricks.parameters import Color, Button -from pybricks.tools import wait, StopWatch - -# Initialize the hub. -hub = EssentialHub() - -# Disable the stop button. -hub.system.set_stop_button(None) - -# Check the button for 5 seconds. -watch = StopWatch() -while watch.time() < 5000: - - # Set light to green if pressed, else red. - if hub.button.pressed(): - hub.light.on(Color.GREEN) - else: - hub.light.on(Color.RED) - -# Enable the stop button again. -hub.system.set_stop_button(Button.CENTER) - -# Now you can press the stop button as usual. -wait(5000) diff --git a/examples/pup/hub_essentialhub/imu_read_scalar.py b/examples/pup/hub_essentialhub/imu_read_scalar.py deleted file mode 100644 index d62da1c..0000000 --- a/examples/pup/hub_essentialhub/imu_read_scalar.py +++ /dev/null @@ -1,20 +0,0 @@ -from pybricks.hubs import EssentialHub -from pybricks.tools import wait -from pybricks.geometry import Axis - -# Initialize the hub. -hub = EssentialHub() - -# Get the acceleration or angular_velocity along a single axis. -# If you need only one value, this is more memory efficient. -while True: - - # Read the forward acceleration. - forward_acceleration = hub.imu.acceleration(Axis.X) - - # Read the yaw rate. - yaw_rate = hub.imu.angular_velocity(Axis.Z) - - # Print the yaw rate. - print(yaw_rate) - wait(100) diff --git a/examples/pup/hub_essentialhub/imu_read_vector.py b/examples/pup/hub_essentialhub/imu_read_vector.py deleted file mode 100644 index 76f265a..0000000 --- a/examples/pup/hub_essentialhub/imu_read_vector.py +++ /dev/null @@ -1,14 +0,0 @@ -from pybricks.hubs import EssentialHub -from pybricks.tools import wait - -# Initialize the hub. -hub = EssentialHub() - -# Get the acceleration vector in g's. -print(hub.imu.acceleration() / 9810) - -# Get the angular velocity vector. -print(hub.imu.angular_velocity()) - -# Wait so we can see what we printed -wait(5000) diff --git a/examples/pup/hub_essentialhub/imu_tilt.py b/examples/pup/hub_essentialhub/imu_tilt.py deleted file mode 100644 index 819c22f..0000000 --- a/examples/pup/hub_essentialhub/imu_tilt.py +++ /dev/null @@ -1,13 +0,0 @@ -from pybricks.hubs import EssentialHub -from pybricks.tools import wait - -# Initialize the hub. -hub = EssentialHub() - -while True: - # Read the tilt values. - pitch, roll = hub.imu.tilt() - - # Print the result. - print(pitch, roll) - wait(200) diff --git a/examples/pup/hub_essentialhub/imu_tilt_blast.py b/examples/pup/hub_essentialhub/imu_tilt_blast.py deleted file mode 100644 index 6dbb02a..0000000 --- a/examples/pup/hub_essentialhub/imu_tilt_blast.py +++ /dev/null @@ -1,17 +0,0 @@ -from pybricks.hubs import EssentialHub -from pybricks.tools import wait -from pybricks.geometry import Axis - -# Initialize the hub. In this case, specify that the hub is mounted with the -# top side facing forward and the front side facing to the right. -# For example, this is how the hub is mounted in BLAST in the 51515 set. -hub = EssentialHub(top_side=Axis.X, front_side=-Axis.Y) - -while True: - # Read the tilt values. Now, the values are 0 when BLAST stands upright. - # Leaning forward gives positive pitch. Leaning right gives positive roll. - pitch, roll = hub.imu.tilt() - - # Print the result. - print(pitch, roll) - wait(200) diff --git a/examples/pup/hub_essentialhub/imu_up.py b/examples/pup/hub_essentialhub/imu_up.py deleted file mode 100644 index 893fc50..0000000 --- a/examples/pup/hub_essentialhub/imu_up.py +++ /dev/null @@ -1,29 +0,0 @@ -from pybricks.hubs import EssentialHub -from pybricks.parameters import Color, Side -from pybricks.tools import wait - -# Initialize the hub. -hub = EssentialHub() - -# Define colors for each side in a dictionary. -SIDE_COLORS = { - Side.TOP: Color.RED, - Side.BOTTOM: Color.BLUE, - Side.LEFT: Color.GREEN, - Side.RIGHT: Color.YELLOW, - Side.FRONT: Color.MAGENTA, - Side.BACK: Color.BLACK, -} - -# Keep updating the color based on detected up side. -while True: - - # Check which side of the hub is up. - up_side = hub.imu.up() - - # Change the color based on the side. - hub.light.on(SIDE_COLORS[up_side]) - - # Also print the result. - print(up_side) - wait(50) diff --git a/examples/pup/hub_essentialhub/light_blink.py b/examples/pup/hub_essentialhub/light_blink.py deleted file mode 100644 index 5c103da..0000000 --- a/examples/pup/hub_essentialhub/light_blink.py +++ /dev/null @@ -1,16 +0,0 @@ -from pybricks.hubs import EssentialHub -from pybricks.parameters import Color -from pybricks.tools import wait - -# Initialize the hub -hub = EssentialHub() - -# Keep blinking red on and off. -hub.light.blink(Color.RED, [500, 500]) - -wait(10000) - -# Keep blinking green slowly and then quickly. -hub.light.blink(Color.GREEN, [500, 500, 50, 900]) - -wait(10000) diff --git a/examples/pup/hub_essentialhub/light_hsv.py b/examples/pup/hub_essentialhub/light_hsv.py deleted file mode 100644 index 7f557d0..0000000 --- a/examples/pup/hub_essentialhub/light_hsv.py +++ /dev/null @@ -1,21 +0,0 @@ -from pybricks.hubs import EssentialHub -from pybricks.parameters import Color -from pybricks.tools import wait - -# Initialize the hub. -hub = EssentialHub() - -# Show the color at 30% brightness. -hub.light.on(Color.RED * 0.3) - -wait(2000) - -# Use your own custom color. -hub.light.on(Color(h=30, s=100, v=50)) - -wait(2000) - -# Go through all the colors. -for hue in range(360): - hub.light.on(Color(hue)) - wait(10) diff --git a/examples/pup/hub_essentialhub/light_off.py b/examples/pup/hub_essentialhub/light_off.py deleted file mode 100644 index 0487b29..0000000 --- a/examples/pup/hub_essentialhub/light_off.py +++ /dev/null @@ -1,15 +0,0 @@ -from pybricks.hubs import EssentialHub -from pybricks.parameters import Color -from pybricks.tools import wait - -# Initialize the hub. -hub = EssentialHub() - -# Turn the light on and off 5 times. -for i in range(5): - - hub.light.on(Color.RED) - wait(1000) - - hub.light.off() - wait(500) diff --git a/examples/pup/hub_essentialhub/system_shutdown.py b/examples/pup/hub_essentialhub/system_shutdown.py deleted file mode 100644 index ce2ca80..0000000 --- a/examples/pup/hub_essentialhub/system_shutdown.py +++ /dev/null @@ -1,12 +0,0 @@ -from pybricks.hubs import EssentialHub -from pybricks.tools import wait - -# Initialize the hub. -hub = EssentialHub() - -# Say goodbye and give some time to send it. -print("Goodbye!") -wait(100) - -# Shut the hub down. -hub.system.shutdown() diff --git a/examples/pup/hub_movehub/button_single.py b/examples/pup/hub_movehub/button_single.py deleted file mode 100644 index 0cd459f..0000000 --- a/examples/pup/hub_movehub/button_single.py +++ /dev/null @@ -1,25 +0,0 @@ -from pybricks.hubs import MoveHub -from pybricks.parameters import Color, Button -from pybricks.tools import wait, StopWatch - -# Initialize the hub. -hub = MoveHub() - -# Disable the stop button. -hub.system.set_stop_button(None) - -# Check the button for 5 seconds. -watch = StopWatch() -while watch.time() < 5000: - - # Set light to green if pressed, else red. - if hub.button.pressed(): - hub.light.on(Color.GREEN) - else: - hub.light.on(Color.RED) - -# Enable the stop button again. -hub.system.set_stop_button(Button.CENTER) - -# Now you can press the stop button as usual. -wait(5000) diff --git a/examples/pup/hub_movehub/imu_up.py b/examples/pup/hub_movehub/imu_up.py deleted file mode 100644 index abfdc61..0000000 --- a/examples/pup/hub_movehub/imu_up.py +++ /dev/null @@ -1,29 +0,0 @@ -from pybricks.hubs import MoveHub -from pybricks.parameters import Color, Side -from pybricks.tools import wait - -# Initialize the hub. -hub = MoveHub() - -# Define colors for each side in a dictionary. -SIDE_COLORS = { - Side.TOP: Color.RED, - Side.BOTTOM: Color.BLUE, - Side.LEFT: Color.GREEN, - Side.RIGHT: Color.YELLOW, - Side.FRONT: Color.MAGENTA, - Side.BACK: Color.BLACK, -} - -# Keep updating the color based on detected up side. -while True: - - # Check which side of the hub is up. - up_side = hub.imu.up() - - # Change the color based on the side. - hub.light.on(SIDE_COLORS[up_side]) - - # Also print the result. - print(up_side) - wait(50) diff --git a/examples/pup/hub_movehub/light_off.py b/examples/pup/hub_movehub/light_off.py deleted file mode 100644 index 5de6a43..0000000 --- a/examples/pup/hub_movehub/light_off.py +++ /dev/null @@ -1,15 +0,0 @@ -from pybricks.hubs import MoveHub -from pybricks.parameters import Color -from pybricks.tools import wait - -# Initialize the hub. -hub = MoveHub() - -# Turn the light on and off 5 times. -for i in range(5): - - hub.light.on(Color.RED) - wait(1000) - - hub.light.off() - wait(500) diff --git a/examples/pup/hub_primehub/imu_tilt_blast.py b/examples/pup/hub_primehub/imu_tilt_blast.py deleted file mode 100644 index 84551a3..0000000 --- a/examples/pup/hub_primehub/imu_tilt_blast.py +++ /dev/null @@ -1,17 +0,0 @@ -from pybricks.hubs import PrimeHub -from pybricks.tools import wait -from pybricks.geometry import Axis - -# Initialize the hub. In this case, specify that the hub is mounted with the -# top side facing forward and the front side facing to the right. -# For example, this is how the hub is mounted in BLAST in the 51515 set. -hub = PrimeHub(top_side=Axis.X, front_side=-Axis.Y) - -while True: - # Read the tilt values. Now, the values are 0 when BLAST stands upright. - # Leaning forward gives positive pitch. Leaning right gives positive roll. - pitch, roll = hub.imu.tilt() - - # Print the result. - print(pitch, roll) - wait(200) diff --git a/examples/pup/hub_primehub/light_animate.py b/examples/pup/hub_primehub/light_animate.py deleted file mode 100644 index fd9699d..0000000 --- a/examples/pup/hub_primehub/light_animate.py +++ /dev/null @@ -1,22 +0,0 @@ -from pybricks.hubs import PrimeHub -from pybricks.parameters import Color -from pybricks.tools import wait -from umath import sin, pi - -# Initialize the hub. -hub = PrimeHub() - -# Make an animation with multiple colors. -hub.light.animate([Color.RED, Color.GREEN, Color.NONE], interval=500) - -wait(10000) - -# Make the color RED grow faint and bright using a sine pattern. -hub.light.animate([Color.RED * (0.5 * sin(i / 15 * pi) + 0.5) for i in range(30)], 40) - -wait(10000) - -# Cycle through a rainbow of colors. -hub.light.animate([Color(h=i * 8) for i in range(45)], interval=40) - -wait(10000) diff --git a/examples/pup/hub_primehub/light_blink.py b/examples/pup/hub_primehub/light_blink.py deleted file mode 100644 index 1df0347..0000000 --- a/examples/pup/hub_primehub/light_blink.py +++ /dev/null @@ -1,16 +0,0 @@ -from pybricks.hubs import PrimeHub -from pybricks.parameters import Color -from pybricks.tools import wait - -# Initialize the hub -hub = PrimeHub() - -# Keep blinking red on and off. -hub.light.blink(Color.RED, [500, 500]) - -wait(10000) - -# Keep blinking green slowly and then quickly. -hub.light.blink(Color.GREEN, [500, 500, 50, 900]) - -wait(10000) diff --git a/examples/pup/hub_primehub/light_off.py b/examples/pup/hub_primehub/light_off.py deleted file mode 100644 index f13eb0d..0000000 --- a/examples/pup/hub_primehub/light_off.py +++ /dev/null @@ -1,15 +0,0 @@ -from pybricks.hubs import PrimeHub -from pybricks.parameters import Color -from pybricks.tools import wait - -# Initialize the hub. -hub = PrimeHub() - -# Turn the light on and off 5 times. -for i in range(5): - - hub.light.on(Color.RED) - wait(1000) - - hub.light.off() - wait(500) diff --git a/examples/pup/hub_primehub/system_shutdown.py b/examples/pup/hub_primehub/system_shutdown.py deleted file mode 100644 index 6a5c0d4..0000000 --- a/examples/pup/hub_primehub/system_shutdown.py +++ /dev/null @@ -1,12 +0,0 @@ -from pybricks.hubs import PrimeHub -from pybricks.tools import wait - -# Initialize the hub. -hub = PrimeHub() - -# Say goodbye and give some time to send it. -print("Goodbye!") -wait(100) - -# Shut the hub down. -hub.system.shutdown() diff --git a/examples/pup/hub_shared/button_single.py b/examples/pup/hub_shared/button_single.py deleted file mode 100644 index 5851bf9..0000000 --- a/examples/pup/hub_shared/button_single.py +++ /dev/null @@ -1,26 +0,0 @@ -# ExampleHub = MoveHub CityHub TechnicHub EssentialHub -from pybricks.hubs import ExampleHub -from pybricks.parameters import Color, Button -from pybricks.tools import wait, StopWatch - -# Initialize the hub. -hub = ExampleHub() - -# Disable the stop button. -hub.system.set_stop_button(None) - -# Check the button for 5 seconds. -watch = StopWatch() -while watch.time() < 5000: - - # Set light to green if pressed, else red. - if hub.button.pressed(): - hub.light.on(Color.GREEN) - else: - hub.light.on(Color.RED) - -# Enable the stop button again. -hub.system.set_stop_button(Button.CENTER) - -# Now you can press the stop button as usual. -wait(5000) diff --git a/examples/pup/hub_shared/imu_read_scalar.py b/examples/pup/hub_shared/imu_read_scalar.py deleted file mode 100644 index 0841e75..0000000 --- a/examples/pup/hub_shared/imu_read_scalar.py +++ /dev/null @@ -1,21 +0,0 @@ -# ExampleHub = TechnicHub PrimeHub EssentialHub -from pybricks.hubs import ExampleHub -from pybricks.tools import wait -from pybricks.geometry import Axis - -# Initialize the hub. -hub = ExampleHub() - -# Get the acceleration or angular_velocity along a single axis. -# If you need only one value, this is more memory efficient. -while True: - - # Read the forward acceleration. - forward_acceleration = hub.imu.acceleration(Axis.X) - - # Read the yaw rate. - yaw_rate = hub.imu.angular_velocity(Axis.Z) - - # Print the yaw rate. - print(yaw_rate) - wait(100) diff --git a/examples/pup/hub_shared/imu_read_vector.py b/examples/pup/hub_shared/imu_read_vector.py deleted file mode 100644 index 7850081..0000000 --- a/examples/pup/hub_shared/imu_read_vector.py +++ /dev/null @@ -1,15 +0,0 @@ -# ExampleHub = TechnicHub PrimeHub EssentialHub -from pybricks.hubs import ExampleHub -from pybricks.tools import wait - -# Initialize the hub. -hub = ExampleHub() - -# Get the acceleration vector in g's. -print(hub.imu.acceleration() / 9810) - -# Get the angular velocity vector. -print(hub.imu.angular_velocity()) - -# Wait so we can see what we printed -wait(5000) diff --git a/examples/pup/hub_shared/imu_tilt.py b/examples/pup/hub_shared/imu_tilt.py deleted file mode 100644 index a68b166..0000000 --- a/examples/pup/hub_shared/imu_tilt.py +++ /dev/null @@ -1,14 +0,0 @@ -# ExampleHub = TechnicHub PrimeHub EssentialHub -from pybricks.hubs import ExampleHub -from pybricks.tools import wait - -# Initialize the hub. -hub = ExampleHub() - -while True: - # Read the tilt values. - pitch, roll = hub.imu.tilt() - - # Print the result. - print(pitch, roll) - wait(200) diff --git a/examples/pup/hub_shared/imu_tilt_blast.py b/examples/pup/hub_shared/imu_tilt_blast.py deleted file mode 100644 index 73afbba..0000000 --- a/examples/pup/hub_shared/imu_tilt_blast.py +++ /dev/null @@ -1,18 +0,0 @@ -# ExampleHub = TechnicHub PrimeHub EssentialHub -from pybricks.hubs import ExampleHub -from pybricks.tools import wait -from pybricks.geometry import Axis - -# Initialize the hub. In this case, specify that the hub is mounted with the -# top side facing forward and the front side facing to the right. -# For example, this is how the hub is mounted in BLAST in the 51515 set. -hub = ExampleHub(top_side=Axis.X, front_side=-Axis.Y) - -while True: - # Read the tilt values. Now, the values are 0 when BLAST stands upright. - # Leaning forward gives positive pitch. Leaning right gives positive roll. - pitch, roll = hub.imu.tilt() - - # Print the result. - print(pitch, roll) - wait(200) diff --git a/examples/pup/hub_shared/imu_up.py b/examples/pup/hub_shared/imu_up.py deleted file mode 100644 index c4acdee..0000000 --- a/examples/pup/hub_shared/imu_up.py +++ /dev/null @@ -1,30 +0,0 @@ -# ExampleHub = TechnicHub PrimeHub MoveHub EssentialHub -from pybricks.hubs import ExampleHub -from pybricks.parameters import Color, Side -from pybricks.tools import wait - -# Initialize the hub. -hub = ExampleHub() - -# Define colors for each side in a dictionary. -SIDE_COLORS = { - Side.TOP: Color.RED, - Side.BOTTOM: Color.BLUE, - Side.LEFT: Color.GREEN, - Side.RIGHT: Color.YELLOW, - Side.FRONT: Color.MAGENTA, - Side.BACK: Color.BLACK, -} - -# Keep updating the color based on detected up side. -while True: - - # Check which side of the hub is up. - up_side = hub.imu.up() - - # Change the color based on the side. - hub.light.on(SIDE_COLORS[up_side]) - - # Also print the result. - print(up_side) - wait(50) diff --git a/examples/pup/hub_shared/light_animate.py b/examples/pup/hub_shared/light_animate.py deleted file mode 100644 index c19359c..0000000 --- a/examples/pup/hub_shared/light_animate.py +++ /dev/null @@ -1,23 +0,0 @@ -# ExampleHub = CityHub TechnicHub PrimeHub EssentialHub -from pybricks.hubs import ExampleHub -from pybricks.parameters import Color -from pybricks.tools import wait -from umath import sin, pi - -# Initialize the hub. -hub = ExampleHub() - -# Make an animation with multiple colors. -hub.light.animate([Color.RED, Color.GREEN, Color.NONE], interval=500) - -wait(10000) - -# Make the color RED grow faint and bright using a sine pattern. -hub.light.animate([Color.RED * (0.5 * sin(i / 15 * pi) + 0.5) for i in range(30)], 40) - -wait(10000) - -# Cycle through a rainbow of colors. -hub.light.animate([Color(h=i * 8) for i in range(45)], interval=40) - -wait(10000) diff --git a/examples/pup/hub_shared/light_blink.py b/examples/pup/hub_shared/light_blink.py deleted file mode 100644 index ed7db00..0000000 --- a/examples/pup/hub_shared/light_blink.py +++ /dev/null @@ -1,17 +0,0 @@ -# ExampleHub = MoveHub CityHub TechnicHub PrimeHub EssentialHub -from pybricks.hubs import ExampleHub -from pybricks.parameters import Color -from pybricks.tools import wait - -# Initialize the hub -hub = ExampleHub() - -# Keep blinking red on and off. -hub.light.blink(Color.RED, [500, 500]) - -wait(10000) - -# Keep blinking green slowly and then quickly. -hub.light.blink(Color.GREEN, [500, 500, 50, 900]) - -wait(10000) diff --git a/examples/pup/hub_shared/light_hsv.py b/examples/pup/hub_shared/light_hsv.py deleted file mode 100644 index 237cc45..0000000 --- a/examples/pup/hub_shared/light_hsv.py +++ /dev/null @@ -1,22 +0,0 @@ -# ExampleHub = CityHub TechnicHub PrimeHub EssentialHub -from pybricks.hubs import ExampleHub -from pybricks.parameters import Color -from pybricks.tools import wait - -# Initialize the hub. -hub = ExampleHub() - -# Show the color at 30% brightness. -hub.light.on(Color.RED * 0.3) - -wait(2000) - -# Use your own custom color. -hub.light.on(Color(h=30, s=100, v=50)) - -wait(2000) - -# Go through all the colors. -for hue in range(360): - hub.light.on(Color(hue)) - wait(10) diff --git a/examples/pup/hub_shared/light_off.py b/examples/pup/hub_shared/light_off.py deleted file mode 100644 index cb17651..0000000 --- a/examples/pup/hub_shared/light_off.py +++ /dev/null @@ -1,16 +0,0 @@ -# ExampleHub = MoveHub CityHub TechnicHub PrimeHub EssentialHub -from pybricks.hubs import ExampleHub -from pybricks.parameters import Color -from pybricks.tools import wait - -# Initialize the hub. -hub = ExampleHub() - -# Turn the light on and off 5 times. -for i in range(5): - - hub.light.on(Color.RED) - wait(1000) - - hub.light.off() - wait(500) diff --git a/examples/pup/hub_shared/make_shared_examples.py b/examples/pup/hub_shared/make_shared_examples.py deleted file mode 100755 index c50a9d2..0000000 --- a/examples/pup/hub_shared/make_shared_examples.py +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env python3 -"""Replaces all instances of ExampleHub in template with actual hub names.""" -import os - -# Get list of scripts to be parsed -script_names = [f for f in os.listdir(".") if f != "make_shared_examples.py"] - -# Go through all template scripts -for script in (open(f, "r") for f in script_names): - - # First line contains hub info - hubs = script.readline().strip().split()[3:] - - print("Converting", script.name, "for", hubs) - - for hub in hubs: - # Determine path to the hub - hub_path = os.path.join("..", "hub_" + hub.lower()) - - # Reset source script - script.seek(0) - script.readline() - - # Open destination script: - with open(os.path.join(hub_path, script.name), "w") as dest_file: - - # Read script line by line - for line in script.readlines(): - - # Replace hub name if present - dest_file.writelines(line.replace("ExampleHub", hub)) diff --git a/examples/pup/hub_shared/system_shutdown.py b/examples/pup/hub_shared/system_shutdown.py deleted file mode 100644 index 770660a..0000000 --- a/examples/pup/hub_shared/system_shutdown.py +++ /dev/null @@ -1,13 +0,0 @@ -# ExampleHub = MoveHub CityHub TechnicHub PrimeHub EssentialHub -from pybricks.hubs import ExampleHub -from pybricks.tools import wait - -# Initialize the hub. -hub = ExampleHub() - -# Say goodbye and give some time to send it. -print("Goodbye!") -wait(100) - -# Shut the hub down. -hub.system.shutdown() diff --git a/examples/pup/hub_technichub/button_single.py b/examples/pup/hub_technichub/button_single.py deleted file mode 100644 index 9736369..0000000 --- a/examples/pup/hub_technichub/button_single.py +++ /dev/null @@ -1,25 +0,0 @@ -from pybricks.hubs import TechnicHub -from pybricks.parameters import Color, Button -from pybricks.tools import wait, StopWatch - -# Initialize the hub. -hub = TechnicHub() - -# Disable the stop button. -hub.system.set_stop_button(None) - -# Check the button for 5 seconds. -watch = StopWatch() -while watch.time() < 5000: - - # Set light to green if pressed, else red. - if hub.button.pressed(): - hub.light.on(Color.GREEN) - else: - hub.light.on(Color.RED) - -# Enable the stop button again. -hub.system.set_stop_button(Button.CENTER) - -# Now you can press the stop button as usual. -wait(5000) diff --git a/examples/pup/hub_technichub/imu_read_scalar.py b/examples/pup/hub_technichub/imu_read_scalar.py deleted file mode 100644 index 8d1334b..0000000 --- a/examples/pup/hub_technichub/imu_read_scalar.py +++ /dev/null @@ -1,20 +0,0 @@ -from pybricks.hubs import TechnicHub -from pybricks.tools import wait -from pybricks.geometry import Axis - -# Initialize the hub. -hub = TechnicHub() - -# Get the acceleration or angular_velocity along a single axis. -# If you need only one value, this is more memory efficient. -while True: - - # Read the forward acceleration. - forward_acceleration = hub.imu.acceleration(Axis.X) - - # Read the yaw rate. - yaw_rate = hub.imu.angular_velocity(Axis.Z) - - # Print the yaw rate. - print(yaw_rate) - wait(100) diff --git a/examples/pup/hub_technichub/imu_read_vector.py b/examples/pup/hub_technichub/imu_read_vector.py deleted file mode 100644 index ee5688b..0000000 --- a/examples/pup/hub_technichub/imu_read_vector.py +++ /dev/null @@ -1,14 +0,0 @@ -from pybricks.hubs import TechnicHub -from pybricks.tools import wait - -# Initialize the hub. -hub = TechnicHub() - -# Get the acceleration vector in g's. -print(hub.imu.acceleration() / 9810) - -# Get the angular velocity vector. -print(hub.imu.angular_velocity()) - -# Wait so we can see what we printed -wait(5000) diff --git a/examples/pup/hub_technichub/imu_tilt.py b/examples/pup/hub_technichub/imu_tilt.py deleted file mode 100644 index 26311c5..0000000 --- a/examples/pup/hub_technichub/imu_tilt.py +++ /dev/null @@ -1,13 +0,0 @@ -from pybricks.hubs import TechnicHub -from pybricks.tools import wait - -# Initialize the hub. -hub = TechnicHub() - -while True: - # Read the tilt values. - pitch, roll = hub.imu.tilt() - - # Print the result. - print(pitch, roll) - wait(200) diff --git a/examples/pup/hub_technichub/imu_up.py b/examples/pup/hub_technichub/imu_up.py deleted file mode 100644 index d7208bb..0000000 --- a/examples/pup/hub_technichub/imu_up.py +++ /dev/null @@ -1,29 +0,0 @@ -from pybricks.hubs import TechnicHub -from pybricks.parameters import Color, Side -from pybricks.tools import wait - -# Initialize the hub. -hub = TechnicHub() - -# Define colors for each side in a dictionary. -SIDE_COLORS = { - Side.TOP: Color.RED, - Side.BOTTOM: Color.BLUE, - Side.LEFT: Color.GREEN, - Side.RIGHT: Color.YELLOW, - Side.FRONT: Color.MAGENTA, - Side.BACK: Color.BLACK, -} - -# Keep updating the color based on detected up side. -while True: - - # Check which side of the hub is up. - up_side = hub.imu.up() - - # Change the color based on the side. - hub.light.on(SIDE_COLORS[up_side]) - - # Also print the result. - print(up_side) - wait(50) diff --git a/examples/pup/hub_technichub/light_animate.py b/examples/pup/hub_technichub/light_animate.py deleted file mode 100644 index 5cd91f1..0000000 --- a/examples/pup/hub_technichub/light_animate.py +++ /dev/null @@ -1,22 +0,0 @@ -from pybricks.hubs import TechnicHub -from pybricks.parameters import Color -from pybricks.tools import wait -from umath import sin, pi - -# Initialize the hub. -hub = TechnicHub() - -# Make an animation with multiple colors. -hub.light.animate([Color.RED, Color.GREEN, Color.NONE], interval=500) - -wait(10000) - -# Make the color RED grow faint and bright using a sine pattern. -hub.light.animate([Color.RED * (0.5 * sin(i / 15 * pi) + 0.5) for i in range(30)], 40) - -wait(10000) - -# Cycle through a rainbow of colors. -hub.light.animate([Color(h=i * 8) for i in range(45)], interval=40) - -wait(10000) diff --git a/examples/pup/hub_technichub/light_blink.py b/examples/pup/hub_technichub/light_blink.py deleted file mode 100644 index 441ad62..0000000 --- a/examples/pup/hub_technichub/light_blink.py +++ /dev/null @@ -1,16 +0,0 @@ -from pybricks.hubs import TechnicHub -from pybricks.parameters import Color -from pybricks.tools import wait - -# Initialize the hub -hub = TechnicHub() - -# Keep blinking red on and off. -hub.light.blink(Color.RED, [500, 500]) - -wait(10000) - -# Keep blinking green slowly and then quickly. -hub.light.blink(Color.GREEN, [500, 500, 50, 900]) - -wait(10000) diff --git a/examples/pup/hub_technichub/light_hsv.py b/examples/pup/hub_technichub/light_hsv.py deleted file mode 100644 index ae76cf5..0000000 --- a/examples/pup/hub_technichub/light_hsv.py +++ /dev/null @@ -1,21 +0,0 @@ -from pybricks.hubs import TechnicHub -from pybricks.parameters import Color -from pybricks.tools import wait - -# Initialize the hub. -hub = TechnicHub() - -# Show the color at 30% brightness. -hub.light.on(Color.RED * 0.3) - -wait(2000) - -# Use your own custom color. -hub.light.on(Color(h=30, s=100, v=50)) - -wait(2000) - -# Go through all the colors. -for hue in range(360): - hub.light.on(Color(hue)) - wait(10) diff --git a/examples/pup/hub_technichub/light_off.py b/examples/pup/hub_technichub/light_off.py deleted file mode 100644 index 4227d2f..0000000 --- a/examples/pup/hub_technichub/light_off.py +++ /dev/null @@ -1,15 +0,0 @@ -from pybricks.hubs import TechnicHub -from pybricks.parameters import Color -from pybricks.tools import wait - -# Initialize the hub. -hub = TechnicHub() - -# Turn the light on and off 5 times. -for i in range(5): - - hub.light.on(Color.RED) - wait(1000) - - hub.light.off() - wait(500) diff --git a/examples/pup/hub_technichub/system_shutdown.py b/examples/pup/hub_technichub/system_shutdown.py deleted file mode 100644 index bf01b90..0000000 --- a/examples/pup/hub_technichub/system_shutdown.py +++ /dev/null @@ -1,12 +0,0 @@ -from pybricks.hubs import TechnicHub -from pybricks.tools import wait - -# Initialize the hub. -hub = TechnicHub() - -# Say goodbye and give some time to send it. -print("Goodbye!") -wait(100) - -# Shut the hub down. -hub.system.shutdown()