ros-drivers / rosserial

A ROS client library for small, embedded devices, such as Arduino. See: http://wiki.ros.org/rosserial
515 stars 525 forks source link

Sync issues with rosserial and Arduino #125

Open aakarm opened 10 years ago

aakarm commented 10 years ago

Hey all,

I know this question has been put up a few times earlier, but I haven't been able to find a solution to it yet. I have been getting the error "Unable to sync with device" when I run the rosserial node. I have noticed till the time I have a simple code with no function calls, the device sync is not an issue. But when I call a few functions from the Loop(), the syncing with the device is an issue. Reading other posts, I found that reusing spinOnce() again and again over a small interval of time is required. I have tried that too throughout my code. It still gives me an error. That solution worked for me only when I was getting the issue of "Lost sync with Device". In this case I think the device is not getting connected at all. I don't know if I am missing some posts online which have already clarified this issue.

I cloned the rosserial library for Groovy about a week ago and I am using an Arduino DUE.

Any help on this topic would be really great. Thank you!

mikepurvis commented 9 years ago

Hi @aakarm,

I haven't used the DUE myself, but I suspect that the ArduinoHardware class is trying to connect via the default UART (hardware serial port) on the MCU, rather than the emulated one provided over the USB link. At least for the Leonardo, this ambiguity is resolved in Hydro+ by the optional USB_CON define. Not sure if USB_CON specifically applies to the DUE, but I imagine you'll have to follow a similar path.

If you get it working, please let us know how; I'd happily merge a change to ArduinoHardware for indigo to make it more straightforward.

chrisspen commented 8 years ago

@mikepurvis, I ran into this with the Leonardo on Indigo. No, unfortunately, specifying #define USB_CON does not fix the problem. That string isn't even referenced in the code you linked to.

I found this post that suggested using #define USE_USBCON, but that doesn't work either.

I also tried #define USBCON, and still receive the error.

eborghi10 commented 7 years ago

Hi, anyone has solved this issue?

I have the same problem but using ROS Kinetic. Also I tried to change the baud rate using rosrun rosserial_python serial_node.py /dev/ttyACM0 baud:=XXX but without lucky.

NOTE: I tested the Arduino Leonardo with the publisher-subscriber example.

chrisspen commented 7 years ago

I don't think there's anything rosserial can do about this. In my experience, it's usually a problem with the Arduino running out of memory, or trying to send a message that's larger than the Arduino's serial buffer. If your Arduino sketch takes over 80% of memory, or you're sending a message like IMU, Odometry, or TF, that's probably the cause.

eborghi10 commented 7 years ago

@chrisspen I tried increasing the serial buffer but the problem continues...

laukikm commented 6 years ago

I don't think there's anything rosserial can do about this. In my experience, it's usually a problem with the Arduino running out of memory, or trying to send a message that's larger than the Arduino's serial buffer. If your Arduino sketch takes over 80% of memory, or you're sending a message like IMU, Odometry, or TF, that's probably the cause.

No. I tried sending sensor_msgs/LaserScan and a partial message was sent (4-5 out of 90 array points). Also, I experience this syncing issue when I do not change anything code-wise, just by disconnecting and reconnecting again. Please help!

attermann commented 6 years ago

FYI, if you suspect size of messages is your issue and you’re using IMU, Odom, TF, etc., then you might want to checkout https://github.com/ecostech/rosproxy https://github.com/ecostech/rosproxy. It essentially compresses the messages sent over the serial link by getting rid of unused or redundant data on the arduino side and then expands the messages again on the server side. Hope this helps.

On Apr 10, 2017, at 7:19 AM, Chris Spencer notifications@github.com wrote:

I don't think there's anything rosserial can do about this. In my experience, it's usually a problem with the Arduino running out of memory, or trying to send a message that's larger than the Arduino's serial buffer. If your Arduino sketch takes over 80% of memory, or you're sending a message like IMU, Odometry, or TF, that's probably the cause.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ros-drivers/rosserial/issues/125#issuecomment-292946747, or mute the thread https://github.com/notifications/unsubscribe-auth/AK41mapTXf3JMwBRhN-u7OxLxJu8lO5iks5ruixcgaJpZM4CAJFE.

eborghi10 commented 6 years ago

I used rosproxy with Odom and Twist messages and works like a charm.

chrisspen commented 6 years ago

