Neato Robot ROS Package Splits Laser Scan Read Operations

neato_robot
ROS package works, and debugging its hang inside getMotors()
was a great first step. Now that I'm past the problem of mismatching responses between author's Neato robot vacuum and mine, I started looking at other parts of neato_driver.py
for potential explanations to its new (possibly timing-related) hang.
Since I had just examined getMotors()
, I looked at its counterpart setMotors()
and found nothing remarkable. getAnalogSensors()
, getDigitalSensors()
, and getCharger()
used the exact pattern as getMotors()
which meant they share the same fragility against different Neato responses but they'll work for now. setBacklight()
is nearly trivial.
That leaves the two methods for reading Neato's laser distance scanner. Wait, two? Yes, and that's where my concern lies. Other data retrieval methods like getMotors()
would issue a command and then parse its response before returning to caller. For the laser distance scanner, this is split into a requestScan()
which issues a getldsscan
command and immediately returns. Reading and parsing laser distance data is done in a separate method getScanRanges()
which the caller is expected to call later.
Why was this code structured in such a manner? My hypothesis is this was motivated by performance. When a getldsscan
command is issued over serial, a lot of data is returned. There are 360 lines of data, one for each degree of laser scanning with distance and intensity information, plus a few more lines of overhead. This is far more than any of the other data retrieval methods. So rather than wait for all that data to transmitted before it could be processed, this two-call pattern allows the caller to go off and do something else. The transmitted data is trusted to be buffered and waiting in serial communication module.
But this only works when the caller is diligent about making sure these two calls always follow each other, with no chance for some other command to accidentally get in between. If they fail to do so, everything will fall out of whack. Would that cause the hang I've observed? I'm not sure yet, but it would be better if we didn't even have to worry about such things.