rosrun inside a script
ros kinetic, ubuntu 16.04, intera 5.2 for a sawyer simulation, gazebo 7,
I want to be able to run a python script from an already running python script, and i'm not sure if this is possible and if what i've read already explains what i'm looking for.
Example:
rosrun pkg python_1.py
inside python1.py, i want to run python2.py.
What is the equivalent of rosrun
inside a python script?
Since i'm asking about this, i might as well ask, how could i do the same inside a C++
script?
Any information is much appreciated.
Thanks in advance.
~ Luke
Asked by lr101095 on 2018-06-24 23:59:17 UTC
Answers
I think that there's a "ROS way" to do this (if there is such a thing), or at least a couple of ROS ways. Instead of having your node start another node, why not just use topics, services, or actions?
For example, you can have the node that's solving the inverse kinematics (IK node) publish its status on a topic and the node that takes over subscribing to that topic. When the IK node publishes that it's task is complete, the next node gets the message and takes over.
This way will give you some extra flexibility in that you change swap out nodes and remap topics etc.
Asked by jayess on 2018-06-25 00:32:21 UTC
Comments
I've thought about doing something like that, but i was hoping there was a simpler way to go about it. I'll see if i can manage to use what you suggested and i'll let you know how it goes
Asked by lr101095 on 2018-06-25 02:27:37 UTC
I would actually recommend using services in this case: the IK task is probably self-contained (solve for a given EEF pose) and the control flow of the caller should be blocked by the callee (ie: caller should wait for completion). That is what services do. Actions would be more complex.
Asked by gvdhoorn on 2018-06-25 03:18:26 UTC
Comments
Why would you want to do this?
Asked by jayess on 2018-06-25 00:20:05 UTC
@jayess i have an inverse kinematics script that determines a required pose of a sawyer arm. so after the pose is achieved, i want a separate script to take over which is written independently of the IK script to be called.
Asked by lr101095 on 2018-06-25 00:22:20 UTC
Not sure if starting a node inside another one is the correct way to solve your issue, but you can have a look to python subprocess https://pythonspot.com/python-subprocess/
Asked by GuillaumeB on 2018-06-25 09:23:57 UTC