In meinem aktuellsten Projekt habe ich das LEGO Technic Batmobil aus diesem Jahr motorisiert, damit es ferngesteuert werden kann.
Hardware
- Großer Technic Hub mit Pybricks Firmware
- Powered Up Fernsteuerung
- Kleiner Winkelmotor (2x)
- Einfacher, mittlerer Linearmotor
- 3x3 Farblichtmatrix
- Powered Up Licht
- Power Functions LED-Lichter (2x)
- Powered Up zu Power Functions Adapterkabel von pv-productions
Video
Quellcode (geschrieben mit Pybricks)
from pybricks.hubs import PrimeHub
from pybricks.pupdevices import *
from pybricks.parameters import *
from pybricks.tools import wait
#used hardware
hub = PrimeHub()
fakeEngine = Motor(Port.A)
frontLight = Light(Port.B)
fakeEngineLight = ColorLightMatrix(Port.C)
mainLight = DCMotor(Port.D) #Actually 2 lights via PF adapter cable
driving = DCMotor(Port.E)
steering = Motor(Port.F)
hub.light.on(Color.RED)
remoteControl = Remote()
hub.light.on(Color.GREEN)
#steering calibration sequence
steering.run_until_stalled(500)
steering.reset_angle(0)
steering.run_until_stalled(-500)
maxAngle = steering.angle()
steering.run_target(500, (maxAngle/2)+10)
steering.reset_angle(0)
hub.light.off()
mainLight.dc(10)
#main loop
while True:
#Loop to "start" the car
remoteControl.light.on(Color.YELLOW)
while True:
pressed = remoteControl.buttons.pressed()
if Button.CENTER in pressed: break
#Start engine
remoteControl.light.on(Color.YELLOW)
mainLight.dc(100)
fakeEngineLight.on(Color.BLUE)
fakeEngine.dc(100)
frontLight.on(100)
driving.dc(-40)
wait (200)
driving.brake()
frontLight.off()
fakeEngine.dc(80)
fakeEngineLight.on(Color.RED)
wait(1300)
frontLight.off()
for brightness in range(1, 60):
fakeEngineLight.on(Color(h=0, s=100, v=100-brightness))
fakeEngine.dc(80-brightness)
wait(100)
wait(500)
maxSpeed = 60
remoteControl.light.on(Color.RED)
#mainLoop
while True:
pressed = remoteControl.buttons.pressed()
#turn batmobile off
if Button.CENTER in pressed: break
#Activate hero mode
if (Button.LEFT in pressed) and (Button.RIGHT in pressed):
maxSpeed = 100
fakeEngine.dc(100)
fakeEngineLight.on(Color.BLUE)
remoteControl.light.on(Color.BLUE)
frontLight.on(100)
#commands to drive forwards or backwards
if Button.LEFT_PLUS in pressed:
driving.dc(maxSpeed)
if maxSpeed == 60:
fakeEngineLight.on(Color(h=0, s=100, v=60))
fakeEngine.dc(maxSpeed)
elif Button.LEFT_MINUS in pressed:
driving.dc(-maxSpeed)
if maxSpeed == 60:
fakeEngineLight.on(Color(h=0, s=100, v=60))
fakeEngine.dc(maxSpeed)
else:
driving.brake()
#commands to steer
if Button.RIGHT_PLUS in pressed:
steering.run_target(1200, (maxAngle/2)-5, Stop.HOLD,False)
elif Button.RIGHT_MINUS in pressed:
steering.run_target(1200, -((maxAngle/2)-5), Stop.HOLD,False)
else:
steering.run_target(1200, 0, Stop.HOLD, False)
#turn off sequence
frontLight.off()
remoteControl.light.on(Color.ORANGE)
for brightness in range(1, maxSpeed):
fakeEngine.dc(maxSpeed-brightness)
if (brightness < 20) and (maxSpeed == 100): fakeEngineLight.on(Color(h=240, s=100, v=100-brightness))
elif brightness < 55: fakeEngineLight.on(Color(h=0, s=100, v=100-brightness))
else: fakeEngineLight.on(Color(h=30, s=100, v=100-brightness))
wait(100)
maxSpeed = 60
fakeEngineLight.off()
mainLight.dc(10)
Kommentare
Kommentar veröffentlichen