AutonomyLab / libcreate

C++ library for interfacing with the iRobot Create 1 and 2.
BSD 3-Clause "New" or "Revised" License
47 stars 76 forks source link

Large delay in recieving messages from Roomba #68

Open blaine141 opened 2 years ago

blaine141 commented 2 years ago

I am using libcreate on a Raspberry Pi Zero W to communicate with a Roomba 694. I am noticing a delay of 30 seconds to 2 minutes for messages coming from the Roomba. Looking at the code this delay appears to be coming from messages coming in faster than they can be processed and filling up the serial buffer. My application uses stream mode as it is a V3 device.

I know my case is extreme and most people will not be using 1-core systems. I still feel like this is not the correct way to implement receiving messages from the Roomba. We should be fetching the newest message from the Roomba rather than the oldest message in the buffer.

As a temporary workaround, I have been clearing the buffer after each message is received and the delay has diappeared. I have not fully tested to see if half messages are coming through and being marked as corrupted.

What would be the best way to ensure each message we process is the latest from the Roomba and any older messages are discarded?

Also anyone else jump in if you have experienced this.

jacobperron commented 1 year ago

I'm not sure what the best strategy is for your setup, but one idea is we could add an option to use the serial "query" mode, even though you have a V3 device (which I think should still work). For example, instead of only using the protocol version here to choose the serial mode, we could add an option to override the choice:

https://github.com/AutonomyLab/libcreate/blob/d75d41c63843581cfd113fd8ceac976d65bc06b4/src/create.cpp#L47-L52