-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to have two nodes created in one Notebook? #27
Comments
Hi, I think it would be more common to have one node per notebook (maybe the node should actually be started automatically with jupyter-ros...) But you can definitely have more than one subscriber (runs async in it's own thread) or publisher in the same notebook. For publisher, I had a small decorator to run the publisher in a thread so that you can do something like:
but this part of the code isn't ready yet. If you want to work on something like this that would be awesome. What's your use case for two nodes? |
The use case is teaching: have a simple node that is publishing and another simple nose that subscribes and print. The two are used together in explaining the basics.
It’s probably the most common first example. Basically it’s these two, in one notebook:
#### Node 1
```
import rospy
from std_msgs.msg import Int32
# Make this into a ROS node.
rospy.init_node('topic_publisher')
# Prepare to publish topic `counter`
pub = rospy.Publisher('counter', Int32, queue_size=10)
# sleep at 2 loops per second
rate = rospy.Rate(2)
count = 0
# loop until ^c
while not rospy.is_shutdown():
pub.publish(count)
count += 1
rate.sleep()
NODE 2:
import rospy
from std_msgs.msg import Int32
# define function is called each time the message is published (by some other node)
def callback(msg):
print "The square is " + str(msg.data*msg.data)
rospy.init_node('topic_subscriber')
sub = rospy.Subscriber('counter', Int32, callback)
# Wait for published topics, exit on ^c
rospy.spin()
```
You say that each node has its own thread, but I don’t understand. How does notebook or jupyter-ros know where one node ends and the new one starts?
Also I don’t understand decorators or the example you cite in your email.
|
Any response to these questions. A clarificaiton of the threading and node creation model would be very useful. |
yeah so this would be most simple to do in either two seperate notebooks (very convenient with JupyterLab since you can just create two tabs and put them next to each other) or you can open two Notebooks in two browser tabs. Also you don't need two nodes for a subscriber and publisher. However, the publisher doesn't. You need to manually create a thread, or use the following magic (that has not yet been released): https://github.com/RoboStack/jupyter-ros/blob/master/jupyros/ipy.py That would allow you to create a cell like this:
But it hasn't been released because, IIRC, there were some problems. If you have some PR to make this functionality better that would be awesome! :) |
Hi Wolf,
Also you don't need two nodes for a subscriber and publisher.
I know but I am trying to teach the concept and that is the most natural way to explain it as a first example. But if its not possible then that’s fine/
If you have some PR to make this functionality better that would be awesome! :
I would be happy to but I don’t understand how it all works yet :)
Pito
… w
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#27?email_source=notifications&email_token=AAAK5CMZKMO7NQQFOORI35LP6NGETA5CNFSM4H5BGF32YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZNJALA#issuecomment-509251628>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAAK5CL5DH7UVNRJMVNJXM3P6NGETANCNFSM4H5BGF3Q>.
|
As far as I know you also can't have two nodes in a single python script ... So it's not even a limitation of Jupyter, but rather of rospy that you need two python processes for two real nodes. |
Yes but one of the advantages of using Jupiter Notebook would be to allow better exposition of the concepts in one notebook. Anyway, it’s fine.
ps. Would you prefer I correspond to you directly or continue to post issues that are really questions? Also I just checked out the Jupiter Support in the vscode python package from Microsoft. It’s a very nice implementation. I will be trying jupyter-ros with it and see how it goes.
Pito Salas
Brandeis Computer Science
Volen 134
… On Jul 8, 2019, at 10:09 PM, Wolf Vollprecht ***@***.***> wrote:
As far as I know you also can't have two nodes in a single python script ... So it's not even a limitation of Jupyter, but rather of rospy that you need two python processes for two real nodes.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#27?email_source=notifications&email_token=AAAK5CMNS27HTVGO2PCAUBTP6PXMXA5CNFSM4H5BGF32YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZO3NIQ#issuecomment-509458082>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAAK5CMQLJGIAF6LFMCA6RTP6PXMXANCNFSM4H5BGF3Q>.
|
I am still trying to figure out the threading model of this approach.
The text was updated successfully, but these errors were encountered: