Skip to content

Commit

Permalink
style(pre-commit): autofix
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Feb 12, 2024
1 parent b59c925 commit 2c7d4e4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 106 deletions.
66 changes: 23 additions & 43 deletions common/autoware_node/include/autoware_node/autoware_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#define AUTOWARE_NODE__AUTOWARE_NODE_HPP_

#include "autoware_node/visibility_control.hpp"
#include "rclcpp/message_memory_strategy.hpp"
#include "rclcpp/subscription.hpp"
#include "rclcpp/subscription_options.hpp"
#include "rclcpp/subscription_traits.hpp"
#include "rclcpp_lifecycle/lifecycle_node.hpp"

#include "autoware_control_center_msgs/msg/autoware_node_state.hpp"
Expand All @@ -24,11 +28,6 @@
#include "autoware_control_center_msgs/srv/autoware_node_error.hpp"
#include "autoware_control_center_msgs/srv/autoware_node_register.hpp"

#include "rclcpp/subscription_options.hpp"
#include "rclcpp/subscription.hpp"
#include "rclcpp/subscription_traits.hpp"
#include "rclcpp/message_memory_strategy.hpp"

#include <string>

namespace autoware_node
Expand All @@ -42,51 +41,32 @@ class AutowareNode : public rclcpp_lifecycle::LifecycleNode
const std::string & node_name, const std::string & ns = "",
const rclcpp::NodeOptions & options = rclcpp::NodeOptions());

template<
typename MessageT,
typename CallbackT,
typename AllocatorT = std::allocator<void>,
typename SubscriptionT = rclcpp::Subscription<MessageT, AllocatorT>,
typename MessageMemoryStrategyT = typename SubscriptionT::MessageMemoryStrategyType>
template <
typename MessageT, typename CallbackT, typename AllocatorT = std::allocator<void>,
typename SubscriptionT = rclcpp::Subscription<MessageT, AllocatorT>,
typename MessageMemoryStrategyT = typename SubscriptionT::MessageMemoryStrategyType>
std::shared_ptr<SubscriptionT> create_monitored_subscription(
const std::string & topic_name,
const float hz,
const rclcpp::QoS & qos,
CallbackT && callback,
const rclcpp::SubscriptionOptions & options =
rclcpp::SubscriptionOptions(),
typename MessageMemoryStrategyT::SharedPtr msg_mem_strat = (
MessageMemoryStrategyT::create_default()
)
);
const std::string & topic_name, const float hz, const rclcpp::QoS & qos, CallbackT && callback,
const rclcpp::SubscriptionOptions & options = rclcpp::SubscriptionOptions(),
typename MessageMemoryStrategyT::SharedPtr msg_mem_strat =
(MessageMemoryStrategyT::create_default()));

template<
typename MessageT,
typename CallbackT,
typename AllocatorT = std::allocator<void>,
typename SubscriptionT = rclcpp::Subscription<MessageT, AllocatorT>>
template <
typename MessageT, typename CallbackT, typename AllocatorT = std::allocator<void>,
typename SubscriptionT = rclcpp::Subscription<MessageT, AllocatorT>>
std::shared_ptr<SubscriptionT> create_simple_monitored_subscription(
const std::string & topic_name,
const rclcpp::QoS & qos,
CallbackT && callback);
const std::string & topic_name, const rclcpp::QoS & qos, CallbackT && callback);

template<
typename MessageT,
typename CallbackT,
typename AllocatorT = std::allocator<void>,
template <
typename MessageT, typename CallbackT, typename AllocatorT = std::allocator<void>,
typename SubscriptionT = rclcpp::Subscription<MessageT, AllocatorT>,
typename MessageMemoryStrategyT = typename SubscriptionT::MessageMemoryStrategyType>
std::shared_ptr<SubscriptionT>
test_create_subscription(
const std::string & topic_name,
const rclcpp::QoS & qos,
CallbackT && callback,
std::shared_ptr<SubscriptionT> test_create_subscription(
const std::string & topic_name, const rclcpp::QoS & qos, CallbackT && callback,
const rclcpp::SubscriptionOptionsWithAllocator<AllocatorT> & options =
rclcpp_lifecycle::create_default_subscription_options<AllocatorT>(),
typename MessageMemoryStrategyT::SharedPtr msg_mem_strat = (
MessageMemoryStrategyT::create_default()
)
);
rclcpp_lifecycle::create_default_subscription_options<AllocatorT>(),
typename MessageMemoryStrategyT::SharedPtr msg_mem_strat =
(MessageMemoryStrategyT::create_default()));

