Skip to content

Commit a780d4f

Browse files
committed
move G graph to generic, use DataConfig to DSR params and period and erase setParams
1 parent 0fd48cc commit a780d4f

6 files changed

Lines changed: 70 additions & 24 deletions

File tree

cli/robocompdsl/robocompdsl/templates/templateCPP/plugins/dsr/functions/etc/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66

77
DSR_CONFIG_STR = """\
8-
Agent.id = 0 # Change id
8+
# Change id
9+
Agent.id = 0
910
Agent.name = "${name}"
1011
Agent.configFile = ""
1112
"""

cli/robocompdsl/robocompdsl/templates/templatePython/files/generated/genericworker.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import sys, Ice, os
2222
from PySide6 import QtWidgets, QtCore
23+
${import_dsr}
24+
2325

2426
${ui_import}
2527

@@ -38,7 +40,7 @@ def __init__(self, mprx, configData):
3840

3941
self.Period = 30
4042
self.timer = QtCore.QTimer(self)
41-
43+
${insert_dsr}
4244

4345
@QtCore.Slot()
4446
def killYourSelf(self):

cli/robocompdsl/robocompdsl/templates/templatePython/files/generated/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def sigint_handler(*args):
9696

9797
if interface_manager.status == 0:
9898
worker = SpecificWorker(interface_manager.get_proxies_map(), configData, args.startup_check)
99-
worker.setParams(configData)
99+
if hasattr(worker, "setParams"): worker.setParams(configData)
100100
else:
101101
print("Error getting required connections, check config file")
102102
sys.exit(-1)

cli/robocompdsl/robocompdsl/templates/templatePython/files/src/specificworker.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,10 @@
3030

3131
${dsr_import}
3232

33-
# If RoboComp was compiled with Python bindings you can use InnerModel in Python
34-
# import librobocomp_qmat
35-
# import librobocomp_osgviewer
36-
# import librobocomp_innermodel
37-
38-
3933
class SpecificWorker(GenericWorker):
4034
def __init__(self, proxy_map, configData, startup_check=False):
4135
super(SpecificWorker, self).__init__(proxy_map, configData)
42-
self.Period = 2000
36+
self.Period = configData["Period"]["Compute"]
4337
${dsr_init}
4438
if startup_check:
4539
self.startup_check()
@@ -49,14 +43,6 @@ def __init__(self, proxy_map, configData, startup_check=False):
4943
def __del__(self):
5044
"""Destructor"""
5145

52-
def setParams(self, params):
53-
# try:
54-
# self.innermodel = InnerModel(params["InnerModelPath"])
55-
# except:
56-
# traceback.print_exc()
57-
# print("Error reading config params")
58-
return True
59-
6046
${compute_creation}
6147

6248
def startup_check(self):
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import datetime
2+
3+
from robocompdsl.dsl_parsers.parsing_utils import communication_is_ice, get_name_number
4+
from robocompdsl.templates.common.templatedict import TemplateDict
5+
6+
7+
DSR_INIT_STR = """\
8+
self.agent_id = configData["Agent"]["id"]
9+
self.g = DSRGraph(0, configData["Agent"]["name"], self.agent_id, configData["Agent"]["configFile"])
10+
"""
11+
12+
13+
class src_genericworker_py(TemplateDict):
14+
def __init__(self, component):
15+
super(src_genericworker_py, self).__init__()
16+
self.component = component
17+
self['year'] = str(datetime.date.today().year)
18+
self['requires_proxies'] = self.requires_proxies()
19+
self['publishes_proxies'] = self.publishes_proxies()
20+
self['insert_dsr'] = self.insert_dsr()
21+
self['import_dsr'] = self.import_dsr()
22+
23+
24+
25+
def import_dsr(self):
26+
if self.component.dsr:
27+
return "from pydsr import DSRGraph"
28+
else:
29+
return ""
30+
31+
def insert_dsr(self):
32+
if self.component.dsr:
33+
return DSR_INIT_STR
34+
else:
35+
return ""
36+
37+
# TODO: Refactor this and publishes with a zip?
38+
def requires_proxies(self):
39+
result = ""
40+
for req, num in get_name_number(self.component.requires):
41+
if isinstance(req, str):
42+
rq = req
43+
else:
44+
rq = req[0]
45+
if communication_is_ice(req):
46+
result += "self." + rq.lower() + num + "_proxy = mprx[\"" + rq + num + "\"]\n"
47+
else:
48+
result += "self." + rq.lower() + "_proxy = ServiceClient" + rq + "()\n"
49+
return result
50+
51+
def publishes_proxies(self):
52+
result = ""
53+
for pb, num in get_name_number(self.component.publishes):
54+
if isinstance(pb, str):
55+
pub = pb
56+
else:
57+
pub = pb[0]
58+
if communication_is_ice(pb):
59+
result += "self." + pub.lower() + num + "_proxy = mprx[\"" + pub + num + "\"]\n"
60+
else:
61+
result += "self." + pub.lower() + "_proxy = Publisher" + pub + "()\n"
62+
return result

cli/robocompdsl/robocompdsl/templates/templatePython/plugins/dsr/functions/src/specificworker_py.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ def delete_edge(self, fr: int, to: int, type: str):
3636

3737
DSR_INIT_STR = """\
3838
39-
# YOU MUST SET AN UNIQUE ID FOR THIS AGENT IN YOUR DEPLOYMENT. "_CHANGE_THIS_ID_" for a valid unique integer
40-
#self.agent_id = "_CHANGE_THIS_ID_"
41-
self.agent_id = 4095
42-
self.g = DSRGraph(0, "pythonAgent", self.agent_id)
43-
4439
try:
4540
signals.connect(self.g, signals.UPDATE_NODE_ATTR, self.update_node_att)
4641
signals.connect(self.g, signals.UPDATE_NODE, self.update_node)
@@ -51,7 +46,7 @@ def delete_edge(self, fr: int, to: int, type: str):
5146
console.print("signals connected")
5247
except RuntimeError as e:
5348
print(e)
54-
49+
5550
"""
5651

5752
class src_specificworker_py(TemplateDict):

0 commit comments

Comments
 (0)