Use Arduino Libraries in ROS
Hello all.
I have made a publisher/subscriber for rosserial to communicate with Arduino. There are 6 sensors in total, 1 ultrasonic, 2 analog IRs and 3 digital IRs. I uploaded my code and it is running smoothly with rosserial. But when I made a library for the sensors and used it in the Arduino, I suddenly get an error "run loop error: serial port read error returned short". How do you use an Arduino library with ROS?
One thing to check is whether any of those libraries are trying to use the serial port (they can't, not even for printing a log message, as
rosserial
needs exclusive access to it) or whether they are using any busy waits (ie:while
loops to wait for data/pins).rosserial
runs an eventloop, .... and calling functions that could potentially block for a "long time" interferes with the normal control flow and could results in desyncs.
I believe you've already figured part of this out, seeing as you posted #q302299.
Is that a duplicate of this one or a follow-up?
Do I need to include the rosserial library in my custom library?
I can't say. You write in your other question that you're using "delays". That is what I mean with "block for a long time". IIRC, you cannot do that with
rosserial
. I don't understand how including one library in another would solve that.The library for the sensors was just to simplify the code and put all the functions for the sensors in a neat library. Since it doens't work, I rejected the idea of having a library. If it would help, I didn't include any delays in the library, either.
If I can't use delays in rosserial, can I instead delay the publishing of a message? So it looks like I'm delaying too? The delay would be in the python code.