Robotics StackExchange | Archived questions

create node in python as thread

Hi everyone, I've been stuck with a difficult problem of creating background nodes via threading within a python script. My goal is to create nodes dynamical within a python function.

from threading import Thread
import rospy
import time


def create_node(caller_id=""):
    rospy.init_node(caller_id, disable_signals=True, anonymous=True)
    rospy.spin()


def main():

    b_thread = Thread(target=(create_node), args=("test_node",))

    b_thread.daemon = True

    b_thread.start()

    time.sleep(1)

main()

Asked by JaimeOrellana on 2017-07-11 13:55:27 UTC

Comments

Do these need to be separate nodes or is it OK if main() calls rospy.init_node and then just create publishers or subscribers as necessary in your threads?

Asked by ahendrix on 2017-07-11 14:16:37 UTC

Thanks for responding so quick! The goal of threading would be to make each call a separate node so that I would be able to manage their subscriptions via the rosmaster.

Asked by JaimeOrellana on 2017-07-11 15:16:22 UTC

Can you clarify what you mean with 'each call'? Are you talking about service servers here? And what does "manage their subscriptions via the rosmaster" mean exactly?

Can you perhaps describe what your ultimate goal is?

Asked by gvdhoorn on 2017-07-11 15:29:40 UTC

manage their subscriptions via rosmaster means calling the rosmaster api to manage creating new subscribers/deleting subscribers

Asked by JaimeOrellana on 2017-07-11 16:12:39 UTC

Why did you close your question?

Asked by gvdhoorn on 2017-07-12 01:58:32 UTC

Answers