rclcpp::CallbackGroup::SharedPtr callback_group_mut_ex_;

Expand Down
86 changes: 30 additions & 56 deletions common/autoware_node/src/autoware_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,90 +189,64 @@ void AutowareNode::send_state(
RCLCPP_INFO(get_logger(), "Send node state");
}

template<
typename MessageT,
typename CallbackT,
typename AllocatorT = std::allocator<void>,
typename SubscriptionT = rclcpp::Subscription<MessageT, AllocatorT>,
typename MessageMemoryStrategyT = typename SubscriptionT::MessageMemoryStrategyType>
template <
typename MessageT, typename CallbackT, typename AllocatorT = std::allocator<void>,
typename SubscriptionT = rclcpp::Subscription<MessageT, AllocatorT>,
typename MessageMemoryStrategyT = typename SubscriptionT::MessageMemoryStrategyType>
std::shared_ptr<SubscriptionT> AutowareNode::create_monitored_subscription(
const std::string & topic_name,
const float hz,
const rclcpp::QoS & qos,
CallbackT && callback,
const std::string & topic_name, const float hz, const rclcpp::QoS & qos, CallbackT && callback,
const rclcpp::SubscriptionOptions & options,
typename MessageMemoryStrategyT::SharedPtr msg_mem_strat)
{
// create proper qos based on input parameter
// update lease duration and deadline in qos
// create proper qos based on input parameter
// update lease duration and deadline in qos
RCLCPP_INFO(get_logger(), "Create monitored subscription");
std::chrono::milliseconds lease_duration = 1.0 / hz * 1000;
lease_duration = 1.1 * lease_duration; // add 10 % gap to lease duration (buffer)
lease_duration = 1.1 * lease_duration; // add 10 % gap to lease duration (buffer)
rclcpp::QoS qos_profile = qos;
qos_profile.liveliness(RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_TOPIC)
.liveliness_lease_duration(lease_duration)
.deadline(lease_duration);

rclcpp::SubscriptionOptions sub_options = options;
sub_options.event_callbacks.deadline_callback =
[=](rclcpp::QOSDeadlineRequestedInfo& event) -> void {
RCLCPP_INFO(get_logger(), "Requested deadline missed - total %d delta %d\n",
event.total_count, event.total_count_change);
// add NodeError service call
std::string msg = "Deadline for topic " + topic_name + " was missed.";
autoware_control_center_msgs::msg::AutowareNodeState node_state;
node_state.status = autoware_control_center_msgs::msg::AutowareNodeState::ERROR;
send_state(node_state, msg);
sub_options.event_callbacks.deadline_callback =
[=](rclcpp::QOSDeadlineRequestedInfo & event) -> void {
RCLCPP_INFO(
get_logger(), "Requested deadline missed - total %d delta %d\n", event.total_count,
event.total_count_change);
// add NodeError service call
std::string msg = "Deadline for topic " + topic_name + " was missed.";
autoware_control_center_msgs::msg::AutowareNodeState node_state;
node_state.status = autoware_control_center_msgs::msg::AutowareNodeState::ERROR;
send_state(node_state, msg);
};

return rclcpp::create_subscription<MessageT> (
*this,
topic_name,
qos_profile,
std::forward<CallbackT>(callback),
sub_options,
msg_mem_strat);
return rclcpp::create_subscription<MessageT>(
*this, topic_name, qos_profile, std::forward<CallbackT>(callback), sub_options, msg_mem_strat);
}

template<
typename MessageT,
typename CallbackT,
typename AllocatorT = std::allocator<void>,
typename SubscriptionT = rclcpp::Subscription<MessageT, AllocatorT>>
template <
typename MessageT, typename CallbackT, typename AllocatorT = std::allocator<void>,
typename SubscriptionT = rclcpp::Subscription<MessageT, AllocatorT>>
std::shared_ptr<SubscriptionT> AutowareNode::create_simple_monitored_subscription(
const std::string & topic_name,
const rclcpp::QoS & qos,
CallbackT && callback)
const std::string & topic_name, const rclcpp::QoS & qos, CallbackT && callback)
{
return rclcpp_lifecycle::LifecycleNode::create_subscription<MessageT>(
topic_name,
qos,
std::forward<CallbackT>(callback));
topic_name, qos, std::forward<CallbackT>(callback));
}


