mirror of
https://github.com/pybricks/pybricks-projects.git
synced 2026-07-28 04:06:07 +00:00
Gelo: Add initial program
* update Robodoz3r README Update * add index.md for gelo * add Gelo basic program * update Gelo basic program * refactor gelo-basic program
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
from pybricks.hubs import InventorHub
|
||||
from pybricks.pupdevices import Motor, ColorSensor, UltrasonicSensor
|
||||
from pybricks.geometry import Axis
|
||||
from pybricks.parameters import Direction, Port, Side
|
||||
from pybricks.tools import wait
|
||||
|
||||
|
||||
class Gelo:
|
||||
def __init__(self):
|
||||
self.hub = InventorHub(top_side=Axis.Z, front_side=-Axis.X)
|
||||
|
||||
# Configure the leg motors
|
||||
self.front_left_leg_motor = Motor(Port.D)
|
||||
self.front_right_leg_motor = \
|
||||
Motor(Port.C, Direction.COUNTERCLOCKWISE)
|
||||
self.rear_left_leg_motor = Motor(Port.B)
|
||||
self.rear_right_leg_motor = \
|
||||
Motor(Port.A, Direction.COUNTERCLOCKWISE)
|
||||
self.leg_motors = [
|
||||
self.front_left_leg_motor, self.front_right_leg_motor,
|
||||
self.rear_left_leg_motor, self.rear_right_leg_motor
|
||||
]
|
||||
|
||||
# Configure the sensors
|
||||
self.color_sensor = ColorSensor(Port.F)
|
||||
self.distance_sensor = UltrasonicSensor(Port.E)
|
||||
|
||||
def activate_display(self):
|
||||
self.hub.display.orientation(up=Side.TOP)
|
||||
|
||||
for _ in range(10):
|
||||
self.hub.display.image([[00, 11, 33, 11, 00],
|
||||
[11, 33, 33, 33, 11],
|
||||
[33, 66, 99, 66, 33],
|
||||
[11, 33, 66, 33, 11],
|
||||
[00, 11, 33, 11, 00]])
|
||||
wait(50)
|
||||
self.hub.display.off()
|
||||
wait(50)
|
||||
|
||||
def straighten_legs(self):
|
||||
for leg_motor in self.leg_motors:
|
||||
leg_motor.run_target(speed=1000,
|
||||
target_angle=0,
|
||||
wait=False)
|
||||
|
||||
def walk(self, speed: int, seconds: int):
|
||||
for _ in range(seconds):
|
||||
self.front_left_leg_motor.run_time(speed=speed,
|
||||
time=500,
|
||||
wait=False)
|
||||
self.rear_right_leg_motor.run_time(speed=speed,
|
||||
time=500)
|
||||
|
||||
self.front_right_leg_motor.run_time(speed=speed,
|
||||
time=500,
|
||||
wait=False)
|
||||
self.rear_left_leg_motor.run_time(speed=speed,
|
||||
time=500)
|
||||
|
||||
|
||||
# Initialize Gelo
|
||||
gelo = Gelo()
|
||||
|
||||
# Straighten his legs
|
||||
gelo.straighten_legs()
|
||||
|
||||
# Turn on his Distance Sensor
|
||||
gelo.distance_sensor.lights.on(100)
|
||||
|
||||
# Activate his display
|
||||
gelo.activate_display()
|
||||
|
||||
# Gelo takes his first walk
|
||||
gelo.walk(speed=800, seconds=10)
|
||||
|
||||
# Turn off his Distance Sensor
|
||||
gelo.distance_sensor.lights.off()
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 755 KiB |
@@ -0,0 +1,28 @@
|
||||
---
|
||||
title: "Gelo"
|
||||
maintainer:
|
||||
user: "TheVinhLuong102"
|
||||
name: "The Lương-Phạm Family"
|
||||
image:
|
||||
local: "gelo.jpg"
|
||||
credit: "LEGO"
|
||||
video:
|
||||
youtube: "5Fa4m1XzlCA"
|
||||
description:
|
||||
"A real life four-legged robot. Its unique mechanism means it can walk, avoid obstacles, and even perform tricks."
|
||||
building_instructions:
|
||||
external: https://www.lego.com/cdn/product-assets/product.bi.additional.main.pdf/51515_Gelo.pdf
|
||||
code: "#program"
|
||||
---
|
||||
|
||||
|
||||
## Program
|
||||
|
||||
The playing instructions for each robot variant are in the docstrings of the corresponding file.
|
||||
|
||||
The code for Gelo's basic walk is in `gelo-basic.py` as follows:
|
||||
|
||||
{% include copy-code.html %}
|
||||
```python
|
||||
{% include_relative gelo-basic.py %}
|
||||
```
|
||||
Reference in New Issue
Block a user