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

Is there a way to write terminal commands within a ROS node?

asked 2016-11-10 05:19:46 -0500

Marcofon gravatar image

updated 2016-11-11 03:31:51 -0500

gvdhoorn gravatar image

Hello, I'll try to be clear. I want to build a ROS node in which some code will execute terminal commands without the user input. In fact i have a script that does some elaborations to .txt files and that takes only terminal (I'm on Ubuntu) commands to do its elaborations. For example, this is how i call the script from a terminal window:

get_hrv -R test.txt

So, what i want, it's a node that will have, for example, this piece of code above nested in some ROS code, so the terminal window with the results of the elaboration will show up when I'll run the node. I hope that it's all clear, let me know if you need a better explanation. Maybe, there is a ROS package that does the job that i want, i don't know, I'm searching it. Thank you in advance for your help!

Marco


Edit: Many thanks to both of you. In fact, since i'm using C++, i just used the code

system("get_hrv -R test.txt");

and all went fine! Thank you again and sorry for my bad knowledge of programming languages, i must use ROS and so on because i'm doing a project for my university, but i come from a completely different field, since i'm a mechanical engineer. Thank you!!!

edit retag flag offensive close merge delete

Comments

@Marcofon: could I ask you to please not post answers unless you are actually answering a question? ROS Answers is slightly different from a 'normal' forum.

If any of the answers posted by @rbbg or @Airuno2L answered your question, could you please mark it as such by ticking the checkmark? Thanks!

gvdhoorn gravatar image gvdhoorn  ( 2016-11-11 03:34:29 -0500 )edit

Ok, i'm very sorry! No problem!

Marcofon gravatar image Marcofon  ( 2016-11-11 04:02:56 -0500 )edit

No need to apologise. Just keep it in mind.

gvdhoorn gravatar image gvdhoorn  ( 2016-11-11 05:35:53 -0500 )edit

Sure! Of course!

Marcofon gravatar image Marcofon  ( 2016-11-11 06:00:09 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-11-10 06:52:34 -0500

Airuno2L gravatar image

There is nothing in ROS that prevents you from doing what you would normally do with python or C++. For example in python you could simply do this:

import os
os.system('get_hrv -R test.txt')

(Just a note, os.system is easy to use but is slowly being replaced by subprocess which isn't as easy to use in my opinion but is more capable. The main point is like rbbg said, this is really a python or C++ question, the fact that you want to do it with ROS doesn't really change anything).

edit flag offensive delete link more

Comments

Thank you for your reply, the problem is that i'm not experienced with programming. For example i have never used python and i really don't know how implementing it in a ros node. More over, i must use c++ in my node, for other reasons. Can you help me with it?

Marcofon gravatar image Marcofon  ( 2016-11-10 09:09:06 -0500 )edit
1

answered 2016-11-10 06:31:59 -0500

rbbg gravatar image

Hi Marco,

The way to do this depends on your system and the language you use for writing your node and you don't need ROS to do so. Stackoverflow offers a number of options both for Python and C++.

edit flag offensive delete link more

Comments

Thank you. As i wrote it on the other comment, can you help me to implement the code i need ? I must use c++ and my OS is Ubuntu 14.04. Can you help me with a detailed explanation? Sorry if i'm stealing your time, but i'm afraid that i will get lost on asking or reading on stackoverflow.

Marcofon gravatar image Marcofon  ( 2016-11-10 09:11:59 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-11-10 05:19:46 -0500

Seen: 1,433 times

Last updated: Nov 11 '16