forked from tier4/nebula
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove MtQueue, add debug publishers for decode latency
Signed-off-by: Max SCHMELLER <[email protected]>
- Loading branch information
Showing
28 changed files
with
393 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2024 TIER IV, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include "nebula_ros/common/debug_publisher.hpp" | ||
|
||
#include <tier4_debug_msgs/msg/int64_stamped.hpp> | ||
|
||
#include <chrono> | ||
#include <cstdint> | ||
#include <map> | ||
#include <string> | ||
namespace nebula::ros | ||
{ | ||
|
||
class Counter | ||
{ | ||
public: | ||
using clock = std::chrono::steady_clock; | ||
|
||
explicit Counter(rclcpp::Node * node) : debug_pub_(node, node->get_fully_qualified_name()) {} | ||
|
||
void contribute(const std::string & key, clock::duration duration) | ||
{ | ||
measurements_.try_emplace(key, 0); | ||
measurements_[key] += duration; | ||
} | ||
|
||
bool try_publish(const std::string & key) | ||
{ | ||
if (measurements_.find(key) == measurements_.end()) { | ||
return false; | ||
} | ||
|
||
debug_pub_.publish<tier4_debug_msgs::msg::Int64Stamped>(key, measurements_[key].count()); | ||
measurements_.erase(key); | ||
return true; | ||
} | ||
|
||
void publish_all() | ||
{ | ||
for (const auto & [key, value] : measurements_) { | ||
debug_pub_.publish<tier4_debug_msgs::msg::Int64Stamped>(key, value.count()); | ||
} | ||
measurements_.clear(); | ||
} | ||
|
||
private: | ||
autoware::universe_utils::DebugPublisher debug_pub_; | ||
std::map<std::string, clock::duration> measurements_; | ||
}; | ||
|
||
} // namespace nebula::ros |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2020 Tier IV, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef AUTOWARE__UNIVERSE_UTILS__ROS__DEBUG_PUBLISHER_HPP_ | ||
#define AUTOWARE__UNIVERSE_UTILS__ROS__DEBUG_PUBLISHER_HPP_ | ||
|
||
#include <rclcpp/publisher_base.hpp> | ||
#include <rclcpp/rclcpp.hpp> | ||
#include <rosidl_runtime_cpp/traits.hpp> | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <unordered_map> | ||
|
||
namespace autoware::universe_utils | ||
{ | ||
namespace debug_publisher | ||
{ | ||
template <class T_msg, class T> | ||
T_msg to_debug_msg(const T & data, const rclcpp::Time & stamp) | ||
{ | ||
T_msg msg; | ||
msg.stamp = stamp; | ||
msg.data = data; | ||
return msg; | ||
} | ||
} // namespace debug_publisher | ||
|
||
class DebugPublisher | ||
{ | ||
public: | ||
explicit DebugPublisher(rclcpp::Node * node, const char * ns) : node_(node), ns_(ns) {} | ||
|
||
template <class T> | ||
void publish(const std::string & name, const T & data, const rclcpp::QoS & qos = rclcpp::QoS(1)) | ||
{ | ||
if (pub_map_.count(name) == 0) { | ||
pub_map_[name] = node_->create_publisher<T>(std::string(ns_) + "/" + name, qos); | ||
} | ||
|
||
std::dynamic_pointer_cast<rclcpp::Publisher<T>>(pub_map_.at(name))->publish(data); | ||
} | ||
|
||
template <class T_msg, class T> | ||
void publish(const std::string & name, const T & data, const rclcpp::QoS & qos = rclcpp::QoS(1)) | ||
{ | ||
publish(name, debug_publisher::to_debug_msg<T_msg>(data, node_->now()), qos); | ||
} | ||
|
||
private: | ||
rclcpp::Node * node_; | ||
const char * ns_; | ||
std::unordered_map<std::string, std::shared_ptr<rclcpp::PublisherBase>> pub_map_; | ||
}; | ||
} // namespace autoware::universe_utils | ||
|
||
#endif // AUTOWARE__UNIVERSE_UTILS__ROS__DEBUG_PUBLISHER_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.