ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Not getting an answer I'm answering my own question.

I went ahead, for now, and cleaned up the Arduino code I had written that integrates with rosserial_arduino. There were a number of issues given that the Nano board only has 2Kbytes of RAM memory, and with the ROS stuff integrated there were issues when trying to have more than about 4 messages subscribed to. I could push up to 10, but it was unstable, with erratic communications issues especially on startup.

Note that the simple servo example for rosserial doesn't provide the ability to control the velocity of the servo(s) and that is something that is needed, so I have that implemented in my Arduino code. But that, of course makes the code bigger and adds a bit more processing when moving the servo(s).

I finally resolved the memory issues by using UInt32 messages and packing the UInt32 with a servo index, and the value(s) associated with the request. That got me down to only two Subscribed messages and allows me to control as many servos as I want, currently I have 5 in the head. I support MoveTo() and setting of Velocity and/or Acceleration values. With this change I went from about 300 bytes of free RAM (as reported by the Arduino IDE) to nearly 800 bytes. And the operation seems to be very reliable, so the Arduino no longer appears to be running out of RAM during operation.

My other alternative was to write a simple serial protocol for talking to the Arduino, but since that has already been done in rosserial_arduino, and it has a bunch of timeout and error handling code I didn't feel like reinventing the wheel.

On the PC side of the fence I have a Python bit of code that has an object for a Servo and that manages the mapping of servo input values to servo output (actual physical limits that I want the servo to move. Also the Acceleration and Velocity values are maintained within this object (as well as being sent down to the Arduino).

Ultimately the Python code will likely get migrated to C++, and will be used by other parts of ROS to manage the low level control of the servos.

I gather that once there is a complete definition for the robot that will include the various joint limits which would translate to servo (or other actuator) limits, but for now this works quite well.

My Python test code includes a GUI with the ability to move the servos via sliders, set the Acceleration and Velocity, as well as returning the servos to rest position.