pybricks / pybricks-projects

Example programs for Pybricks
MIT License
94 stars 42 forks source link

Add Spike Essential projects #87

Open laurensvalk opened 1 year ago

laurensvalk commented 1 year ago

Need to make instructions and publish code for:

Tic Tac Toe

image

Balancer

image

laurensvalk commented 1 year ago

We could also ask @ZPhilo for permission to share his Pybricks Gymnast:

image

ZPhilo commented 1 year ago

Sure! I can share code and LDraw file...

from pybricks.hubs import EssentialHub
from pybricks.pupdevices import Motor, ColorSensor, ColorLightMatrix
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop, Axis
from pybricks.robotics import DriveBase
from pybricks.tools import wait, StopWatch

hub = EssentialHub()

# Motor order doesn't matter
hipsmotor1=Motor(Port.A)
hipsmotor2=Motor(Port.B,Direction.COUNTERCLOCKWISE)

# Set capabilities well above physical limits to maximize power/speed
maxspeed=1000
hipsmotor1.control.limits(maxspeed,8000)
hipsmotor2.control.limits(maxspeed,8000)

# This hips angle provides a good match with natural period of pendulum
hipsangle=55
wait(1000)
while True:
    # Wait till we are on top of swing
    while hub.imu.angular_velocity(Axis.X)>0:
        continue
    # Then rotate legs
    hipsmotor1.run_target(maxspeed,hipsangle,wait=False)
    hipsmotor2.run_target(maxspeed,hipsangle)
    while hub.imu.angular_velocity(Axis.X)<0:
        continue
    hipsmotor1.run_target(maxspeed,-hipsangle,wait=False)
    hipsmotor2.run_target(maxspeed,-hipsangle)

gymnast.mpd.txt

laurensvalk commented 1 year ago

Thank you @ZPhilo !