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

ROS Real Time

asked 2012-05-23 21:04:26 -0600

acp gravatar image

updated 2012-05-25 09:02:55 -0600

Kevin gravatar image

Hi everybody.

I just controlled two motors using ROS, however it is not a real time process.

I am just wondering what is the best easy way to make a pthread that runs in real time, which control the motors and can easily send messages to other ROS nodes.

Any help will be appreciate it

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2012-05-25 05:17:58 -0600

jbohren gravatar image

updated 2012-05-25 05:19:17 -0600

  1. Do you really need realtime control? At what rate are you trying to control your motors?
  2. As Bence said, a good architecture for doing realtime control in a ROS environment is OROCOS/RTT.
  3. If you just care about publishing from your realtime loops, there is a realtime publisher in the realtime_tools package (, but I've never used these.

If you create an RTT component, you can make a given input/output port use some ROS message type, and then use the tools in the rtt_ros_integration package to connect that port up to a ROS topic ( ). The default way to interact with an RTT component is through the OCL Deployer interface, and you can write interpreted scripts for this interface that specify how to connect RTT ports up to ROS topics. The line of script to connect an RTT port to a ROS topic looks something like this:

stream("YourComponentName.YourRTTPortName", ros.topic("/topic_name"))
edit flag offensive delete link more


Hi, in advance thank you for your replay. Yea, I need a real time control, however I have some questions. 1.-) do i need to install a real time tool, for instance RTAI and then use this tool to create a rtt component? 2.-)what do you think about Boost?

acp gravatar image acp  ( 2012-05-28 21:16:05 -0600 )edit

Hi, in advance thank you for your replay. Yea, I need a real time control, however I have some questions.

acp gravatar image acp  ( 2012-05-28 21:16:38 -0600 )edit

I am a bit confuse, I have installed orocos_toolchain_ros which contain rtt_ros_integration, is that enough to create a rtt component?

acp gravatar image acp  ( 2012-05-28 21:56:02 -0600 )edit

If you need realtime control, then you need a kernel that supports some sort of realtime scheduling. If you don't have a realtime kernel, then any RTT components that you build will not have realtime precision.

jbohren gravatar image jbohren  ( 2012-05-29 06:43:00 -0600 )edit i recommend to read RTT wiki and toolchain and follow the examples in (RTT 2.x Exercises). To get a good in site of rtt-components and real time processes

acp gravatar image acp  ( 2012-06-05 22:14:57 -0600 )edit

what is the C++ equivalent of the script line you passed to link a port to the topic?

matheus.pinto gravatar image matheus.pinto  ( 2019-02-20 13:55:01 -0600 )edit

answered 2012-05-24 00:20:51 -0600

Bence Magyar gravatar image

For real time control tasks the most commonly used tool is Orocos.

edit flag offensive delete link more


Thank you for the answer, but what I am missing is a simple code in real time using RTT where I can have a simple communication with the ports.

acp gravatar image acp  ( 2012-05-24 01:39:15 -0600 )edit

answered 2012-05-24 04:06:12 -0600

DimitriProsser gravatar image

updated 2012-05-25 03:53:18 -0600

If you really want to run a real-time thread in your application, skip pthread and just use boost::thread instead. You can find the docs here. It's simple, clean, and ROS uses it all over the place.


You can run as many threads in a process as you want, but there are only certain conditions under which these threads will run at full performance. boost::thread will use multiple cores by default, but if your threads do less work than scheduling the thread then you won't see any benefit from multithreading. Also, if you have more threads than cores, you won't see much performance increase.

Other than that, there's no reason that you can't run multiple threads in a single process.

Just an aside: ROS runs each node as a separate process to enable maximum operating system optimization (processes are typically handled and scheduled better than threads). You could look into splitting your real-time process into multiple nodes.

edit flag offensive delete link more


It looks really nice, thank you, however is this library suitable for running more than one single real-time thread in a single ros-node?

acp gravatar image acp  ( 2012-05-24 21:37:17 -0600 )edit

If you use the standard ROS communications C++ API, even if you're running realtime threads, your program will not be realtime-safe.

jbohren gravatar image jbohren  ( 2012-05-25 05:10:46 -0600 )edit

Thank you for your replay, I have a question, does boost runs the threads in real time? I have been looking for information about this, so far, I have not found anything?

acp gravatar image acp  ( 2012-05-28 21:24:16 -0600 )edit

Question Tools



Asked: 2012-05-23 21:04:26 -0600

Seen: 4,173 times

Last updated: May 25 '12