
fredebec

Hi,
I am continuing my EZ-scripts to Python conversion and I have begin to work on my Roomba robot. All my command work with the EZ-scripts, but some of them don't with Python. I have in particular some difficulties with the reading of UART data.
Here are some part of scripts used to identify the Roomba working mode:
With EZ-Script
uartinit(0, 1, 115200) #have to have this to clear the buffer
sleep(1000)
$rxdata=0
uartWrite(0,1,142) # Mode check
uartWrite(0,1,35) # Mode check
sleep(50)
$rx = UartAvailable(0, 1)
print($rx)
if ($rx=1)
$rxdata = UARTRead(0, 1, $rx)
print( $rxdata )
endif
With this script, I am able to print $rxdata and then the rest of the script continues normally.
With Python
UART.InitHardwareUart(1, 115200) #have to have this to clear the buffer
sleep(1000)
UART.HardwareUartWrite(1,142) # Mode check 1
UART.HardwareUartWrite(1,35) # Mode check 2
sleep(50)
rxdata = 0
rx = UART.HardwareUartAvailable(1)
print(rx)
if rx == 1:
rxdata = UART.HardwareUartRead(1,rx)
print(rxdata)
With this script, i am unable to print rxdata and the console prints "Not connected" instead (and the script stop).
So, it seems that UART.HardwareUartRead does not behave like UARTRead (when UART.InitHardwareUart, UART.HardwareUartWrite and UART.HardwareUartAvailable behave as expected like their EZ-scripts equivalents).
Did I missed something ? Thanks
(By the way, the link to the Roomba manual page (https://synthiam.com/Software/Manual/Roomba-Movement-Panel-16116) does not seems to be active anymore)
Upgrade to this: https://synthiam.com/Products/ARC/Releases/ARC-Beta-2020-05-08-00-19463
@DJ thanks for the update. No more "not connected message"
@ptp, thanks a lot for your help and advice
Your script does not work: here is the output of the console:
Here the output with my ezscript (post #6):
@ptp, update:
I succeeded in running your code, but only when keeping separated HardwareUartAvailable and HardwareUartRead as I used to do:
I obtain the expected output
It seems the solution to my script was in the line
Could you explain what [0] means ?
Thanks
data is an array, data[0] is the first byte, data[1] the second byte etc.
Oh, OK. It's clear now. Thanks
Thanks to your help and advice, I have successfully converted most of my Roomba data reading scripts.
I have looked a little closer to "arrays" and using the array module, I have improved the previous script. Indeed, when using 2 lines for UART.HardwareUartWrite(), I had inconstancy in the results. By using biteArray, it is now working every time.
here is my final script:
Each call to HardwareUartWrite is a round-trip so there is a latency. Visualize the path: Python-ARC-Network-WIFI-EZB-Roomba you can imagine each step adding milliseconds. The roomba firmware must have timeout to avoid getting stuck waiting for a sub-command (second byte). I presume in some cases the sub-command (second byte) is handled as the the command and as consequence ignored. That is why is important to understand all the layers involved. Like DJ said does not make sense to reinvent the wheel. reinvention may be justified if you can learn from the process, later you will appreciate the software/control.
Padawan, you are in search of knowledge, Patient you must be. Your path you must decide.