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

ROS Real Time

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

acp gravatar image

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

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
5

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

jbohren gravatar image

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

  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 (http://www.ros.org/wiki/realtime_tools), 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 ( http://www.ros.org/wiki/rtt_ros_integration ). 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

Comments

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 -0500 )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 -0500 )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 -0500 )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 -0500 )edit

http://www.orocos.org/wiki/orocos/ i recommend to read RTT wiki and toolchain and follow the examples in http://www.orocos.org/wiki/orocos/toolchain/getting-started/toolchain-tutorials (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 -0500 )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 -0500 )edit
3

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

Bence Magyar gravatar image

For real time control tasks the most commonly used tool is Orocos. http://www.ros.org/wiki/orocos

edit flag offensive delete link more

Comments

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 -0500 )edit
0

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

DimitriProsser gravatar image

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

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.

EDIT:

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

Comments

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 -0500 )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 -0500 )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 -0500 )edit

Question Tools

3 followers

Stats

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

Seen: 4,210 times

Last updated: May 25 '12