Robotics StackExchange | Archived questions

How to import a ros-communicating class within a separate python script

I want to have a python class which I can import in a python script and initialize, to read and write from it. This python class however would also have some ros-servers inside it which would communicate with another ros application. I'm not sure however how it is possible or if it can be possible.

I can for example have one python script which defines this class and also initializes it within a ros-node inside the same python script that is executed with rosrun or through a launch file. However, while I am working with another scrip, especially in pycharm, I don't know if I can access the information of that python class without initializing another ros node in this secondary script. Another environment could also be importing this class inside a jupyter-notebook.

One possible scenario that I see is that the moment I import the class and initialize it, it is also separately initialized as a ros node . But I don't know how it can be possible, especially without using the rosrun or roslaunch command.

Another scenario could also be that I have already launched the node but can still communicate or import it from another script in jupyter-notebook or pycharm. Or perhaps using rospkg may help.

The best would be something like this:

import some_module
m = some_module(with_its_ros_communicating_methods_available=True)

Asked by azerila on 2020-04-14 15:17:02 UTC

Comments

Answers