Open fengxie opened 4 years ago
I was encountering the same issue and just started poking about when I saw this. I took the liberty of creating a fork to implement and test these changes. See: https://github.com/esklarski/bricknil
I was picking through the two versions and noticed that the current version of BLEAK has a lot more error catching than the bricknil version, and I suspect the errors we are getting are for things not handled at the time of the fork.
Thanks for starting this, i will be doing testing as I have free time.
Found the first issue, seems there is a problem unwrapping values from a list returned by a sensor.
File ".../bricknil/sensor/sensor.py", line 534, in update_value if self.value[ss] & (1<<15): # negative sign bit TypeError: unsupported operand type(s) for &: 'list' and 'int'
I am just playing with the DuploTrain example (link).
I can fix the problem by eliminating one of the values from the attach statement.
Does not work, and produces the above error:
@attach(DuploSpeedSensor, name='speed_sensor', capabilities=['sense_speed', 'sense_count'])
Works fine with no error:
@attach(DuploSpeedSensor, name='speed_sensor', capabilities=['sense_speed'])
@virantha if you're about still, what modifications were necessary when you forked Bleak originally?
I am getting the same error from both @virantha and your branch @esklarski . This is observed in MacOS 10.14.6 when trying to run vernie_remote.py, and upgrading to bleak 0.7.1 results in the same issue:
inside curio run loop INFO:BLE Event Q.0:Clearing BLE cache data INFO:BLE Event Q.0:Found adapter Default Adapter INFO:BLE Event Q.0:Powering up adapter Default Adapter INFO:BLE Event Q.0:Starting scan for UART 00001623-1212-efde-1623-785feabcd123 INFO:BLE Event Q.0:Looking for first matching hub INFO:BLE Event Q.0:Rescanning for 00001623-1212-efde-1623-785feabcd123 (60 tries left) INFO:BLE Event Q.0:Rescanning for 00001623-1212-efde-1623-785feabcd123 (59 tries left) INFO:BLE Event Q.0:Rescanning for 00001623-1212-efde-1623-785feabcd123 (58 tries left) INFO:BLE Event Q.0:Rescanning for 00001623-1212-efde-1623-785feabcd123 (57 tries left) INFO:BLE Event Q.0:Rescanning for 00001623-1212-efde-1623-785feabcd123 (56 tries left) INFO:BLE Event Q.0:Rescanning for 00001623-1212-efde-1623-785feabcd123 (55 tries left) INFO:BLE Event Q.0:Rescanning for 00001623-1212-efde-1623-785feabcd123 (54 tries left) 2020-07-03 17:44:45.104 Python[14025:2500771] Terminating app due to uncaught exception 'OC_PythonException', reason: '<class 'AssertionError'>: <memory at 0x102956b80>' First throw call stack: ( 0 CoreFoundation 0x00007fff3cf59acd exceptionPreprocess + 256 1 libobjc.A.dylib 0x00007fff6765da17 objc_exception_throw + 48 2 CoreFoundation 0x00007fff3cf73629 -[NSException raise] + 9 3 _objc.cpython-38-darwin.so 0x00000001028c78fe PyObjCErr_ToObjCWithGILState + 46 4 _objc.cpython-38-darwin.so 0x00000001028bfc64 -[OC_PythonObject forwardInvocation:] + 708 5 CoreFoundation 0x00007fff3cefb67e __forwarding + 780 6 CoreFoundation 0x00007fff3cefb2e8 _CF_forwarding_prep_0 + 120 7 CoreBluetooth 0x00007fff3c9cd46a -[CBCentralManager handlePeripheralDiscovered:] + 1156 8 CoreBluetooth 0x00007fff3c9ce4ba -[CBCentralManager handleMsg:args:] + 536 9 CoreBluetooth 0x00007fff3c9c97db __30-[CBXpcConnection _handleMsg:]_block_invoke + 53 10 libdispatch.dylib 0x00007fff68dde5f8 _dispatch_call_block_and_release + 12 11 libdispatch.dylib 0x00007fff68ddf63d _dispatch_client_callout + 8 12 libdispatch.dylib 0x00007fff68de58e0 _dispatch_lane_serial_drain + 602 13 libdispatch.dylib 0x00007fff68de63c6 _dispatch_lane_invoke + 433 14 libdispatch.dylib 0x00007fff68dea54b _dispatch_main_queue_callback_4CF + 813 15 CoreFoundation 0x00007fff3cea3a87 CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 9 16 CoreFoundation 0x00007fff3cea31b1 __CFRunLoopRun + 2289 17 CoreFoundation 0x00007fff3cea266e CFRunLoopRunSpecific + 455 18 Foundation 0x00007fff3f1082ff -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 280 19 _objc.cpython-38-darwin.so 0x00000001028c6627 ffi_call_unix64 + 79 20 ??? 0x000000010451be30 0x0 + 4367433264 ) libc++abi.dylib: terminating with uncaught exception of type NSException Abort trap: 6
@Janvrany has a better solution in the works. See: https://github.com/virantha/bricknil/issues/9 or: https://github.com/janvrany/bricknil/tree/devel
I've tried the devel branch and it seems to work well.
@janvrany has a better solution in the works. See:
9
or: https://github.com/janvrany/bricknil/tree/devel
I've tried the devel branch and it seems to work well.
Thanks. I tried this branch and it works well to output control signals. But it seems not returning input correctly.
I'm reading sensor like this. I expect it returns value of position and speed but output it [None].
print("DEBUG", self.rear_drive.value)
DEBUG: Rear [None]
DEBUG {<capability.sense_speed: 1>: [None], <capability.sense_pos: 2>: [None]}
#!/usr/bin/env python3
import logging
# from curio import sleep
from asyncio import sleep
from bricknil import attach, start
from bricknil.hub import CPlusHub
from bricknil.sensor.motor import CPlusXLMotor, CPlusLargeMotor, TachoMotor
@attach(CPlusLargeMotor, name='front_drive', capabilities=['sense_speed', ('sense_pos', 1)], port=1)
@attach(CPlusXLMotor, name='rear_drive', capabilities=['sense_speed', 'sense_pos'], port=3)
class Truck(CPlusHub):
def __init__(self, name, query_port_info=False, ble_id=None):
super().__init__(name, query_port_info, ble_id)
self.set_rear_speed = 100
async def front_drive_change(self):
front_speed = self.front_drive.value[TachoMotor.capability.sense_speed]
front_pos = self.front_drive.value[TachoMotor.capability.sense_pos]
async def rear_drive_change(self):
rear_speed = self.rear_drive.value[TachoMotor.capability.sense_speed]
async def run(self):
self.message_info("Running")
await self.rear_drive.activate_updates()
await sleep(5) # Give it enough time to gather data
await self.rear_drive.set_pos(0)
print("DEBUG", self.rear_drive.value)
async def system():
hub = Truck('truck', True)
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
start(system)
Is there any idea about this?
My bleak version == 0.7.1
λ uname -a Linux jetson-nano 4.9.140-tegra #1 SMP PREEMPT Wed Apr 8 18:10:49 PDT 2020 aarch64 aarch64 aarch64 GNU/Linux
@janvrany has a better solution in the works. See:
9
or: https://github.com/janvrany/bricknil/tree/devel I've tried the devel branch and it seems to work well.
Thanks. I tried this branch and it works well to output control signals. But it seems not returning input correctly.
I'm reading sensor like this. I expect it returns value of position and speed but output it [None].
print("DEBUG", self.rear_drive.value)
DEBUG: Rear [None] DEBUG {<capability.sense_speed: 1>: [None], <capability.sense_pos: 2>: [None]}
#!/usr/bin/env python3 import logging # from curio import sleep from asyncio import sleep from bricknil import attach, start from bricknil.hub import CPlusHub from bricknil.sensor.motor import CPlusXLMotor, CPlusLargeMotor, TachoMotor @attach(CPlusLargeMotor, name='front_drive', capabilities=['sense_speed', ('sense_pos', 1)], port=1) @attach(CPlusXLMotor, name='rear_drive', capabilities=['sense_speed', 'sense_pos'], port=3) class Truck(CPlusHub): def __init__(self, name, query_port_info=False, ble_id=None): super().__init__(name, query_port_info, ble_id) self.set_rear_speed = 100 async def front_drive_change(self): front_speed = self.front_drive.value[TachoMotor.capability.sense_speed] front_pos = self.front_drive.value[TachoMotor.capability.sense_pos] async def rear_drive_change(self): rear_speed = self.rear_drive.value[TachoMotor.capability.sense_speed] async def run(self): self.message_info("Running") await self.rear_drive.activate_updates() await sleep(5) # Give it enough time to gather data await self.rear_drive.set_pos(0) print("DEBUG", self.rear_drive.value) async def system(): hub = Truck('truck', True) if __name__ == '__main__': logging.basicConfig(level=logging.DEBUG) start(system)
Is there any idea about this?
My bleak version == 0.7.1
λ uname -a Linux jetson-nano 4.9.140-tegra #1 SMP PREEMPT Wed Apr 8 18:10:49 PDT 2020 aarch64 aarch64 aarch64 GNU/Linux
I figured out what's wrong. Seems exception inside async routines are ignored. If they failed then it doesn't produce meaningful value.
What was causing the exceptions?
What was causing the exceptions?
My code was bad as capability
is no longer inherit from TachoMotor
.
async def front_drive_change(self):
front_speed = self.front_drive.value[TachoMotor.capability.sense_speed]
front_pos = self.front_drive.value[TachoMotor.capability.sense_pos]
This triggered exception. Didn't figure out where it is handled. But the result is invalid value read back and the process seems dead.
For some reason, I randomly hit following error and no clue how it happens.
From error message, I guess it's because of some random events that old version of bleak can't handle properly. I made some minor changes to use the latest bleak and it works well. As my knowledge of entire code base is limited, I'm not sure if it works well for other part of the code. Attached is diff.
Diffs