Cannot resize buffers in rosserial, Arduino runs out of RAM

asked 2019-04-08 09:45:37 -0600

lmrosset gravatar image

I am using ROS kinetic on Ubuntu 16.04. The Adruino used is an Arduino UNO SMD (ATMega328P, 16MHz) plus an Adafruit Motor/Stepper/Servo Shield. The Arduino sketch includes ros_lib and Adafruit's shield's library.

What I am trying to do with the Arduino is to use it to drive a linear actuator according to (std_msgs::Int16) instructions sent by other ROS nodes from the computer, as well as publish the position (also std_msgs::Int16) of the motor from its encoder.

My sketch takes around 73% of the Arduino's RAM, leaving less than 600 bytes free after compiling. When I run a toy program, without the motor shield, there is enough memory for the Arduino to function properly but, with it, the controller stops responding very few milliseconds after the actuator starts running (and the positions start being published). I tested the sketch independently from the ROS library and it worked normally, taking instructions and printing the positions through a serial monitor.

The default buffer lengths for the Arduino UNO are 280 bytes each, which is probably trying to eat up more RAM than the controller has left. What I have been trying to do to fix this was resizing the publisher and subscriber buffers in ros_lib arduino library as well as in the rosserial_arduino ROS package (I did remake it with catkin_make). In both cases I changed every default buffer length value to 64 and every default or maximum number of publishers/subscribers to 6 (that last number should not be the problem, though). However, when running rosrun rosserial_arduino _port:=/dev/ttyACM0, the node connects to the Arduino and prints:

[INFO] [1554732556.538001]: Note: publish buffer size is 280 bytes
[INFO] [1554732556.538715]: Setup publisher on /Actuator_Position [std_msgs/Int16]
[INFO] [1554732556.554360]: Note: subscribe buffer size is 280 bytes
[INFO] [1554732556.554954]: Setup subscriber on /Actuator_Control [std_msgs/Int16]

which indicates to me (along with the Arduino crashing after the actuator starts moving) that the buffers are still unchanged.

The files I changed in ros_lib are: ros.h and ros/node_handle.h

Files changed in rosserial: rosserial_arduino/src/ros.h

Here is my Arduino sketch, with some simplifications and commentings that I tried using to make it lighter (please don't judge ;p). I am including the whole sketch because the minimal working example does work, since its RAM consumption is low enough to allow ros_lib's buffers to be allocated.

* Controlling the linear actuator:
* this node is subscribed to a ROS topic named "/Actuator_Control", of type
* `std_msgs::Int16' and will control the position of the linear actuator accor-
* ding to the Hall sensor units in the actuator.
* The instructions sent to this node should be formatted as follows:
* 2-byte instruction ([INS][DIR][RES][VAL])
*   bit[15:14], INSruction: 0b00 for GO-TO
*                           0b01 for STEP
*                           0b10 for FORCE
*                           0b11 for RESET
*   bit[13],    DIRection:  0b0 for FORWARD
*                           0b1 for BACKWARD
*   bit[12],    REServed:   Unused
*   bit[11:0],  VALue:      0x0000 - 0x0FFF step size, absolute position or ...
edit retag flag offensive close merge delete