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

How to write ros commands in python file

asked 2013-03-18 04:46:50 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hi,

I am a newbie here. Went through ros documentation and executed all commands one by one. Just wondering how can I write a couple of ros commands in python file and execute it? For example, my program should be able to save data being published on a certain topic.

I can do it by entering commands one by one in ros. But dont know how can I combine all those commands in a python file and just run the file.

Looks a pretty stupid question, but would help me a lot.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
4

answered 2013-03-18 05:20:27 -0500

This is precisely what launch files are for (read more about roslaunch here.) With a launch file, you create a list of ROS commands that you want to run in an xml file, and then when you "launch" the file, all of the commands are executed. Within launch files, you can start nodes, set parameters, parse command-line options, etc. It may seem intimidating to have one more new thing to learn, but my advice is to go ahead and learn how to use launch files early on. They will be very helpful as you learn more about ROS.

If you specifically are interested in recording data using rosbag, check out this question. There is a good example of exactly how to do that.

edit flag offensive delete link more

Comments

Do these launch files only uses xml commands? Can I use python/c++ instead of xml for the launch file?

Latif Anjum gravatar image Latif Anjum  ( 2013-03-19 00:29:38 -0500 )edit

No, you cannot use anything other than supported XML in launch files. But, if you have a python script then you can start it using the XML syntax in launch files and it will run whatever is in your script, as long as it's executable.

Thomas D gravatar image Thomas D  ( 2013-03-19 05:05:33 -0500 )edit
-1

answered 2013-03-19 00:29:08 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Do these launch files only uses xml commands? Can I use python/c++ instead of xml for the launch file?

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-03-18 04:46:50 -0500

Seen: 928 times

Last updated: Mar 19 '13