diff --git a/hbp_nrp_backend/requirements.txt b/hbp_nrp_backend/requirements.txt index a280870..3a75354 100644 --- a/hbp_nrp_backend/requirements.txt +++ b/hbp_nrp_backend/requirements.txt @@ -1,6 +1,6 @@ # other requirements lxml==3.4.0 -PyYAML==3.11 +PyYAML==5.1 rospkg==1.0.38 catkin_pkg==0.2.10 pyxb==1.2.4 diff --git a/hbp_nrp_cleserver/hbp_nrp_cleserver/server/CLEGazeboSimulationAssembly.py b/hbp_nrp_cleserver/hbp_nrp_cleserver/server/CLEGazeboSimulationAssembly.py index 9406908..344d59b 100644 --- a/hbp_nrp_cleserver/hbp_nrp_cleserver/server/CLEGazeboSimulationAssembly.py +++ b/hbp_nrp_cleserver/hbp_nrp_cleserver/server/CLEGazeboSimulationAssembly.py @@ -419,7 +419,7 @@ def __load_tfs(self): continue try: - tfm.set_transfer_function(tf.code, new_code, tf.name, tf.active) + tfm.set_transfer_function(tf.code, new_code, tf.name, tf.active, tf.priority) except tfm.TFLoadingException as loading_e: logger.error(loading_e) tfm.set_flawed_transfer_function(tf.code, tf.name, loading_e) diff --git a/hbp_nrp_commons/hbp_nrp_commons/sim_config/SimConfig.py b/hbp_nrp_commons/hbp_nrp_commons/sim_config/SimConfig.py index 794aa6b..bd72c82 100644 --- a/hbp_nrp_commons/hbp_nrp_commons/sim_config/SimConfig.py +++ b/hbp_nrp_commons/hbp_nrp_commons/sim_config/SimConfig.py @@ -119,18 +119,25 @@ class _TF(object): # pragma: no cover """ Model to store TF information """ - def __init__(self, name, code, src=None, active=False): + def __init__(self, name, code, src=None, active=False, priority=0): """ Initialize a transfer function object :param name: name of the transfer function :param code: compiled (restricted) source code of transfer function :param src: source code (plain text) of transfer function + :param active: active state of the transfer function + :param priority: specifies execution order of the transfer function. Transfer functions with + higher priority are executed first. """ self.name = name self.code = code self.src = src self.active = active + try: + self.priority = int(priority) + except (ValueError, TypeError): + self.priority = 0 class SimConfig(object): @@ -331,8 +338,9 @@ def _read_dom_data(self): code = generate_tf(_tf, self.sim_dir) name = get_tf_name(code) src = _tf.src if _tf.src else None # must be not None and not "" + priority = _tf.priority if _tf.priority else 0 active = bool(_tf.active) if _tf.active else False - self._tfs.append(_TF(name, code, src, active)) + self._tfs.append(_TF(name, code, src, active, priority)) def _read_robot_models(self): """ diff --git a/hbp_nrp_commons/hbp_nrp_commons/tests/sim_config/test_SimConfig.py b/hbp_nrp_commons/hbp_nrp_commons/tests/sim_config/test_SimConfig.py index 9d32ed0..a2cc604 100644 --- a/hbp_nrp_commons/hbp_nrp_commons/tests/sim_config/test_SimConfig.py +++ b/hbp_nrp_commons/hbp_nrp_commons/tests/sim_config/test_SimConfig.py @@ -30,7 +30,7 @@ from mock import patch, Mock, MagicMock, ANY, mock_open from hbp_nrp_commons.MockUtil import MockUtil -from hbp_nrp_commons.sim_config.SimConfig import SimConfig +from hbp_nrp_commons.sim_config.SimConfig import SimConfig, _TF __author__ = 'Hossain Mahmud' @@ -116,6 +116,19 @@ def test_read_data(self): def test_properties(self): pass + def test_priority_is_int(self): + # test _TF priority value is always initialized to an integer + tf_1 = _TF("dummy_name", "dummy_code",priority=None) + tf_2 = _TF("dummy_name", "dummy_code", priority="string_value") + tf_3 = _TF("dummy_name", "dummy_code", priority=False) + tf_4 = _TF("dummy_name", "dummy_code", priority=3.1416) + + self.assertTrue(type(tf_1.priority) == int) + self.assertTrue(type(tf_2.priority) == int) + self.assertTrue(type(tf_3.priority) == int) + self.assertTrue(type(tf_4.priority) == int) + + if __name__ == '__main__': unittest.main()