Rosanswers logo

I'm just getting started with ROS and ultimately want to do some experimentation with CV and physical object manipulation, but I have miles to go before I'm at that point.

I have been working with MyRobotLab but Oracle Java on my 64bit Linux machine is unstable, even after completely nuking all things Java and doing a clean reinstall. When things work it works reasonably well, but too many hiccups to be efficient.

Also issues on a different machine running Win10 and Java there. So I decided to move to ROS which has a steeper learning curve, but appears to be much more stable.

For starters I have a "head" with two cameras for eyes, servos driving the eyes in X and Y and servos driving the head in X and Y.

I have an Arduino in the head that interfaces to the servos to control them. Currently no position feedback from the servos.

In MyRobotLab the Arduino code allows specifying Acceleration and Velocity values for the servos by using the writeMicroseconds() method to drive the servo motion. I have implemented this and have it interfacing with ROS and I'm able to move the servos and set Velocity and Acceleration just fine.

The other part of the MRL implementation is also to be able to specify Min and Max values for the Servo to prevent driving it past points of physical constraint in the head. For example with the eyes the Y axis movement is quite small so the servo range of motion should be limited.

MRL does this with an actually SetMinMax() method and also with a mapping function that allows more control over the relationship of the input and output Min/Max for the servo(s).

So I wondered what people are doing with ROS to accomplish similar things when using Arduino to control your servos?

Is there some code that exists that manages the MinMax() limits for servos. Or will I need to write my own code.

Right now I'm working towards a small application to drive the head and eye motion in a pre-programmed mode as my next set of tests.

Once I get that working (I already have Python code for doing this with MyRobotLab) then it's on to looking at interfacing with OpenCV to do some initial simple object tracking as I have been able to do with MRL (on the days when Java cooperates:)

If I have missed some suitable code/tutorial/examples could someone point me in the right direction?

And I would be interested to hear if others are doing anything similar with your Arduino based servo control?


Originally posted by burtbick on ROS Answers with karma: 201 on 2017-04-14

Post score: 0


1 Answer 1


Rosanswers logo

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.

Originally posted by burtbick with karma: 201 on 2017-04-19

This answer was ACCEPTED on the original site

Post score: 0

Original comments

Comment by cpagravel on 2017-04-19:
From my experience, I think that you are more likely to get answers if you have a very specific question and if you shorten the amount of text in the question body. Being specific and concise will really make a difference. Consider the style of questions that StackOverflow promotes. My two cents.

Comment by Airuno2L on 2017-04-19:
Yeah it's too much information to open real quick and see if I know the answer.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.