Skip to content

Commit 214f2df

Browse files
committed
add context managerless ros example
1 parent 56bde5f commit 214f2df

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

docs/examples/03_backends_ros/01_ros_examples.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,20 @@ see the output ``Connected: True`` if everything is working properly:
2424
2525
from compas_fab.backends import RosClient
2626
with RosClient() as client:
27-
print('Connected:', client.is_connected)
27+
print('Connected: ', client.is_connected)
2828
2929
*Yay! Our first connection to ROS!*
3030

31+
If you prefer to work without a context manager, the equivalent code is:
32+
33+
.. code-block:: python
34+
35+
from compas_fab.backends import RosClient
36+
client = RosClient()
37+
client.run()
38+
print('Connected: ', client.is_connected)
39+
client.close()
40+
3141
.. note::
3242

3343
``RosClient`` also supports using *callbacks* instead of blocking calls.

src/compas_fab/backends/ros/client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ def __init__(self, host='localhost', port=9090, is_secure=False, planner_backend
145145

146146
def __enter__(self):
147147
self.run()
148-
self.connect()
149148

150149
return self
151150

0 commit comments

Comments
 (0)