3

I have a ROS node written in Python that captures messages and writes them to disk (e.g. using pickle). I want to use these files later, in another Python script, outside of ROS, but I need to import the message classes.

Is that possible?

Thanks!

Flux
  • 9,805
  • 5
  • 46
  • 92
Michael Bar-Sinai
  • 2,729
  • 20
  • 27
  • Meanwhile, I'm running the other script from ROS, where I extract the data to a flat file. Works, but not that elegant, really :-( – Michael Bar-Sinai Sep 06 '16 at 06:44
  • What exactly do you mean by "outside of ROS"? It should be possible to use the message classes from any python script if you mean that (the setup.bash probably has to be sourced). After all: why don't you just try it? – luator Sep 07 '16 at 13:22
  • I want to run the script on any (unix) system, not just those that has ROS installed. As for message classes, I found the C++ headers, but not the Python files. Sourcing setup.bash in an interesting idea, though. – Michael Bar-Sinai Sep 08 '16 at 05:24
  • 1
    Well, as the message definitions are part of ROS, it obviously won't be possible on systems that don't have ROS installed. I don't know how the messages are implemented for the Python side but I guess it is only a wrapper around the C++ code. – luator Sep 08 '16 at 07:01

1 Answers1

4

Unfortunately I don't think it's possible to just import the message files outside of any ROS dependencies. For example, if you look inside one of the generated message class files:

---/your_catkin_ws/devel/lib/python2.7/dist-packages/your_package/msg/_Message.py

You will see that it depends at least on genpy and other message types contained in your message. Base messages are the same (in /opt/ros/indigo/lib/python2.7/dist-packages/std_msgs/msg).

While you could try to copy the minimum amount of dependencies until It Finally Works(!), it's a little un-elegant and probably going to be a brittle solution.

I believe the best solution is to convert your message to a generic non-ROS type, then store it in your pickle (so essentially what you've been doing already).

Felix
  • 2,064
  • 3
  • 21
  • 31