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

reading a file and publishing data to topic

asked 2016-03-01 14:13:20 -0500

anonymous user


updated 2016-03-01 14:13:49 -0500

data in the file is of type int [ ] = {1,2,3,4,5,6,7,8,9,10}

Code for Node_1 is as follows:

int main(int argc, char **argv)
  int temp;

  ros::init(argc, argv, "Node_1");

  ros::NodeHandle nh;

  ros::Publisher publisher = nh.advertise<std_msgs::Int32MultiArray>("Topic_1",1);

  std_msgs::Int32MultiArray vec;

  ifstream infile("array1.txt");

  while(infile >> temp)
      ROS_INFO("Extracting the elements of the vector from file");;

  return 0;

Executables are created when I compile (using catkin_make)

But when I run this node, the statement

"ROS_INFO("Extracting the elements of the vector from file");"

is not at all executed

What could probably be going wrong?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-03-02 01:12:29 -0500

mgruhler gravatar image

I'm guessing, you have the file in the wrong location. The file array1.txt needs to be in the directory where you execute rosrun <your_package> <your_node>, because this is set as the working directory of your executable.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-03-01 14:13:20 -0500

Seen: 587 times

Last updated: Mar 02 '16