1

This question is somewhat a follow up question to my previous post: ROS: Publish topic without 3 second latching

Again, as a premise, I'm very inexperienced with ROS, thus this question might be missing some data and or be a little confusing.

Let's say I have a node that publishes to a topic and an external C program that dumps data every x Hz. How can I, from that external program, publish to a rostopic every time I get data from that program?

That is my base question, I'm not sure how understandble that is so I'll be very specific with what I want to do.

I have a C program that dumps ADSB flight data. For every data dump I convert that data into a mavros/ADSBVehicle rosmsg. I was previously trying to publish that message via CLI, which I found out was not the correct way of doing it. Now I have created a ROS node that would to the publishing of that message. My question is, how can I, from that external program, publish to a rostopic through that node?

Does that make sense? Thank you.

  • Is it a C or C++ program you're reading the data with. Also if you're creating a ROS message directly in the code it can be published there. Could you share part of the code where you create a ros message? – BTables Dec 07 '21 at 19:07
  • Hi. It is a C program. I don't have the code right now but I can try to explain. It is a C program that dumps data to the screen (essentially printing every blob of data to the terminal). My naive approach when publishing via CLI was removing the terminal prints and formatting the message (as one would format a message with sprintf) into a mavros/ADSBVehicle message and then calling system(message); (where message would be the formatted ros message). Does that help? If you don't understand I can leave the code in a couple of days but it's essentially a sprintf and system() call. Thank you – Francisco Zacarias Dec 07 '21 at 19:34
  • 1
    I see. So, in this instance it might be best to try and compile the C program as a C++ ros node and put it into a ROS package. The only other option would be to do something like having the C program and the ROS node talk via a named pipe or socket; but both of those are sub-optimal solutions in my mind. – BTables Dec 08 '21 at 14:53
  • Hey @BTables. Thanks for the answers in both topics. Your answers to both topics I made were very helpful. Thank you. – Francisco Zacarias Dec 09 '21 at 14:55

1 Answers1

0

I have used rospylib - https://roslibpy.readthedocs.io/en/latest/ for sending data from my raspberry pi to the computer where I am working on ROS. You have to use ROSBridge in addition to this.

  1. Install and run ROSBridge - http://wiki.ros.org/rosbridge_suite
  2. Use sample code in rospylib to run it

I know you are using C, however there are many developed libraries in different language that works like the same for example in rust we have rosrust - https://github.com/adnanademovic/rosrust/blob/master/examples/examples/publisher_latch_demo.rs

I hope it can direct you in a good direction now.

Ankit Kumar
  • 403
  • 3
  • 8