Use Arduino Libraries in ROS

asked 2018-09-03 21:04:21 -0500

Nelle gravatar image

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?

edit retag flag offensive close merge delete

Comments

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, ..

gvdhoorn gravatar image gvdhoorn  ( 2018-09-04 02:01:12 -0500 )edit

.. and calling functions that could potentially block for a "long time" interferes with the normal control flow and could results in desyncs.

gvdhoorn gravatar image gvdhoorn  ( 2018-09-04 02:01:50 -0500 )edit

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?

gvdhoorn gravatar image gvdhoorn  ( 2018-09-04 02:03:01 -0500 )edit

Do I need to include the rosserial library in my custom library?

Nelle gravatar image Nelle  ( 2018-09-04 02:45:41 -0500 )edit

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.

gvdhoorn gravatar image gvdhoorn  ( 2018-09-04 02:47:25 -0500 )edit

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.

Nelle gravatar image Nelle  ( 2018-09-04 02:50:26 -0500 )edit

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.

Nelle gravatar image Nelle  ( 2018-09-04 02:53:33 -0500 )edit