ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

File reading and roslaunch

asked 2012-05-13 06:13:57 -0600

Barbosa gravatar image

updated 2012-05-13 06:15:07 -0600


I built a node which simply reads a file and builds a vector of data from it. However, when i tried running the node from roslaunch instead of rosrun, according to the log file, it ca n longer open the said data.txt file, causing my node to shutdown. I tried moving the file around but the problem persists. Here is the code

ifstream vel("ros_workspace/odometry/traj.txt");
    ROS_INFO("file not found!");

I am new to ROS and not very familiar with the PATHS, don't even know if the problem comes from there, so this might be a very simple question.

Thanks! Barbosa

edit retag flag offensive close merge delete


Hi, I am unable to read a test file to build a vector from it. Would you please share your code of reading a file and building a vector of data. Thanks

AsifA gravatar image AsifA  ( 2014-07-29 17:10:03 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2012-05-13 07:21:07 -0600

While using roslaunch, all relative paths are evaluated from ~/.ros. So the file is being searched at the location ~/.ros/ros_workspace/odometry/traj.txt.

A much better solution is to provide the filename as an input parameter. You can place the file in one of your packages, and use the find substitution to locate the file. Checkout the roslaunch XML wiki page for an example using manifest.xml. You can then use the roscpp parameter api to obtain this parameter in your code.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-05-13 06:13:57 -0600

Seen: 4,394 times

Last updated: May 13 '12