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

File reading and roslaunch

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

Barbosa gravatar image

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

Hello,

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");
  if(!vel.is_open()
{
    ROS_INFO("file not found!");
    ros::shutdown();
  }

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

Comments

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

1 Answer

Sort by ยป oldest newest most voted
3

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

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

Question Tools

Stats

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

Seen: 4,790 times

Last updated: May 13 '12