In my experience, any Arduino with less than 40KB of memory (e.g. Uno, Leo, etc) will not work with Rosserial, as the relatively large packet sizes overwhelm the Arduino's memory, and cause the "Unable to sync with device". The hacks to increase the USB serial buffer have no effect, because those changes can't magically create more flash. You can allocate all your flash to the buffer, but eventually some queued odom packets will be too big to fit in it.

The real obnoxious thing about this error is that the Arduino will appear to work for a short while...until it receives or has to send a packet that's a little too large, making it very difficult to diagnose. I banged my head against this error for months before I tested my code with an Arduino Mega and an Arduino Uno Pro, which have +100KB of flash, and found those worked perfectly.

I'd recommend the Arduino memory limited be mentioned in the docs, as it seems like many many people have run into this problem, and the current docs imply all Arduinos should work equally well with rosserial.

shuhaowu commented 6 years ago

One thing you can do with an arduino is to lower the buffer size, which will limit the max length of the message by doing something like:

ros::NodeHandle_<ArduinoHardware, 1, 1, 150, 150> nh;

This limits each message to be 150 bytes and 1 sub/pub only. See http://wiki.ros.org/rosserial#Maximum_Size_of_a_Message.2C_Maximum_Number_of_Publishers.2BAC8-Subscribers for details.

One thing that would be interesting to find out is how much space a message takes, then if you only use a particular message, you can optimize significantly.

aena9898 commented 5 years ago

Hello All, I am working with mobile robot and calculating its position in 2D by wheel encoder (it is absolute encoder with 12 bit resolution). I am getting encoder position through MAXRS485 chip using arduino mega 2560. My encoder gives output with 2Mbps baud rate. Now i want to publish odom data to ROS using rosserial package. i have to publish data on nav_msgs::Odometry. But i get large buffer size error. Then i found some solution related to rosserial buffer problem and i changed following into my node_handle.h header file inside Arduino->libraries->ros_lib->ros ,

       int MAX_SUBSCRIBERS=12,
       int MAX_PUBLISHERS=12,
       int INPUT_SIZE=1024,
       int OUTPUT_SIZE=1024>

But still get error. I also try to add following line into my ros.h

#elif defined(__AVR_ATmega2560__)
   typedef NodeHandle_<ArduinoHardware, 1, 1, 150, 150> NodeHandle;

but still get no solution. By using above two changes , now i got this new error. "[WARN] [WallTime: 1564588083.862847] Serial Port read failure: [INFO] [WallTime: 1564588083.864401] Packet Failed : Failed to read msg data [INFO] [WallTime: 1564588083.865604] msg len is 8 [WARN] [WallTime: 1564588084.069648] Serial Port read returned short (expected 61 bytes, received 10 instead)."

I have searched a lot on different blogs and come to know that nav_msgs/Odometry message is quite a big which can be solved by reducing publish rate or choose message with small size.

Please someone guide me through this problem

Thank you

attaoveisi commented 4 years ago

Hello All, I am working with mobile robot and calculating its position in 2D by wheel encoder (it is absolute encoder with 12 bit resolution). I am getting encoder position through MAXRS485 chip using arduino mega 2560. My encoder gives output with 2Mbps baud rate. Now i want to publish odom data to ROS using rosserial package. i have to publish data on nav_msgs::Odometry. But i get large buffer size error. Then i found some solution related to rosserial buffer problem and i changed following into my node_handle.h header file inside Arduino->libraries->ros_lib->ros ,

       int MAX_SUBSCRIBERS=12,
       int MAX_PUBLISHERS=12,
       int INPUT_SIZE=1024,
       int OUTPUT_SIZE=1024>

But still get error. I also try to add following line into my ros.h

#elif defined(__AVR_ATmega2560__)
   typedef NodeHandle_<ArduinoHardware, 1, 1, 150, 150> NodeHandle;

but still get no solution. By using above two changes , now i got this new error. "[WARN] [WallTime: 1564588083.862847] Serial Port read failure: [INFO] [WallTime: 1564588083.864401] Packet Failed : Failed to read msg data [INFO] [WallTime: 1564588083.865604] msg len is 8 [WARN] [WallTime: 1564588084.069648] Serial Port read returned short (expected 61 bytes, received 10 instead)."

I have searched a lot on different blogs and come to know that nav_msgs/Odometry message is quite a big which can be solved by reducing publish rate or choose message with small size.

Please someone guide me through this problem

Thank you

Hi. I know it has been a while. I have the same issue. Have you found a fix so far?