diff --git a/CHANGELOG.md b/CHANGELOG.md index 470e7409..0e4bc9ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ ## [Unreleased] +### Fixed +- Fix TechnicHub dependency in LayoutController hub program (https://github.com/Novakasa/brickrail/issues/108). + ## [1.0.0a1] - 2023-04-15 diff --git a/ble-server/hub_programs/layout_controller.py b/ble-server/hub_programs/layout_controller.py index 7a549813..0f826818 100644 --- a/ble-server/hub_programs/layout_controller.py +++ b/ble-server/hub_programs/layout_controller.py @@ -3,8 +3,7 @@ from uselect import poll from usys import stdin -from pybricks.hubs import TechnicHub -from pybricks.pupdevices import DCMotor, Motor +from pybricks.pupdevices import DCMotor from pybricks.parameters import Port from pybricks.tools import wait, StopWatch @@ -18,10 +17,23 @@ _DATA_SWITCH_CONFIRM = const(0) +def get_port(index): + try: # Primehub + return [Port.A, Port.B, Port.C, Port.D, Port.E, Port.F][index] + except AttributeError: + pass + + try: # Technichub + return [Port.A, Port.B, Port.C, Port.D][index] + except AttributeError: + pass + + # Cityhub + return [Port.A, Port.B][index] + class Switch: def __init__(self, port, pulse_duration = 600): - pb_port = [Port.A, Port.B, Port.C, Port.D][port] - self.motor = DCMotor(pb_port) + self.motor = DCMotor(get_port(port)) self.position = _SWITCH_POS_NONE self.port = port self.pulse_duration = pulse_duration @@ -54,7 +66,6 @@ def execute(self, data): class Controller: def __init__(self): - self.hub = TechnicHub() self.devices = {} def assign_switch(self, data): diff --git a/brickrail-gui/brickrail-layouts/ble_test-technictrain.brl b/brickrail-gui/brickrail-layouts/ble_test-technictrain.brl new file mode 100644 index 00000000..41524843 --- /dev/null +++ b/brickrail-gui/brickrail-layouts/ble_test-technictrain.brl @@ -0,0 +1,522 @@ +{ + "devices": { + "trains": [ + { + "name": "blue" + } + ], + "controllers": [ + { + "name": "city-blue", + "devices": { + "0": "switch_motor", + "1": null, + "2": null, + "3": null + } + } + ] + }, + "layout": { + "tracks": [ + { + "l_idx": 0, + "x_idx": 3, + "y_idx": 1, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 3, + "y_idx": 4, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 3, + "y_idx": 3, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 2, + "y_idx": 1, + "connections": { + "E": [ + "center" + ], + "W": [ + "left" + ] + }, + "sensor": { + "markername": null, + "speeds": { + "E": "cruise", + "W": "cruise" + } + } + }, + { + "l_idx": 0, + "x_idx": 2, + "y_idx": 4, + "connections": { + "E": [ + "center" + ], + "W": [ + "right" + ] + }, + "sensor": { + "markername": null, + "speeds": { + "E": "cruise", + "W": "cruise" + } + } + }, + { + "l_idx": 0, + "x_idx": 2, + "y_idx": 3, + "connections": { + "E": [ + "center" + ], + "W": [ + "right" + ] + }, + "sensor": { + "markername": null, + "speeds": { + "E": "cruise", + "W": "cruise" + } + } + }, + { + "l_idx": 0, + "x_idx": 1, + "y_idx": 3, + "connections": { + "N": [ + "center" + ], + "E": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 1, + "y_idx": 3, + "connections": { + "N": [ + "center" + ], + "S": [ + "left" + ] + } + }, + { + "l_idx": 0, + "x_idx": 1, + "y_idx": 2, + "connections": { + "N": [ + "right" + ], + "S": [ + "left", + "center" + ] + }, + "switches": { + "S": { + "motor1_inverted": false, + "motor2_inverted": false + } + } + }, + { + "l_idx": 0, + "x_idx": 1, + "y_idx": 1, + "connections": { + "S": [ + "center" + ], + "E": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 1, + "y_idx": 4, + "connections": { + "N": [ + "center" + ], + "E": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 4, + "y_idx": 1, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 4, + "y_idx": 4, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 4, + "y_idx": 3, + "connections": { + "E": [ + "center" + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 5, + "y_idx": 1, + "connections": { + "E": [ + "right" + ], + "W": [ + "center" + ] + }, + "sensor": { + "markername": null, + "speeds": { + "E": "cruise", + "W": "cruise" + } + } + }, + { + "l_idx": 0, + "x_idx": 5, + "y_idx": 4, + "connections": { + "E": [ + "left" + ], + "W": [ + "center" + ] + }, + "sensor": { + "markername": null, + "speeds": { + "E": "cruise", + "W": "cruise" + } + } + }, + { + "l_idx": 0, + "x_idx": 5, + "y_idx": 3, + "connections": { + "E": [ + "left" + ], + "W": [ + "center" + ] + }, + "sensor": { + "markername": null, + "speeds": { + "E": "cruise", + "W": "cruise" + } + } + }, + { + "l_idx": 0, + "x_idx": 6, + "y_idx": 1, + "connections": { + "S": [ + "center" + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 6, + "y_idx": 2, + "connections": { + "N": [ + "left" + ], + "S": [ + "center", + "right" + ] + }, + "switches": { + "S": { + "motor1": { + "controller": "city-blue", + "port": 0 + }, + "motor1_inverted": false, + "motor2_inverted": false + } + } + }, + { + "l_idx": 0, + "x_idx": 6, + "y_idx": 3, + "connections": { + "N": [ + "center" + ], + "S": [ + "right" + ] + } + }, + { + "l_idx": 0, + "x_idx": 6, + "y_idx": 3, + "connections": { + "N": [ + "center" + ], + "W": [ + "center" + ] + } + }, + { + "l_idx": 0, + "x_idx": 6, + "y_idx": 4, + "connections": { + "N": [ + "center" + ], + "W": [ + "center" + ] + } + } + ], + "blocks": [ + { + "name": "block0", + "section": { + "tracks": [ + { + "l_idx": 0, + "x_idx": 2, + "y_idx": 1, + "next_slot": "E", + "orientation": "EW" + }, + { + "l_idx": 0, + "x_idx": 3, + "y_idx": 1, + "next_slot": "E", + "orientation": "EW" + }, + { + "l_idx": 0, + "x_idx": 4, + "y_idx": 1, + "next_slot": "E", + "orientation": "EW" + }, + { + "l_idx": 0, + "x_idx": 5, + "y_idx": 1, + "next_slot": "E", + "orientation": "EW" + } + ] + }, + "prior_sensors": { + + }, + "can_stop": { + "0": true, + "1": true + }, + "can_flip": { + "0": true, + "1": true + } + }, + { + "name": "block1", + "section": { + "tracks": [ + { + "l_idx": 0, + "x_idx": 5, + "y_idx": 3, + "next_slot": "W", + "orientation": "EW" + }, + { + "l_idx": 0, + "x_idx": 4, + "y_idx": 3, + "next_slot": "W", + "orientation": "EW" + }, + { + "l_idx": 0, + "x_idx": 3, + "y_idx": 3, + "next_slot": "W", + "orientation": "EW" + }, + { + "l_idx": 0, + "x_idx": 2, + "y_idx": 3, + "next_slot": "W", + "orientation": "EW" + } + ] + }, + "prior_sensors": { + + }, + "can_stop": { + "0": true, + "1": true + }, + "can_flip": { + "0": true, + "1": true + } + }, + { + "name": "block2", + "section": { + "tracks": [ + { + "l_idx": 0, + "x_idx": 5, + "y_idx": 4, + "next_slot": "W", + "orientation": "EW" + }, + { + "l_idx": 0, + "x_idx": 4, + "y_idx": 4, + "next_slot": "W", + "orientation": "EW" + }, + { + "l_idx": 0, + "x_idx": 3, + "y_idx": 4, + "next_slot": "W", + "orientation": "EW" + }, + { + "l_idx": 0, + "x_idx": 2, + "y_idx": 4, + "next_slot": "W", + "orientation": "EW" + } + ] + }, + "prior_sensors": { + + }, + "can_stop": { + "0": true, + "1": true + }, + "can_flip": { + "0": true, + "1": true + } + } + ], + "trains": [ + { + "name": "train0", + "facing": 1, + "fixed_facing": false, + "color": "ff000000", + "num_wagons": 4, + "blockname": "block0", + "blockindex": 0, + "ble_train": "blue" + } + ] + } +} \ No newline at end of file