Skip to content

Commit ce31d0a

Browse files
authored
Merge pull request #120 from dobots/master
Fixes For Ros2 Publisher
2 parents 2be3189 + 366d384 commit ce31d0a

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

jupyros/ros2/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#from ..ros1.server_extension import *
1414
#from ..ros1.turtle_sim import *
1515

16-
from ..ros2.publisher import *
1716
from ..ros2.ros_widgets import *
17+
from ..ros2.publisher import *
18+
1819
from ..ros2.subscriber import *

jupyros/ros2/publisher.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
Date: 19 July 2022
88
99
"""
10-
1110
from typing import TypeVar
1211
import threading
1312
import time
1413
import ipywidgets as widgets
15-
from .ros_widgets import add_widgets
14+
from . import add_widgets
1615
import functools
1716

1817
def rsetattr(obj, attr, val):
@@ -92,15 +91,14 @@ def __init__(self, node: Node, msg_type: MsgType, topic: str) -> None:
9291
def widget_dict_to_msg(self):
9392

9493
"""
95-
Iterate over the attributes and give them per attribute
94+
Iterate over the widget data and assign them per attribute
9695
9796
9897
"""
9998
for key in self.__widget_list:
10099
if(key.has_trait('children')):
101100
try:
102101
attr_adress = ".".join([head_class, str(key.children[0].value)])
103-
print(attr_adress)
104102
#rsetattr(bun,attr_adress, 0.0)
105103
rsetattr(self.msg_inst, attr_adress, float(key.children[1].value))
106104
except:
@@ -153,7 +151,10 @@ def __thread_target(self) -> None:
153151
time.sleep(d)
154152

155153
def __start_thread(self, _) -> None:
156-
self.__thread_map[self.topic] = not self.__thread_map[self.topic]
154+
try:
155+
self.__thread_map[self.topic] = not self.__thread_map[self.topic]
156+
except:
157+
self.__thread_map[self.topic] = self.node
157158
if self.__thread_map[self.topic]:
158159
local_thread = threading.Thread(target=self.__thread_target)
159160
local_thread.start()

notebooks/Ros2 Pub_Sub_Communication.ipynb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@
99
"name": "stdout",
1010
"output_type": "stream",
1111
"text": [
12-
"The actionlib package is not found in your $PYTHONPATH. Action clients are not going to work.\n",
13-
"Do you need to activate your ROS environment?\n",
14-
"The rospy package is not found in your $PYTHONPATH. Subscribe and publish are not going to work.\n",
15-
"Do you need to activate your ROS environment?\n",
16-
"The actionlib package is not found in your $PYTHONPATH. Action clients are not going to work.\n",
17-
"Do you need to activate your ROS environment?\n"
12+
"ROS2 foxy environment detected.\n"
1813
]
1914
}
2015
],
@@ -71,15 +66,15 @@
7166
},
7267
{
7368
"cell_type": "code",
74-
"execution_count": 5,
69+
"execution_count": 7,
7570
"metadata": {
7671
"scrolled": true
7772
},
7873
"outputs": [
7974
{
8075
"data": {
8176
"application/vnd.jupyter.widget-view+json": {
82-
"model_id": "02f465aa904e4e65bf7e48c0681d5662",
77+
"model_id": "534c10313702477ea44c49e430481dea",
8378
"version_major": 2,
8479
"version_minor": 0
8580
},
@@ -99,13 +94,13 @@
9994
},
10095
{
10196
"cell_type": "code",
102-
"execution_count": 6,
97+
"execution_count": 8,
10398
"metadata": {},
10499
"outputs": [
105100
{
106101
"data": {
107102
"application/vnd.jupyter.widget-view+json": {
108-
"model_id": "eedb12e52bc647a3880710dcb1a5fc0d",
103+
"model_id": "744726dbc1e64f8c8a2c69ec39ad4927",
109104
"version_major": 2,
110105
"version_minor": 0
111106
},
@@ -124,13 +119,13 @@
124119
},
125120
{
126121
"cell_type": "code",
127-
"execution_count": 7,
122+
"execution_count": 9,
128123
"metadata": {},
129124
"outputs": [
130125
{
131126
"data": {
132127
"application/vnd.jupyter.widget-view+json": {
133-
"model_id": "f8055553ab1d4f8da77339b36ad3341a",
128+
"model_id": "ef44af737162481f822d1f15fbd675cf",
134129
"version_major": 2,
135130
"version_minor": 0
136131
},
@@ -147,6 +142,13 @@
147142
"pub = jr2.Publisher(test_node, Pose, '/data')\n",
148143
"pub.display()"
149144
]
145+
},
146+
{
147+
"cell_type": "code",
148+
"execution_count": null,
149+
"metadata": {},
150+
"outputs": [],
151+
"source": []
150152
}
151153
],
152154
"metadata": {

0 commit comments

Comments
 (0)