Diaľkové riadenie robota cez PyBrics: Rozdiel medzi revíziami
Skočit na navigaci
Skočit na vyhledávání
(Vytvorená stránka „Ovládač obsahuje tento program: ovladac.py <syntaxhighlight lang="Python"> from pybricks.hubs import PrimeHub from pybricks.pupdevices import Motor, ColorSensor, UltrasonicSensor, ForceSensor from pybricks.parameters import Button, Color, Direction, Port, Side, Stop from pybricks.robotics import DriveBase from pybricks.tools import wait, StopWatch hub = PrimeHub(broadcast_channel=1) print("ahoj") hub.light.on(Color.GREEN) wait(100) hub.light.on(Color.RED) wa…“) |
dBez shrnutí editace |
||
Riadok 1: | Riadok 1: | ||
Ovládač obsahuje tento program: | Ovládač obsahuje tento program: | ||
[[Image:riadeny_robot.jpg|800px]] | |||
[[Image:ovladac.jpg|800px]] | |||
ovladac.py | ovladac.py | ||
Riadok 107: | Riadok 112: | ||
<youtube>_Gg6mv0aJWk</youtube> | <youtube>_Gg6mv0aJWk</youtube> | ||
<youtube>QkEqFUAipEQ</youtube> |
Verzia z 16:17, 21. jún 2024
Ovládač obsahuje tento program:
ovladac.py
from pybricks.hubs import PrimeHub
from pybricks.pupdevices import Motor, ColorSensor, UltrasonicSensor, ForceSensor
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop
from pybricks.robotics import DriveBase
from pybricks.tools import wait, StopWatch
hub = PrimeHub(broadcast_channel=1)
print("ahoj")
hub.light.on(Color.GREEN)
wait(100)
hub.light.on(Color.RED)
wait(50)
print("joha")
hub.light.on(Color.GREEN)
wait(100)
hub.light.on(Color.RED)
wait(50)
print("cau")
hub.light.on(Color.GREEN)
wait(100)
hub.light.on(Color.RED)
wait(50)
print("uac")
mB = Motor(Port.B)
mD = Motor(Port.D)
TA = ForceSensor(Port.A)
TC = ForceSensor(Port.C)
TE = ForceSensor(Port.E)
while True:
pressed = hub.buttons.pressed()
#print("L:" + str(Button.LEFT in pressed) + ", R: " + str(Button.RIGHT in pressed) + ", mb: " + str(mB.angle() % 360) + ",md: " + str(mD.angle() % 360) + ",TA: " + str(TA.pressed()) + ", TC: " + str(TC.pressed()) + ", TE: " + str(TE.pressed()))
data = (Button.LEFT in pressed, Button.RIGHT in pressed, (mB.angle() % 360), (mD.angle() % 360), TA.pressed(), TC.pressed(), TE.pressed())
hub.ble.broadcast(data)
wait(20)
riadený robot obsahuje program:
auto.py
from pybricks.hubs import PrimeHub
from pybricks.pupdevices import Motor, ColorSensor, UltrasonicSensor, ForceSensor
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop
from pybricks.robotics import DriveBase
from pybricks.tools import wait, StopWatch
hub = PrimeHub(observe_channels=[1])
right_motor = Motor(Port.A, Direction.COUNTERCLOCKWISE)
left_motor = Motor(Port.E)
hub.speaker.volume(100)
drive_base = DriveBase(left_motor, right_motor, wheel_diameter=56, axle_track=192)
while True:
# Receive broadcast from the other hub.
data = hub.ble.observe(1)
if data is None:
# No data has been received in the last 1 second.
hub.light.on(Color.RED)
else:
# Data was received and is less that one second old.
hub.light.on(Color.GREEN)
bl, br, mba, mda, tap, tcp, tep = data
if tep:
hub.speaker.beep(1800, 80)
if (mba > 270):
mba = 270
if (mba < 90):
mba = 90
if (mda > 180):
mda = 180
if (mda < 10):
drive_base.stop()
else:
if not tap:
if not tcp:
mda = 0
drive_base.stop()
else:
mda = -mda
drive_base.drive(mda, (180 - mba) / 2)
#print("L:" + str(bl) + ", R: " + str(br) + ", mb: " + str(mba) + ",md: " + str(mda) + ",TA: " + str(tap) + ", TC: " + str(tcp) + ", TE: " + str(tep))
wait(50)