From ff5c8b310f865478d68495febbbcea39934bd46d Mon Sep 17 00:00:00 2001 From: MARIANOCEREDA Date: Thu, 27 Jun 2024 14:56:03 -0300 Subject: [PATCH 1/5] update to make vda5050 version set from parameter --- .../vda5050_connector_py/mqtt_bridge.py | 24 +++++++++++++++++-- .../vda5050_connector_py/utils.py | 3 ++- .../vda5050_controller.py | 1 + 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/vda5050_connector/vda5050_connector_py/mqtt_bridge.py b/vda5050_connector/vda5050_connector_py/mqtt_bridge.py index 21eebf1..e3c860a 100755 --- a/vda5050_connector/vda5050_connector_py/mqtt_bridge.py +++ b/vda5050_connector/vda5050_connector_py/mqtt_bridge.py @@ -49,7 +49,7 @@ from vda5050_connector_py.utils import convert_ros_message_to_json from vda5050_connector_py.utils import get_vda5050_ts -from vda5050_connector_py.vda5050_controller import DEFAULT_PROTOCOL_VERSION +from vda5050_connector_py.vda5050_controller import DEFAULT_PROTOCOL_VERSION, SUPPORTED_PROTOCOL_VERSIONS # ROS msgs / srvs / actions from vda5050_msgs.msg import Action as VDAAction @@ -194,6 +194,15 @@ def generate_vda_instant_action_msg(instant_action): return vda_instant_action +def generate_vda5050_topic_alias(vda_version): + if vda_version in SUPPORTED_PROTOCOL_VERSIONS: + return f"v{vda_version[0]}" + else: + raise ValueError( + f"Invalid protocol major version. Supported versions are: {SUPPORTED_PROTOCOL_VERSIONS}" + f" preceded by 'v', but got {vda_version}" + ) + class MQTTBridge(Node): """Translates VDA5050 MQTT messages from and to ROS2.""" @@ -208,6 +217,9 @@ def __init__(self): mqtt_port = read_int_parameter(self, "mqtt_port", 1883) mqtt_username = read_str_parameter(self, "mqtt_username", "") mqtt_password = read_str_parameter(self, "mqtt_password", "") + + self.vda5050_version = read_str_parameter(self, "vda5050_protocol_version", "2.0.0") + self.vda5050_version_alias = generate_vda5050_topic_alias(self.vda5050_version) self._manufacturer_name = read_str_parameter( self, "manufacturer_name", "robots" @@ -238,6 +250,7 @@ def __init__(self): manufacturer=self._manufacturer_name, serial_number=self._serial_number, topic="connection", + major_version=self.vda5050_version_alias, ) # NOTE: will payload cannot be set dynamically or updated @@ -278,6 +291,7 @@ def on_connect_mqtt(self, client, userdata, flags, rc): manufacturer=self._manufacturer_name, serial_number=self._serial_number, topic="order", + major_version=self.vda5050_version_alias, ) ) self.mqtt_client.subscribe( @@ -285,12 +299,13 @@ def on_connect_mqtt(self, client, userdata, flags, rc): manufacturer=self._manufacturer_name, serial_number=self._serial_number, topic="instantActions", + major_version=self.vda5050_version_alias ) ) self._publish_connection( msg=VDAConnection( header_id=0, - version=DEFAULT_PROTOCOL_VERSION, + version=self.vda5050_version, timestamp=get_vda5050_ts(), manufacturer=self._manufacturer_name, serial_number=self._serial_number, @@ -424,6 +439,7 @@ def on_shutdown(self): manufacturer=self._manufacturer_name, serial_number=self._serial_number, topic="order", + major_version=self.vda5050_version_alias ) ) self.mqtt_client.unsubscribe( @@ -431,6 +447,7 @@ def on_shutdown(self): manufacturer=self._manufacturer_name, serial_number=self._serial_number, topic="instantActions", + major_version=self.vda5050_version_alias ) ) @@ -463,6 +480,7 @@ def _publish_state(self, msg: VDAOrderState): manufacturer=self._manufacturer_name, serial_number=self._serial_number, topic="state", + major_version=self.vda5050_version_alias ) self._publish_to_topic(msg, topic) @@ -485,6 +503,7 @@ def _publish_connection(self, msg: VDAConnection): manufacturer=self._manufacturer_name, serial_number=self._serial_number, topic="connection", + major_version=self.vda5050_version_alias ) self._publish_to_topic(msg, topic) @@ -501,5 +520,6 @@ def _publish_visualization(self, msg: VDAVisualization): manufacturer=self._manufacturer_name, serial_number=self._serial_number, topic="visualization", + major_version=self.vda5050_version_alias ) self._publish_to_topic(msg, topic) diff --git a/vda5050_connector/vda5050_connector_py/utils.py b/vda5050_connector/vda5050_connector_py/utils.py index e1611e6..817b7ce 100644 --- a/vda5050_connector/vda5050_connector_py/utils.py +++ b/vda5050_connector/vda5050_connector_py/utils.py @@ -221,7 +221,7 @@ def convert_ros_message_to_json(msg): def get_vda5050_mqtt_topic( - manufacturer, serial_number, topic, interface_name="uagv", major_version="v1" + manufacturer, serial_number, topic, major_version, interface_name="uagv", ): """ Return suggested VDA5050 MQTT topics. @@ -256,6 +256,7 @@ def get_vda5050_mqtt_topic( string: MQTT topic """ + if topic not in [ "order", "state", diff --git a/vda5050_connector/vda5050_connector_py/vda5050_controller.py b/vda5050_connector/vda5050_connector_py/vda5050_controller.py index 16424b4..b1ec729 100755 --- a/vda5050_connector/vda5050_connector_py/vda5050_controller.py +++ b/vda5050_connector/vda5050_connector_py/vda5050_controller.py @@ -95,6 +95,7 @@ DEFAULT_SERIAL_NUMBER = "robot_1" DEFAULT_PROTOCOL_VERSION = "2.0.0" DEFAULT_STARTING_NODE_ID = "" +SUPPORTED_PROTOCOL_VERSIONS = ["1.1.0", "2.0.0"] DEFAULT_GET_STATE_SVC_NAME = "adapter/get_state" DEFAULT_SUPPORTED_ACTIONS_SVC_NAME = "adapter/supported_actions" From d472f123c41f7b709e17ec6dc99d8c54b375b5eb Mon Sep 17 00:00:00 2001 From: MARIANOCEREDA Date: Thu, 27 Jun 2024 14:57:30 -0300 Subject: [PATCH 2/5] typo --- vda5050_connector/vda5050_connector_py/mqtt_bridge.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vda5050_connector/vda5050_connector_py/mqtt_bridge.py b/vda5050_connector/vda5050_connector_py/mqtt_bridge.py index e3c860a..e4625e1 100755 --- a/vda5050_connector/vda5050_connector_py/mqtt_bridge.py +++ b/vda5050_connector/vda5050_connector_py/mqtt_bridge.py @@ -200,7 +200,7 @@ def generate_vda5050_topic_alias(vda_version): else: raise ValueError( f"Invalid protocol major version. Supported versions are: {SUPPORTED_PROTOCOL_VERSIONS}" - f" preceded by 'v', but got {vda_version}" + f"But got {vda_version}" ) class MQTTBridge(Node): From 52586aefeb3247ab9024ae03f6adc23f635844e0 Mon Sep 17 00:00:00 2001 From: MARIANOCEREDA Date: Thu, 27 Jun 2024 15:02:33 -0300 Subject: [PATCH 3/5] add function description --- .../vda5050_connector_py/mqtt_bridge.py | 21 +++++++++++++++++-- .../vda5050_connector_py/utils.py | 1 - 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/vda5050_connector/vda5050_connector_py/mqtt_bridge.py b/vda5050_connector/vda5050_connector_py/mqtt_bridge.py index e4625e1..f95e8bd 100755 --- a/vda5050_connector/vda5050_connector_py/mqtt_bridge.py +++ b/vda5050_connector/vda5050_connector_py/mqtt_bridge.py @@ -195,12 +195,29 @@ def generate_vda_instant_action_msg(instant_action): def generate_vda5050_topic_alias(vda_version): + """ + Create an alias for the current vda5050 version. The aliases are needed to + create the mqtt topics. + + Args: + ---- + vda_version (string): VDA5050 version with format x.x.x. + + Raises: + ------ + ValueError if the alias is not within the supported values. + + Returns + ------- + The alias of the version. For example, for the version '2.0.0', the alias is + 'v2' + """ if vda_version in SUPPORTED_PROTOCOL_VERSIONS: return f"v{vda_version[0]}" else: raise ValueError( - f"Invalid protocol major version. Supported versions are: {SUPPORTED_PROTOCOL_VERSIONS}" - f"But got {vda_version}" + f"Invalid protocol major version. Supported versions are: {SUPPORTED_PROTOCOL_VERSIONS}," + f"but got {vda_version}" ) class MQTTBridge(Node): diff --git a/vda5050_connector/vda5050_connector_py/utils.py b/vda5050_connector/vda5050_connector_py/utils.py index 817b7ce..430643c 100644 --- a/vda5050_connector/vda5050_connector_py/utils.py +++ b/vda5050_connector/vda5050_connector_py/utils.py @@ -256,7 +256,6 @@ def get_vda5050_mqtt_topic( string: MQTT topic """ - if topic not in [ "order", "state", From 074ffe56a2d045a3762378743f8f31c88adef6b5 Mon Sep 17 00:00:00 2001 From: MARIANOCEREDA Date: Thu, 27 Jun 2024 15:04:44 -0300 Subject: [PATCH 4/5] add missing versions --- vda5050_connector/vda5050_connector_py/mqtt_bridge.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vda5050_connector/vda5050_connector_py/mqtt_bridge.py b/vda5050_connector/vda5050_connector_py/mqtt_bridge.py index f95e8bd..2bbe061 100755 --- a/vda5050_connector/vda5050_connector_py/mqtt_bridge.py +++ b/vda5050_connector/vda5050_connector_py/mqtt_bridge.py @@ -277,7 +277,7 @@ def __init__(self): will_payload = convert_ros_message_to_json( VDAConnection( header_id=0, - version=DEFAULT_PROTOCOL_VERSION, + version=self.vda5050_version, timestamp="1970-01-01T12:00:00.00Z", manufacturer=self._manufacturer_name, serial_number=self._serial_number, @@ -437,7 +437,7 @@ def on_shutdown(self): offline_message = VDAConnection( header_id=0, - version=DEFAULT_PROTOCOL_VERSION, + version=self.vda5050_version, timestamp=get_vda5050_ts(), manufacturer=self._manufacturer_name, serial_number=self._serial_number, From 4c4eaff13b2c20050530b7316027d37872edd989 Mon Sep 17 00:00:00 2001 From: MARIANOCEREDA Date: Thu, 27 Jun 2024 15:18:02 -0300 Subject: [PATCH 5/5] apply pre-commit --- vda5050_connector/vda5050_connector_py/mqtt_bridge.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vda5050_connector/vda5050_connector_py/mqtt_bridge.py b/vda5050_connector/vda5050_connector_py/mqtt_bridge.py index 2bbe061..949780c 100755 --- a/vda5050_connector/vda5050_connector_py/mqtt_bridge.py +++ b/vda5050_connector/vda5050_connector_py/mqtt_bridge.py @@ -196,13 +196,13 @@ def generate_vda_instant_action_msg(instant_action): def generate_vda5050_topic_alias(vda_version): """ - Create an alias for the current vda5050 version. The aliases are needed to + Create an alias for the current vda5050 version. The aliases are needed to create the mqtt topics. Args: ---- vda_version (string): VDA5050 version with format x.x.x. - + Raises: ------ ValueError if the alias is not within the supported values. @@ -234,7 +234,7 @@ def __init__(self): mqtt_port = read_int_parameter(self, "mqtt_port", 1883) mqtt_username = read_str_parameter(self, "mqtt_username", "") mqtt_password = read_str_parameter(self, "mqtt_password", "") - + self.vda5050_version = read_str_parameter(self, "vda5050_protocol_version", "2.0.0") self.vda5050_version_alias = generate_vda5050_topic_alias(self.vda5050_version)