Skip to content

Commit

Permalink
Change max_rate_hz to a float & set 0Hz as disabled.
Browse files Browse the repository at this point in the history
Change max_rate_hz to a float.
Set 0Hz as a disabled topic.
  • Loading branch information
AlexisTM committed Sep 24, 2024
1 parent 8e92e06 commit d63fa78
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/modules/uxrce_dds_client/dds_topics.h.em
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/modules/uxrce_dds_client/dds_topics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions src/modules/uxrce_dds_client/generate_dds_topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d63fa78

Please sign in to comment.