ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Without knowing more about your setup it's hard to know what's wrong. When you compile your sketch, how much space does the compiler say is left for local variables? ("leaving nnn bytes for local variables")
I've had very mixed results with rosserial_arduino
on 2kb RAM Arduino. My sketches failed to work reliably unless at least 700 bytes or so of "local variable" space was left. Remember that "local variables" means stack+heap.
There are some things you can do to reduce memory usage (a little). Instead of declaring your node handle like this:
ros::NodeHande nh;
declare it instead using an internal class and specify the number of publishers and subscribers and the input and output buffer sizes explicitly:
ros::NodeHandle_<ArduinoHardware, 5, 14, 125, 125> nh;
The parameters, in order, are the number of subscribers you will declare, the number of publishers, the size of the input buffer, in bytes, and the size of the output buffer, in bytes. The input buffer must be large enough to hold any incoming messages for one call to nh::spinOnce()
, and the output buffer must be large enough to hold all messages published in between calls to nh::spinOnce()
. On my robot I was trying to publish 14 sensor values. The "125" values for the buffer sizes were are the smallest I was able to get to work. Even at that I had only about 600 bytes free, and the system proved unreliable.
I've abandoned rosserial_arduino
because of the difficulty of making it work on a 2kbyte Arduino. A larger device such as a Mega or Teensy would likely be fine. Instead, I'm using the ros_arduino_bridge
package for Linux/Arduino communication.