template<
typename MessageT,
typename CallbackT,
typename AllocatorT = std::allocator<void>,
template <
typename MessageT, typename CallbackT, typename AllocatorT = std::allocator<void>,
typename SubscriptionT = rclcpp::Subscription<MessageT, AllocatorT>,
typename MessageMemoryStrategyT = typename SubscriptionT::MessageMemoryStrategyType>
std::shared_ptr<SubscriptionT>
AutowareNode::test_create_subscription(
const std::string & topic_name,
const rclcpp::QoS & qos,
CallbackT && callback,
std::shared_ptr<SubscriptionT> AutowareNode::test_create_subscription(
const std::string & topic_name, const rclcpp::QoS & qos, CallbackT && callback,
const rclcpp::SubscriptionOptionsWithAllocator<AllocatorT> & options,
typename MessageMemoryStrategyT::SharedPtr msg_mem_strat)
{
RCLCPP_INFO(get_logger(), "call test_create_subscription");
return rclcpp::create_subscription<MessageT>(
*this,
topic_name,
qos,
std::forward<CallbackT>(callback),
options,
msg_mem_strat);
*this, topic_name, qos, std::forward<CallbackT>(callback), options, msg_mem_strat);
}

} // namespace autoware_node
1 change: 0 additions & 1 deletion common/test_node/include/test_node/test_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "rclcpp_lifecycle/lifecycle_node.hpp"
#include "test_node/visibility_control.hpp"


#include "std_msgs/msg/string.hpp"
namespace test_node
{
Expand Down
13 changes: 7 additions & 6 deletions common/test_node/src/test_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,23 @@ namespace test_node

using std::placeholders::_1;


TestNode::TestNode(const rclcpp::NodeOptions & options)
: autoware_node::AutowareNode("test_node", "", options)
{
RCLCPP_INFO(
get_logger(), "TestNode constructor with name %s",
autoware_node::AutowareNode::self_name.c_str());
// monitored_subscription_ = autoware_node::AutowareNode::create_monitored_subscription<std_msgs::msg::String>(
// monitored_subscription_ =
// autoware_node::AutowareNode::create_monitored_subscription<std_msgs::msg::String>(
// "topic", 10, 10, std::bind(&TestNode::topic_callback, this, _1));
// monitored_subscription_ = autoware_node::AutowareNode::create_simple_monitored_subscription<std_msgs::msg::String>(
// monitored_subscription_ =
// autoware_node::AutowareNode::create_simple_monitored_subscription<std_msgs::msg::String>(
// "topic", 10, std::bind(&TestNode::topic_callback, this, _1)
// );

monitored_subscription_ = autoware_node::AutowareNode::test_create_subscription<std_msgs::msg::String>(
"topic", 10, std::bind(&TestNode::topic_callback, this, _1));

monitored_subscription_ =
autoware_node::AutowareNode::test_create_subscription<std_msgs::msg::String>(
"topic", 10, std::bind(&TestNode::topic_callback, this, _1));
}

void TestNode::topic_callback(const std_msgs::msg::String::SharedPtr msg)
Expand Down

0 comments on commit 2c7d4e4

Please sign in to comment.