initial
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
""" LEGO Liebherr LR 13000 / Xbox Controller / Pybricks
|
||||
|
||||
Top hub connects to Xbox controller.
|
||||
|
||||
Bottom hub receives the control data from the top one.
|
||||
|
||||
Controls:
|
||||
Undercarriage
|
||||
Left track forward ... Left trigger
|
||||
Left track backward ... Left trigger + Button X pushed
|
||||
Right track forward ... Right trigger
|
||||
Right track backward ... Right trigger + Button A pushed
|
||||
The superstructure turning ... Right joystick left / right
|
||||
Crane
|
||||
The boom raising / lowering ... Left joystick up / down
|
||||
The jib raising / lowering ... Left joystick left / right
|
||||
The hook raising / lowering ... Right joystick up / down
|
||||
The lights on / off ... Button Y
|
||||
"""
|
||||
|
||||
from pybricks.hubs import TechnicHub
|
||||
from pybricks.pupdevices import Motor, Light
|
||||
from pybricks.parameters import Button, Color, Direction, Port
|
||||
from pybricks.tools import wait
|
||||
from pybricks.iodevices import XboxController
|
||||
|
||||
hub = TechnicHub(observe_channels=[1])
|
||||
superstr_motor = Motor(Port.D, positive_direction=Direction.COUNTERCLOCKWISE)
|
||||
left_motor = Motor(Port.A, positive_direction=Direction.CLOCKWISE)
|
||||
right_motor = Motor(Port.B, positive_direction=Direction.COUNTERCLOCKWISE)
|
||||
|
||||
# motors settings
|
||||
LEFT_TRACK_SPEED = 800
|
||||
RIGHT_TRACK_SPEED = 800
|
||||
ROTATESPEED = 240 # motor speed to turn the crane superstructure
|
||||
|
||||
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)
|
||||
|
||||
# *data* contains the same values in the same order
|
||||
# that were passed to hub.ble.broadcast() on the
|
||||
# other hub.
|
||||
rot_speed, left_tr_speed, right_tr_speed = data
|
||||
|
||||
# control of the superstructure turning
|
||||
superstr_motor.run(rot_speed * ROTATESPEED / 80)
|
||||
|
||||
# left track control
|
||||
left_motor.run(left_tr_speed * LEFT_TRACK_SPEED / 100)
|
||||
|
||||
# right track control
|
||||
right_motor.run(right_tr_speed * RIGHT_TRACK_SPEED / 100)
|
||||
|
||||
121
42100/pybricks-backup-2024-05-01_18-22-08/LR13000_top_hub_04.py
Normal file
121
42100/pybricks-backup-2024-05-01_18-22-08/LR13000_top_hub_04.py
Normal file
@@ -0,0 +1,121 @@
|
||||
""" LEGO Liebherr LR 13000 / Xbox Controller / Pybricks
|
||||
|
||||
Top hub connects to Xbox controller.
|
||||
|
||||
Bottom hub receives the control data from the top one.
|
||||
|
||||
Controls:
|
||||
Undercarriage
|
||||
Left track forward ... Left trigger
|
||||
Left track backward ... Left trigger + Button X pushed
|
||||
Right track forward ... Right trigger
|
||||
Right track backward ... Right trigger + Button A pushed
|
||||
The superstructure turning ... Right joystick left / right
|
||||
Crane
|
||||
The boom raising / lowering ... Left joystick up / down
|
||||
The jib raising / lowering ... Left joystick left / right
|
||||
The hook raising / lowering ... Right joystick up / down
|
||||
The lights on / off ... Button Y
|
||||
"""
|
||||
|
||||
from pybricks.hubs import TechnicHub
|
||||
from pybricks.pupdevices import Motor, Light
|
||||
from pybricks.parameters import Button, Color, Direction, Port
|
||||
from pybricks.tools import wait
|
||||
from pybricks.iodevices import XboxController
|
||||
|
||||
hub = TechnicHub(broadcast_channel=1)
|
||||
controller = XboxController()
|
||||
boom_motor = Motor(Port.A, positive_direction=Direction.COUNTERCLOCKWISE)
|
||||
arm_motor = Motor(Port.B, positive_direction=Direction.COUNTERCLOCKWISE)
|
||||
bucket_motor = Motor(Port.C, positive_direction=Direction.CLOCKWISE)
|
||||
scoop_motor = Motor(Port.D, positive_direction=Direction.CLOCKWISE)
|
||||
|
||||
# motors settings
|
||||
BOOMSPEED = 1000
|
||||
BUCKETSPEED = 100
|
||||
ARMSPEED = 1000
|
||||
SCOOPSPEED = 1000
|
||||
|
||||
hub.light.on(Color.GREEN)
|
||||
|
||||
while True:
|
||||
|
||||
|
||||
# # control of the boom raising and lowering
|
||||
# boom_speed = 0
|
||||
# horizontal, vertical = controller.joystick_left()
|
||||
# if vertical < -20:
|
||||
# boom_speed = vertical + 20
|
||||
# elif vertical > 20:
|
||||
# boom_speed = vertical - 20
|
||||
|
||||
# boom_motor.run(boom_speed * BOOMSPEED / 80)
|
||||
|
||||
# # control of the jib raising and lowering
|
||||
# bucket_speed = 0
|
||||
# horizontal, vertical = controller.joystick_left()
|
||||
# if horizontal < -20:
|
||||
# bucket_speed = horizontal + 20
|
||||
# elif horizontal > 20:
|
||||
# bucket_speed = horizontal - 20
|
||||
|
||||
# bucket_motor.run(bucket_speed * BUCKETSPEED / 80)
|
||||
|
||||
# # control of arm
|
||||
# arm_speed = 0
|
||||
# horizontal, vertical = controller.joystick_right()
|
||||
# if vertical < -20:
|
||||
# arm_speed = vertical + 20
|
||||
# elif vertical > 20:
|
||||
# arm_speed = vertical - 20
|
||||
|
||||
# arm_motor.run(arm_speed * ARMSPEED / 80)
|
||||
|
||||
# # control of scoop
|
||||
# scoop_speed = 0
|
||||
# horizontal, vertical = controller.joystick_right()
|
||||
# if horizontal < -20:
|
||||
# scoop_speed = vertical + 20
|
||||
# elif horizontal > 20:
|
||||
# scoop_speed = vertical - 20
|
||||
|
||||
# scoop_motor_motor.run(scoop_speed * SCOOPSPEED / 80)
|
||||
|
||||
# control of the superstructure turning
|
||||
rot_speed = 0
|
||||
now_pressed = controller.buttons.pressed()
|
||||
if controller.button.RIGHT:
|
||||
rot_speed = ROTATESPEED
|
||||
elif controller.button.LEFT:
|
||||
rot_speed = ROTATESPEED * -1
|
||||
|
||||
|
||||
|
||||
# left track control
|
||||
left_tr_speed = 0
|
||||
now_pressed = controller.buttons.pressed()
|
||||
if "X" in now_pressed:
|
||||
brake, acceleration = controller.triggers()
|
||||
if brake > 10:
|
||||
left_tr_speed -= brake
|
||||
else:
|
||||
brake, acceleration = controller.triggers()
|
||||
if brake > 10:
|
||||
left_tr_speed += brake
|
||||
|
||||
# right track control
|
||||
right_tr_speed = 0
|
||||
now_pressed = controller.buttons.pressed()
|
||||
if "A" in now_pressed:
|
||||
brake, acceleration = controller.triggers()
|
||||
if acceleration > 10:
|
||||
right_tr_speed -= acceleration
|
||||
else:
|
||||
brake, acceleration = controller.triggers()
|
||||
if acceleration > 10:
|
||||
right_tr_speed += acceleration
|
||||
|
||||
# Set the broadcast data and start broadcasting if not already doing so.
|
||||
data = (rot_speed, left_tr_speed, right_tr_speed)
|
||||
hub.ble.broadcast(data)
|
||||
@@ -0,0 +1,3 @@
|
||||
# pybricks blocks file:{"blocks":{"languageVersion":0,"blocks":[{"type":"blockGlobalSetup","id":"bjK,wS1MYO7aiYkFSwd{","x":150,"y":100,"deletable":false},{"type":"blockGlobalStart","id":"3tJe|AWl0baN(wH9a$@.","x":150,"y":300,"deletable":false,"next":{"block":{"type":"blockPrint","id":"j,,T}?rBkaW$1v?olp4p","extraState":{"optionLevel":0},"inputs":{"TEXT0":{"shadow":{"type":"text","id":"!x5.0YiWya^`(y)yO5B8","fields":{"TEXT":"Hello, Pybricks!"}}}}}}}]},"variables":[{"name":"red","id":"b(K72kbjLK3eaWY0rZ|H","type":"ColorDef"},{"name":"orange","id":"c5QKn-VxQXjXw0PEXW{$","type":"ColorDef"},{"name":"yellow","id":"J2n}pzD-+3vRNACoH}A|","type":"ColorDef"},{"name":"green","id":"0(NPnGB8B#2Qj*3dMqMj","type":"ColorDef"},{"name":"cyan","id":"`cTjOq2c5Qt!:AB0MNE~","type":"ColorDef"},{"name":"blue","id":")~d23yr%3gimljv:M!%H","type":"ColorDef"},{"name":"violet","id":".;6s97*6~~o){?kf32Vu","type":"ColorDef"},{"name":"magenta","id":"hnOw;Pff:#:!OejeEBQ8","type":"ColorDef"},{"name":"white","id":"|u=R}I%9QzW(~|dUY+U}","type":"ColorDef"},{"name":"none","id":"*c=-CgnIE*K6T9Gxk[8}","type":"ColorDef"}],"info":{"type":"pybricks","version":"1.2.2"}}
|
||||
# The main program starts here.
|
||||
print('Hello, Pybricks!')
|
||||
Reference in New Issue
Block a user