Skip to content

Commit 1965de9

Browse files
committed
Update notebook
1 parent 0c07bf5 commit 1965de9

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

files/RosLibJs.ipynb

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"- **ROSLIBJS_DISABLE**: Local comunication isolated to this webinstance, this is the default mode of operation.\n",
1919
"- **ROSLIBJS_ENABLE**: This mode will use the ROSLIBJS library to communicate with a native ROS2 node, this is enabled by setting ROSLIBJS_ENABLE to be \"1\"\n",
2020
"\n",
21-
"For instruction to set up your local ros2 node please read SettingUpNativeNode.ipynb\n"
21+
"For instruction to set up your local ros2 node using native ros2 please read SettingUpNativeNode.ipynb or if using robostack please refer to: https://github.com/ros2wasm/roslibjs_demo \n"
2222
]
2323
},
2424
{
@@ -153,12 +153,34 @@
153153
"asyncio.create_task(stopper())"
154154
]
155155
},
156+
{
157+
"cell_type": "markdown",
158+
"metadata": {},
159+
"source": [
160+
"# Subscribe to native node\n",
161+
"\n",
162+
"If you have roslibjs enabled and follow the instructions to set up a native node, you can run the following code to subscribe to the native node. This will create a subscriber that will listen to the topic /topic \n",
163+
"being published by the minimal publisher ros2 example.\n"
164+
]
165+
},
156166
{
157167
"cell_type": "code",
158168
"execution_count": null,
159169
"metadata": {},
160170
"outputs": [],
161-
"source": []
171+
"source": [
172+
"running = True\n",
173+
"sub_native = MinimalSubscriber('minimal_subscriber_native_node', ['topic'])\n",
174+
"print(\"subscribe for 10 seconds to a native ros2 node\")\n",
175+
"asyncio.create_task(spin_subscriber(sub_native))\n",
176+
"async def stopper():\n",
177+
" global running\n",
178+
" await asyncio.sleep(5)\n",
179+
" print(\"Stopping all tasks\")\n",
180+
" running = False\n",
181+
"\n",
182+
"asyncio.create_task(stopper())\n"
183+
]
162184
}
163185
],
164186
"metadata": {

0 commit comments

Comments
 (0)