create node in python as thread [closed]

asked 2017-07-11 13:55:27 -0500

JaimeOrellana gravatar image

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()
edit retag flag offensive reopen merge delete

Closed for the following reason too localized by JaimeOrellana
close date 2017-07-11 16:20:15.374121

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?

ahendrix gravatar image ahendrix  ( 2017-07-11 14:16:37 -0500 )edit

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.

JaimeOrellana gravatar image JaimeOrellana  ( 2017-07-11 15:16:22 -0500 )edit

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?

gvdhoorn gravatar image gvdhoorn  ( 2017-07-11 15:29:40 -0500 )edit

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

JaimeOrellana gravatar image JaimeOrellana  ( 2017-07-11 16:12:39 -0500 )edit

Why did you close your question?

gvdhoorn gravatar image gvdhoorn  ( 2017-07-12 01:58:32 -0500 )edit