RaspberryPiFoundation / python-build-hat

Build HAT Python library
MIT License
52 stars 18 forks source link

ValueError when Logging Data w/ 100 Hz Rate #194

Closed ArnavDagar closed 1 year ago

ArnavDagar commented 1 year ago

Hi,

With the new changes, I found that when I try to log motor data, I receive the following error after around 30 seconds to a minute:

Exception in thread Thread-2: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 865, in run self._target(*self._args, **self._kwargs) File "/home/pi/.local/lib/python3.7/site-packages/buildhat/serinterface.py", line 360, in loop newdata.append(int(d)) ValueError: invalid literal for int() with base 10: '+2\x009'

In another test, I got:

  1. ValueError: invalid literal for int() with base 10: '+4\x009041'
  2. ValueError: invalid literal for int() with base 10: '\x00'

The new changes also choke my RP Lidar Connected to USB port through a Serial to USB adapter for UART.

Can you please let me know how I can revert to the old library from December that worked much better for me. I am new to github and need help to go to an older library

Thank you so much, Arnav

chrisruk commented 1 year ago

I'm a bit confused about the error you're getting, I've been running the following for around 10mins without issue.

#!/usr/bin/python3.9
import time
from buildhat import Motor, Hat

h = Hat(debug=True)
m = Motor('B')

m.start(20)

while True:
    print(m.get())

I wasn't sure what you meant by logging. Please can you paste the python code you were running.

Also make sure you don't have a terminal emulator such as minicom etc. running at the same time as running python buildhat code.

For example if you have a terminal emulator such as minicom open on the same serial port it will interfere and cause issues with buildhat such as -

Exception in thread Thread-6:
Traceback (most recent call last):
  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "/home/pi/Repositories/python-build-hat/buildhat/serinterface.py", line 335, in loop
    portid = int(line[1])
ValueError: invalid literal for int() with base 10: 'C'

The line number in your error message also confused me as https://github.com/RaspberryPiFoundation/python-build-hat/blob/main/buildhat/serinterface.py#L360 line 360 doesn't seem to be the same as what is in your error message.

I'd recommend making sure buildhat is uninstalled by doing the following

pip3 uninstall buildhat

A few times, till you get the message:

WARNING: Skipping buildhat as it is not installed.

Then try installing from git again.

Also by using

h = Hat(debug=True)

like I did, it will create a log file of the serial data that was sent to the buildhat and received from the buildhat in /tmp

ArnavDagar commented 1 year ago

Hi Thanks, I will try, but right now I am very short on time for a deadline. Can you please guide me how to go to an older library from Dec that was functioning with my code. I am new to github and need some handholding.

In my project, besides the buildhat for Lego components, I am using a RPLidar A1 and a TFLuna which use UART over serial to USB interface with the raspberry pi. The RPLidar does not even function with the new library as it runs into buffer issues. And the TFluna based project runs into the value error issue Both these projects were running fine (but with lower motor and color sensor rates) before I went to the new library.

My project is due this Friday and I need to go to the older library for now. Can you please let me know how?

Thank you so much

Arnav

chrisruk commented 1 year ago

You should just be able to do the following to uninstall and install.

pip3 uninstall buildhat
pip3 install buildhat
ArnavDagar commented 1 year ago

Thanks! This will take me to the library from Dec or the one with the updated motor and color sensor rates?

chrisruk commented 1 year ago

It will install the latest version from the PyPi repository which was released in December ( https://pypi.org/project/buildhat/ ).

chrisruk commented 1 year ago

Would you be able to show the snippet of python that triggers the issue you're referring to? It's not clear to me what you mean here by logging.

At the moment I can't replicate this, apart from by opening a terminal emulator on the same serial interface.

Thanks!

chrisruk commented 1 year ago

Closing for now, as I can't reproduce unfortunately from within Python.

Feel free to re-open