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

how to read a text file and publish the data

asked 2016-06-05 14:14:11 -0600

naqi.nick gravatar image

i am trying to read a file.txt in my home directory and publish the integer value extracted from the file how can i do that can someone help plz

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-06-09 21:13:50 -0600

janindu gravatar image

Follow the tutorial in Publishers and Subscribers to learn how to publish a message.

After that, follow these simple steps.

Step 1 : Read integers from file and store them in an array / vector

Step 2 : Advertise a publisher to a topic of your preference with message type std_msgs/Int64.msg

ros::Publisher pub = nh.advertise<std_msgs::Int64>("topic_name", 5);

Step 3 : Iterate through your integer array/vector and publish them.

edit flag offensive delete link more


thank you for your reply can u plz explain how can i read a file too?

naqi.nick gravatar image naqi.nick  ( 2016-06-10 05:07:28 -0600 )edit

Reading from a file depends on the programming language and perhaps the platform.

Clear examples are included here :

Good luck! And sorry it took me 4 days to reply. It was a long weekend here in Aus and I took some time away from all my gadgets.

janindu gravatar image janindu  ( 2016-06-13 18:47:32 -0600 )edit

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: 2016-06-05 14:14:11 -0600

Seen: 1,939 times

Last updated: Jun 09 '16