Skip to content

Commit

Permalink
Fix error with new pybricks firmware due to reliance on DCMotor (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
Novakasa committed Jan 2, 2024
1 parent 710d620 commit a4a3523
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

### Fixed

- Fix pybricks error with motors with rotation encoders in pybricks 3.3-stable (https://github.com/Novakasa/brickrail/issues/174).
- Don't allow adding train to occupied block. This previously created invalid state.
- Fixed Switches and Crossing motors invalidated port when renaming a hub (https://github.com/Novakasa/brickrail/issues/163)

Expand Down
12 changes: 9 additions & 3 deletions ble-server/hub_programs/layout_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from uselect import poll
from usys import stdin

from pybricks.pupdevices import DCMotor
from pybricks.pupdevices import DCMotor, Motor
from pybricks.parameters import Port
from pybricks.tools import wait, StopWatch

Expand Down Expand Up @@ -51,7 +51,10 @@ def get_port(index):

class Crossing:
def __init__(self, port):
self. motor = DCMotor(get_port(port))
try:
self.motor = DCMotor(get_port(port))
except OSError:
self.motor = Motor(get_port(port))
self.position = _CROSSING_POS_UP
self.port = port
self.stopwatch = StopWatch()
Expand Down Expand Up @@ -82,7 +85,10 @@ def execute(self, data):

class Switch:
def __init__(self, port, pulse_duration = 600):
self.motor = DCMotor(get_port(port))
try:
self.motor = DCMotor(get_port(port))
except OSError:
self.motor = Motor(get_port(port))
self.position = _SWITCH_POS_NONE
self.port = port
self.pulse_duration = pulse_duration
Expand Down
7 changes: 5 additions & 2 deletions ble-server/hub_programs/smart_train.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from micropython import const
from ustruct import pack, pack_into

from pybricks.pupdevices import ColorDistanceSensor, DCMotor
from pybricks.pupdevices import ColorDistanceSensor, DCMotor, Motor
from pybricks.parameters import Port

from io_hub_unfrozen import IOHub, VERSION
Expand Down Expand Up @@ -112,7 +112,10 @@ class TrainMotor:
def __init__(self):
self.speed = 0
self.target_speed = 0
self.motor = DCMotor(Port.A)
try:
self.motor = DCMotor(Port.A)
except OSError:
self.motor = Motor(Port.A)
self.direction = 1

def flip_direction(self):
Expand Down
4 changes: 2 additions & 2 deletions brickrail-gui/brickrail-layouts/ble_test.brl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"devices": {
"trains": [
{
"name": "city-blue",
"name": "city_hub",
"storage": {
"0": 3500,
"1": 40,
Expand Down Expand Up @@ -881,7 +881,7 @@
"random_targets": true,
"block_id": "block2",
"blockindex": 0,
"ble_train": "city-blue"
"ble_train": "city_hub"
}
]
}
Expand Down

0 comments on commit a4a3523

Please sign in to comment.