Skip to content

Commit

Permalink
Added boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
ZodiusInfuser committed Nov 20, 2023
1 parent d80aee6 commit d607142
Show file tree
Hide file tree
Showing 25 changed files with 122 additions and 24 deletions.
98 changes: 98 additions & 0 deletions examples/boilerplate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
from pimoroni_yukon import Yukon

# Perform system level imports here
# e.g. import math

# Import any slots needed for your modules
# e.g. from pimoroni_yukon import SLOT1 as SLOT

# Import any Yukon modules you are using
# e.g. from pimoroni_yukon.modules import DualMotorModule

# Import the logging level to use (if you wish to change from the default)
# e.g. from pimoroni_yukon.logging import LOG_NONE, LOG_WARN, LOG_INFO, LOG_DEBUG

from pimoroni_yukon.timing import ticks_ms, ticks_add # This import is only needed if using .monitor_until_ms()

# Perform any other imports here
# e.g. from pimoroni_yukon.devices.stepper import OkayStepper

"""
This is a boilerplate example for Yukon. Use it as a base for your own programs.
Press "Boot/User" to exit the program.
"""

# Constants
SLEEP_TIME = 0.1

# Place other constants here
# e.g. VOLTAGE_LIMIT = 12

# Variables
yukon = Yukon() # Create a new Yukon object. These optional keyword parameters are supported:
# `voltage_limit`, `current_limit`, `temperature_limit`, and `logging_level`

# Create your module objects here
# e.g. module = DualMotorModule()

# Place other variables here
# e.g. button_state = False


# Put any functions needed for your program here
# e.g. def my_function():
# pass


# Wrap the code in a try block, to catch any exceptions (including KeyboardInterrupt)
try:
# Register your module with their respective slots
# e.g. yukon.register_with_slot(module, SLOT)

# Verify that the correct modules are attached to Yukon, and initialise them
# This is not necessary if your program uses Yukon's IO directly, or via proto modules
# yukon.verify_and_initialise()

# Set up any variables or objects that need initialised modules
# e.g. stepper = OkayStepper(module.motor1, module.motor2)

yukon.enable_main_output() # Turn on power to the module slots

# Enable any modules or objects
# e.g. module.enable()

current_time = ticks_ms() # Record the start time of the program loop. Only needed if using .monitor_until_ms()

# Loop until the BOOT/USER button is pressed
while not yukon.is_boot_pressed():

#######################
# Put your program here
#######################

# Choose one of three options for monitoring Yukon's sensors

# 1) Perform a single check of Yukon's internal voltage, current, and temperature sensors
# yukon.monitor_once()

# 2) Monitor sensors for a number of seconds, recording the min, max, and average for each
# yukon.monitored_sleep(SLEEP_TIME)

# 3) Advance the current time by a number of seconds
current_time = ticks_add(current_time, int(SLEEP_TIME * 1000))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

# Print out any readings from the monitoring period that may be useful
yukon.print_readings(allowed="Vi_avg")

# Reset the yukon instance if the program completes successfully or an exception occurs
finally:
# Clean up any objects that hold on to hardware resources
# e.g. if stepper is not None:
# stepper.release()

yukon.reset()
2 changes: 1 addition & 1 deletion examples/modules/bench_power/multiple_powers.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def voltage_from_index(index, offset=0.0):
current_time = ticks_add(current_time, int(1000 / UPDATES))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

finally:
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/big_motor/all_motors_no_encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def speed_from_index(index, offset=0.0):
current_time = ticks_add(current_time, int(1000 / UPDATES))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

finally:
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/big_motor/multiple_motors.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def pio_and_sm_generator():
current_time = ticks_add(current_time, int(1000 / UPDATES))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

finally:
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/big_motor/position_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
current_time = ticks_add(current_time, int(1000 * UPDATE_RATE))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

module.motor.disable() # Disable the motor
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/big_motor/position_on_velocity_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
current_time = ticks_add(current_time, int(1000 * UPDATE_RATE))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

module.motor.disable() # Disable the motor
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/big_motor/single_motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
current_time = ticks_add(current_time, int(1000 / UPDATES))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

finally:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
current_time = ticks_add(current_time, int(1000 * UPDATE_RATE))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

module.motor.disable() # Disable the motor
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/big_motor/tuning/position_tuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
current_time = ticks_add(current_time, int(1000 * UPDATE_RATE))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

module.motor.disable() # Disable the motor
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/big_motor/tuning/velocity_tuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
current_time = ticks_add(current_time, int(1000 * UPDATE_RATE))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

module.motor.disable() # Disable the motor
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/big_motor/velocity_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
current_time = ticks_add(current_time, int(1000 * UPDATE_RATE))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

module.motor.disable() # Disable the motor
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/dual_motor/all_motors.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def speed_from_index(index, offset=0.0):
current_time = ticks_add(current_time, int(1000 / UPDATES))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

finally:
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/dual_motor/multiple_motors.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def speed_from_index(index, offset=0.0):
current_time = ticks_add(current_time, int(1000 / UPDATES))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

finally:
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/dual_motor/two_motors.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def speed_from_index(index, offset=0.0):
current_time = ticks_add(current_time, int(1000 / UPDATES))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

finally:
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/dual_output/multiple_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def state_from_index(index, offset=0.0):
current_time = ticks_add(current_time, int(1000 / UPDATES))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

finally:
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/led_strip/multiple_strips.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def pio_and_sm_generator():
current_time = ticks_add(current_time, int(SLEEP * 1000))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

finally:
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/led_strip/single_strip.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def update_rainbow(strip, offset):
current_time = ticks_add(current_time, int(SLEEP * 1000))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

finally:
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/quad_servo/all_servos.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def angle_from_index(index, offset=0.0):
current_time = ticks_add(current_time, int(1000 / UPDATES))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

finally:
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/quad_servo/four_servos.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def angle_from_index(index, offset=0.0):
current_time = ticks_add(current_time, int(1000 / UPDATES))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

finally:
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/quad_servo/multiple_servos.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def angle_from_index(index, offset=0.0):
current_time = ticks_add(current_time, int(1000 / UPDATES))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

finally:
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/serial_servo/all_servos.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def angle_from_index(index, offset=0.0):
current_time = ticks_add(current_time, int(1000 / UPDATES))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

finally:
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/serial_servo/drive_servo.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def button_newly_pressed(btn):
current_time = ticks_add(current_time, int(SLEEP * 1000))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

finally:
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/serial_servo/move_servo.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def button_newly_pressed(btn):
current_time = ticks_add(current_time, int(SLEEP * 1000))

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

finally:
Expand Down
2 changes: 1 addition & 1 deletion examples/showcase/rover/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def joystick_callback(x, y):
current_time = ticks_add(current_time, TIMESTEP_MS)

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)
except RuntimeError as e:
left_driver.disable()
Expand Down
2 changes: 1 addition & 1 deletion examples/showcase/spidertank/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def extent_to_displacements(x_extent, z_extent, percent):
current_time = ticks_add(current_time, TIMESTEP_MS)

# Monitor sensors until the current time is reached, recording the min, max, and average for each
# This approach accounts for the updates takinga non-zero amount of time to complete
# This approach accounts for the updates taking a non-zero amount of time to complete
yukon.monitor_until_ms(current_time)

# Get the average voltage recorded from monitoring, and print it out
Expand Down

0 comments on commit d607142

Please sign in to comment.