-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0427fa3
commit bf1f6e5
Showing
7 changed files
with
246 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import time | ||
import math | ||
from pimoroni_yukon import Yukon | ||
from pimoroni_yukon.modules import BigMotorModule | ||
|
||
SPEED = 5 # The speed that the motors will cycle at | ||
UPDATES = 50 # How many times to update LEDs and Servos per second | ||
MOTOR_EXTENT = 0.4 # How far from zero to drive the motors | ||
|
||
# Create a Yukon object to begin using the board | ||
yukon = Yukon(logging_level=6) | ||
|
||
# List to store the modules | ||
motor_modules = [] | ||
|
||
import tca | ||
|
||
def print_tca(message=""): | ||
print(f"---- {message} -----") | ||
#print(f"Stored Dir = [0]{tca.stored_config(0):0{16}b} [1]{tca.stored_config(1):0{16}b}") | ||
print(f"True Dir = [0]{tca.read_config(0):0{16}b} [1]{tca.read_config(1):0{16}b}") | ||
print() | ||
#print(f"Stored Out = [0]{tca.stored_output(0):0{16}b} [1]{tca.stored_output(1):0{16}b}") | ||
print(f"True Out = [0]{tca.read_output(0):0{16}b} [1]{tca.read_output(1):0{16}b}") | ||
print("-----------") | ||
print("\n") | ||
|
||
try: | ||
#print_tca() | ||
|
||
# Create a Quad Servo Direct class for each populated module slot | ||
for slot in yukon.find_slots_with_module(BigMotorModule): | ||
big_motor = BigMotorModule() | ||
yukon.register_with_slot(big_motor, slot) | ||
motor_modules.append(big_motor) | ||
|
||
# Initialise Yukon's registered modules | ||
yukon.initialise_modules(allow_unregistered=True) | ||
|
||
NUM_MOTORS = len(motor_modules) | ||
print(f"Up to {NUM_MOTORS} motors available") | ||
|
||
#time.sleep(5) | ||
|
||
# Turn on the module power | ||
yukon.enable_main_output() | ||
|
||
#print_tca() | ||
|
||
# Enable the outputs on the regulated servo modules | ||
for module in motor_modules: | ||
try: | ||
module.enable() | ||
except AttributeError: | ||
# No enable function | ||
pass | ||
|
||
#print_tca("post_enable_motors") | ||
|
||
offset = 0 | ||
while not yukon.is_boot_pressed(): | ||
offset += SPEED / 1000.0 | ||
|
||
# Update all the Motors | ||
i = 0 | ||
for module in motor_modules: | ||
angle = ((i / NUM_MOTORS) + offset) * math.pi * 2 | ||
module.motor.speed(math.sin(angle) * MOTOR_EXTENT) | ||
i += 1 | ||
|
||
#yukon.monitored_sleep(1.0 / UPDATES, allowed=("T_avg", "Fault")) | ||
yukon.monitored_sleep(1.0, allowed=("T_avg", "Fault")) | ||
|
||
finally: | ||
# Put the board back into a safe state, regardless of how the program may have ended | ||
yukon.reset() |
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,57 @@ | ||
import time | ||
import math | ||
from pimoroni_yukon import Yukon | ||
from pimoroni_yukon.modules import DualMotorModule | ||
|
||
SPEED = 5 # The speed that the motors will cycle at | ||
UPDATES = 50 # How many times to update LEDs and Servos per second | ||
MOTOR_EXTENT = 1.0 # How far from zero to drive the motors | ||
|
||
# Create a Yukon object to begin using the board | ||
yukon = Yukon() | ||
|
||
# List to store the modules | ||
motor_modules = [] | ||
|
||
try: | ||
# Create a Quad Servo Direct class for each populated module slot | ||
for slot in yukon.find_slots_with_module(DualMotorModule): | ||
dual_motor = DualMotorModule() | ||
yukon.register_with_slot(dual_motor, slot) | ||
motor_modules.append(dual_motor) | ||
|
||
# Initialise Yukon's registered modules | ||
yukon.initialise_modules(allow_unregistered=True) | ||
|
||
NUM_MOTORS = len(motor_modules) * DualMotorModule.NUM_MOTORS | ||
print(f"Up to {NUM_MOTORS} motors available") | ||
|
||
# Turn on the module power | ||
yukon.enable_main_output() | ||
|
||
# Enable the outputs on the regulated servo modules | ||
for module in motor_modules: | ||
try: | ||
module.enable() | ||
except AttributeError: | ||
# No enable function | ||
pass | ||
|
||
offset = 0 | ||
while not yukon.is_boot_pressed(): | ||
offset += SPEED / 1000.0 | ||
|
||
# Update all the Motors | ||
i = 0 | ||
for module in motor_modules: | ||
for motor in module.motors: | ||
angle = ((i / NUM_MOTORS) + offset) * math.pi * 2 | ||
motor.speed(math.sin(angle) * MOTOR_EXTENT) | ||
i += 1 | ||
|
||
yukon.monitored_sleep(1.0 / UPDATES) | ||
|
||
finally: | ||
# Put the board back into a safe state, regardless of how the program may have ended | ||
yukon.reset() | ||
|
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,62 @@ | ||
import time | ||
import math | ||
from pimoroni_yukon import Yukon | ||
from pimoroni_yukon.modules import QuadServoDirectModule, QuadServoRegModule | ||
|
||
SPEED = 5 # The speed that the servos will cycle at | ||
UPDATES = 50 # How many times to update LEDs and Servos per second | ||
SERVO_EXTENT = 80.0 # How far from zero to move the servos | ||
|
||
# Create a Yukon object to begin using the board | ||
yukon = Yukon(logging_level=2) | ||
|
||
# List to store the modules | ||
servo_modules = [] | ||
|
||
try: | ||
# Create a Quad Servo Direct class for each populated module slot | ||
for slot in yukon.find_slots_with_module(QuadServoDirectModule): | ||
direct_servo = QuadServoDirectModule() | ||
yukon.register_with_slot(direct_servo, slot) | ||
servo_modules.append(direct_servo) | ||
|
||
# Create a Quad Servo Reg class for each populated module slot | ||
for slot in yukon.find_slots_with_module(QuadServoRegModule): | ||
reg_servo = QuadServoRegModule() | ||
yukon.register_with_slot(reg_servo, slot) | ||
servo_modules.append(reg_servo) | ||
|
||
# Initialise Yukon's registered modules | ||
yukon.initialise_modules(allow_unregistered=True) | ||
|
||
NUM_SERVOS = len(servo_modules) * QuadServoDirectModule.NUM_SERVOS | ||
print(f"Up to {NUM_SERVOS} servos available") | ||
|
||
# Turn on the module power | ||
yukon.enable_main_output() | ||
|
||
# Enable the outputs on the regulated servo modules | ||
for module in servo_modules: | ||
try: | ||
module.enable() | ||
except AttributeError: | ||
# No enable function | ||
pass | ||
|
||
offset = 0 | ||
while not yukon.is_boot_pressed(): | ||
offset += SPEED / 1000.0 | ||
|
||
# Update all the Servos | ||
i = 0 | ||
for module in servo_modules: | ||
for servo in module.servos: | ||
angle = ((i / NUM_SERVOS) + offset) * math.pi * 2 | ||
servo.value(math.sin(angle) * SERVO_EXTENT) | ||
i += 1 | ||
|
||
yukon.monitored_sleep(1.0 / UPDATES) | ||
|
||
finally: | ||
# Put the board back into a safe state, regardless of how the program may have ended | ||
yukon.reset() |
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
Oops, something went wrong.