From 2669f5a00d2c06c067e98962098098f9e0cc56ca Mon Sep 17 00:00:00 2001 From: Alexis Paques Date: Fri, 2 Aug 2024 10:20:02 +0200 Subject: [PATCH] Change max_rate_hz to a float & set 0Hz as disabled. Change max_rate_hz to a float. Set 0Hz as a disabled topic. --- src/modules/uxrce_dds_client/dds_topics.h.em | 4 ++-- src/modules/uxrce_dds_client/dds_topics.yaml | 4 ++-- .../uxrce_dds_client/generate_dds_topics.py | 14 ++++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/modules/uxrce_dds_client/dds_topics.h.em b/src/modules/uxrce_dds_client/dds_topics.h.em index 31add7ca1a55..c7693c22e795 100644 --- a/src/modules/uxrce_dds_client/dds_topics.h.em +++ b/src/modules/uxrce_dds_client/dds_topics.h.em @@ -44,7 +44,7 @@ struct SendSubscription { const char* topic; uint32_t topic_size; UcdrSerializeMethod ucdr_serialize_method; - uint16_t max_rate_hz; + float max_rate_hz; }; // Subscribers for messages to send @@ -75,7 +75,7 @@ void SendTopicsSubs::init() { for (unsigned idx = 0; idx < sizeof(send_subscriptions)/sizeof(send_subscriptions[0]); ++idx) { fds[idx].fd = orb_subscribe(send_subscriptions[idx].orb_meta); fds[idx].events = POLLIN; - orb_set_interval(fds[idx].fd, send_subscriptions[idx].max_rate_hz ? 1000 / send_subscriptions[idx].max_rate_hz : 0); + orb_set_interval(fds[idx].fd, send_subscriptions[idx].max_rate_hz > 0 ? 1000 / send_subscriptions[idx].max_rate_hz : 10000); } } diff --git a/src/modules/uxrce_dds_client/dds_topics.yaml b/src/modules/uxrce_dds_client/dds_topics.yaml index c53b6a452a6d..479b0802849a 100644 --- a/src/modules/uxrce_dds_client/dds_topics.yaml +++ b/src/modules/uxrce_dds_client/dds_topics.yaml @@ -3,7 +3,7 @@ # This file maps all the topics that are to be used on the uXRCE-DDS client. # ##### -default_max_rate_hz: 100 +default_max_rate_hz: 100.0 publications: @@ -39,7 +39,7 @@ publications: - topic: /fmu/out/sensor_combined type: px4_msgs::msg::SensorCombined - max_rate_hz: 1000 + max_rate_hz: 1000.0 - topic: /fmu/out/timesync_status type: px4_msgs::msg::TimesyncStatus diff --git a/src/modules/uxrce_dds_client/generate_dds_topics.py b/src/modules/uxrce_dds_client/generate_dds_topics.py index 70c770f5d968..b8826b72ca4d 100644 --- a/src/modules/uxrce_dds_client/generate_dds_topics.py +++ b/src/modules/uxrce_dds_client/generate_dds_topics.py @@ -85,10 +85,10 @@ merged_em_globals = {} all_type_includes = [] -if "default_max_rate_hz" not in msg_map: - msg_map["default_max_rate_hz"] = 100 +if 'default_max_rate_hz' not in msg_map: + msg_map['default_max_rate_hz'] = 100.0 else: - msg_map["default_max_rate_hz"] = int(msg_map["default_max_rate_hz"]) + msg_map['default_max_rate_hz'] = int(msg_map['default_max_rate_hz']) def process_message_type(msg_type): # eg TrajectoryWaypoint from px4_msgs::msg::TrajectoryWaypoint @@ -103,16 +103,18 @@ def process_message_type(msg_type): msg_type['dds_type'] = msg_type['type'].replace("::msg::", "::msg::dds_::") + "_" # topic_simple: eg vehicle_status msg_type['topic_simple'] = msg_type['topic'].split('/')[-1] - if "max_rate_hz" not in msg_type: - msg_type["max_rate_hz"] = msg_map["default_max_rate_hz"] + if 'max_rate_hz' not in msg_type: + msg_type['max_rate_hz'] = msg_map['default_max_rate_hz'] else: - msg_type["max_rate_hz"] = int(msg_type["max_rate_hz"]) + msg_type['max_rate_hz'] = float(msg_type['max_rate_hz']) pubs_not_empty = msg_map['publications'] is not None if pubs_not_empty: for p in msg_map['publications']: process_message_type(p) +# Remove disabled publications +msg_map['publications'] = list(filter(lambda x: x['max_rate_hz'] > 0, msg_map['publications'])) merged_em_globals['publications'] = msg_map['publications'] if pubs_not_empty else [] subs_not_empty = msg_map['subscriptions'] is not None