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

Support publishing client message as loaned message #314

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Parameters are provided to configure the behavior of the bridge. These parameter
* (ROS 2) __min_qos_depth__: Minimum depth used for the QoS profile of subscriptions. Defaults to `1`. This is to set a lower limit for a subscriber's QoS depth which is computed by summing up depths of all publishers. See also [#208](https://github.com/foxglove/ros-foxglove-bridge/issues/208).
* (ROS 2) __max_qos_depth__: Maximum depth used for the QoS profile of subscriptions. Defaults to `25`.
* (ROS 2) __include_hidden__: Include hidden topics and services. Defaults to `false`.
* (ROS 2) __disable_load_message__: Do not publish as loaned message when publishing a client message. Defaults to `false`.
achim-k marked this conversation as resolved.
Show resolved Hide resolved

## Building from source

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ constexpr char PARAM_USE_COMPRESSION[] = "use_compression";
constexpr char PARAM_CAPABILITIES[] = "capabilities";
constexpr char PARAM_CLIENT_TOPIC_WHITELIST[] = "client_topic_whitelist";
constexpr char PARAM_INCLUDE_HIDDEN[] = "include_hidden";
constexpr char PARAM_DISABLE_LOAN_MESSAGE[] = "disable_load_message";
constexpr char PARAM_ASSET_URI_ALLOWLIST[] = "asset_uri_allowlist";

constexpr int64_t DEFAULT_PORT = 8765;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class FoxgloveBridge : public rclcpp::Node {
std::vector<std::string> _capabilities;
std::atomic<bool> _subscribeGraphUpdates = false;
bool _includeHidden = false;
bool _disableLoanMessage = false;
achim-k marked this conversation as resolved.
Show resolved Hide resolved
std::unique_ptr<foxglove::CallbackQueue> _fetchAssetQueue;
std::atomic<bool> _shuttingDown = false;

Expand Down
8 changes: 8 additions & 0 deletions ros2_foxglove_bridge/src/param_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ void declareParameters(rclcpp::Node* node) {
includeHiddenDescription.read_only = true;
node->declare_parameter(PARAM_INCLUDE_HIDDEN, false, includeHiddenDescription);

auto disableLoanMessageDescription = rcl_interfaces::msg::ParameterDescriptor{};
disableLoanMessageDescription.name = PARAM_DISABLE_LOAN_MESSAGE;
disableLoanMessageDescription.type = rcl_interfaces::msg::ParameterType::PARAMETER_BOOL;
disableLoanMessageDescription.description =
"Do not publish as loaned message when publishing a client message";
disableLoanMessageDescription.read_only = true;
node->declare_parameter(PARAM_DISABLE_LOAN_MESSAGE, false, disableLoanMessageDescription);
achim-k marked this conversation as resolved.
Show resolved Hide resolved

auto assetUriAllowlistDescription = rcl_interfaces::msg::ParameterDescriptor{};
assetUriAllowlistDescription.name = PARAM_ASSET_URI_ALLOWLIST;
assetUriAllowlistDescription.type = rcl_interfaces::msg::ParameterType::PARAMETER_STRING_ARRAY;
Expand Down
7 changes: 6 additions & 1 deletion ros2_foxglove_bridge/src/ros2_foxglove_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ FoxgloveBridge::FoxgloveBridge(const rclcpp::NodeOptions& options)
_includeHidden = this->get_parameter(PARAM_INCLUDE_HIDDEN).as_bool();
const auto assetUriAllowlist = this->get_parameter(PARAM_ASSET_URI_ALLOWLIST).as_string_array();
_assetUriAllowlistPatterns = parseRegexStrings(this, assetUriAllowlist);
_disableLoanMessage = this->get_parameter(PARAM_DISABLE_LOAN_MESSAGE).as_bool();

const auto logHandler = std::bind(&FoxgloveBridge::logHandler, this, _1, _2);
// Fetching of assets may be blocking, hence we fetch them in a separate thread.
Expand Down Expand Up @@ -710,7 +711,11 @@ void FoxgloveBridge::clientMessage(const foxglove::ClientMessage& message, Conne
rclSerializedMsg.buffer_length = message.getLength();

// Publish the message
publisher->publish(serializedMessage);
if (_disableLoanMessage || !publisher->can_loan_messages()) {
publisher->publish(serializedMessage);
} else {
publisher->publish_as_loaned_msg(serializedMessage);
}
}

void FoxgloveBridge::setParameters(const std::vector<foxglove::Parameter>& parameters,
Expand Down
Loading