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

Subscribing to a text file

asked 2019-09-11 17:26:22 -0500

enthusiast.australia gravatar image

updated 2019-09-11 17:28:23 -0500

hello everyone. I want to know if i could subscribe to a data stored in a text file. My data is in the form

0.97542241 1.22256888

1.66565685 1.25254882

1.22222658 1.26589587

There is a tab space between each row entry, two entries in a row and multiple in column. Something like that. I am running a program which is giving me these readings. I am storing them in a text file. Now i want to use this but i am unable to do so. I know about publisher/subscriber but i am unable to directly publish this data, so i thought of going other way around, now i am storing this data in a text file and i want to read that file use this in the form a message. Any idea how can i do that. I am using python for coding and ros kinetic with ubuntu 16.04.

edit retag flag offensive close merge delete

Comments

1

but i am unable to directly publish this data

Is the other program not something you can modify, or are you having trouble getting the publisher setup and working properly?

It's not impossible to do what you ask, but it would be a last resort if there wasn't a tidier way of doing it.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-09-11 18:21:26 -0500 )edit

I can modify but the the other is in python 3.6 and kinetic uses 2.7. I tried to modify the code but unable to do so, so i thought of coming up with this thing. there were certain libraries and chunks of code which were hectic to transform. so, i decide to go with this approach

enthusiast.australia gravatar image enthusiast.australia  ( 2019-09-11 18:29:30 -0500 )edit
1

It is actually possible to build a version of Kinetic that supports Python 3.x.

See my answer to #q237613. It is somewhat involved, but would make it possible to write a regular publisher and use ROS 'normally' for this.

Seeing your other questions: if you're still using a Raspberry Pi, there is a good chance you're building ROS from source anyway, so building it for a different version of Python should not be such a big change.

gvdhoorn gravatar image gvdhoorn  ( 2019-09-14 06:10:30 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-09-12 05:21:35 -0500

Okay, I understand your situation now.

I'd recommend using a FIFO instead of a file, they're similar in many ways. You can open them with the same functions you use for files but they just pipe data between processes instead of storing it on a disk.

There's a good example of doing this in python here because the only connection is the linux FIFO the sender can be python 3.6 and the receiver can be python 2.7.

Lets us know how you get on.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2019-09-11 17:26:22 -0500

Seen: 534 times

Last updated: Sep 12 '19