ITADN

[Bug] Motors with rotation sensors don't work

#174Closediragm 创建于 2023-12-31
I
iragmcommented
**Describe the bug** What is the problem? Several PUP motors, including the very affordable 88008 (Boost M) and the very useful [88013](https://www.bricklink.com/v2/catalog/catalogitem.page?S=88013-1) L-motor give the generic connection error when I attempt to use them. **To reproduce** Instead of one of the DCMotor() devices, connect any pybricks Motor() device to your hub. On running, brickrail goes into emergency stop because the motor isn't connected, but of course there is a motor -- just the "wrong" type. It looks like this could be addressed in the simplest form with a simple try except block in e.g. `layout_controller.py`: ``` class Switch: def __init__(self, port, pulse_duration = 600): try: self.motor = DCMotor(get_port(port)) except: # also need to import Motor on line 6 above... self.motor = Motor(get_port(port)) self.position = _SWITCH_POS_NONE self.port = port ... ``` This would need to be done in `auto_train.py` and `smart_train.py` too. But this would leave out some useful stuff, specifically, the L-motor can be set to run at a constant speed regardless of the load. It might make sense to have some sort of custom class that takes advantage of the rotation sensor when possible, and falls back to the standard DCMotor class when that's not available. It looks like both auto_train.py and smart_train.py have a TrainMotor() class already that could be used for this. I'm not set up with a dev environment for this project but I can help with code if needed. Is there any way that I can use the current release with my own custom pybricks code to test things out?
关闭于 2024-01-02 4 条评论