Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uXRCE - Allow to set the uORB polling rate per subscription #23473

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/modules/uxrce_dds_client/dds_topics.h.em
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import os
#include <uORB/topics/@(include).h>
@[end for]@

#define UXRCE_DEFAULT_POLL_RATE 10

typedef bool (*UcdrSerializeMethod)(const void* data, ucdrBuffer& buf, int64_t time_offset);

static constexpr int max_topic_size = 512;
Expand All @@ -46,6 +44,7 @@ struct SendSubscription {
const char* topic;
uint32_t topic_size;
UcdrSerializeMethod ucdr_serialize_method;
float max_rate_hz;
};

// Subscribers for messages to send
Expand All @@ -58,6 +57,7 @@ struct SendTopicsSubs {
"@(pub['topic'])",
ucdr_topic_size_@(pub['simple_base_type'])(),
&ucdr_serialize_@(pub['simple_base_type']),
@(pub['max_rate_hz']),
},
@[ end for]@
};
Expand All @@ -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, UXRCE_DEFAULT_POLL_RATE);
orb_set_interval(fds[idx].fd, send_subscriptions[idx].max_rate_hz > 0 ? 1000 / send_subscriptions[idx].max_rate_hz : 100);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/modules/uxrce_dds_client/dds_topics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# This file maps all the topics that are to be used on the uXRCE-DDS client.
#
#####
default_max_rate_hz: 100.0

publications:

- topic: /fmu/out/register_ext_component_reply
Expand Down Expand Up @@ -37,6 +39,7 @@ publications:

- topic: /fmu/out/sensor_combined
type: px4_msgs::msg::SensorCombined
max_rate_hz: 1000.0

- topic: /fmu/out/timesync_status
type: px4_msgs::msg::TimesyncStatus
Expand Down
11 changes: 11 additions & 0 deletions src/modules/uxrce_dds_client/generate_dds_topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
merged_em_globals = {}
all_type_includes = []

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'])

def process_message_type(msg_type):
# eg TrajectoryWaypoint from px4_msgs::msg::TrajectoryWaypoint
simple_base_type = msg_type['type'].split('::')[-1]
Expand All @@ -98,12 +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']
else:
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
Loading