Skip to content

Instantly share code, notes, and snippets.

@dlech
Created April 14, 2024 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlech/393ab221d155de3c3fff54c27fce3cb7 to your computer and use it in GitHub Desktop.
Save dlech/393ab221d155de3c3fff54c27fce3cb7 to your computer and use it in GitHub Desktop.
Resolver test bench
#!/usr/bin/env pybricks-micropython
# SPDX-License-Identifier: MIT
# Copyright (c) 2024 David Lechner <dlechner@baylibre.com>
import math
from pybricks.hubs import EV3Brick
from pybricks.ev3devices import Motor, InfraredSensor
from pybricks.parameters import Port, Direction, Button
from pybricks.tools import wait
# This program requires LEGO EV3 MicroPython v2.x.
# Click "Open user guide" on the EV3 extension tab for more information.
ev3 = EV3Brick()
ir = InfraredSensor(Port.S4)
motor = Motor(Port.A, Direction.COUNTERCLOCKWISE, [(36, 12)] * 3)
# startup sound
ev3.speaker.beep(100)
ev3.speaker.beep(200)
while True:
# angle isn't accurate because of high gearing
# ev3.screen.print(
# "angle:", "{:.2f}".format(math.radians(motor.angle()) % (math.pi * 2)), "rad"
# )
ev3.screen.print("spd:", "{:.2f}".format(math.radians(motor.speed())), "rad/s")
pressed = ir.buttons(channel=1)
if pressed:
motor.dc(100)
# speed control doesn't work with default tuning
# motor.run(DEFAULT_SPEED)
else:
motor.stop()
wait(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment