Skip to content

Commit

Permalink
feat: add external adaptor for cpu usage topic (autowarefoundation#19)
Browse files Browse the repository at this point in the history
* add external adaptor for cpu usage topic

Signed-off-by: TakumiKozaka-T4 <takumi.kozaka@tier4.jp>

* run pre-commit

Signed-off-by: TakumiKozaka-T4 <takumi.kozaka@tier4.jp>

* modified along the comment on PR

Signed-off-by: TakumiKozaka-T4 <takumi.kozaka@tier4.jp>

* modify a comment

Signed-off-by: TakumiKozaka-T4 <takumi.kozaka@tier4.jp>
  • Loading branch information
TakumiKozaka-T4 authored Feb 21, 2022
1 parent f72bb18 commit a187a54
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
2 changes: 2 additions & 0 deletions autoware_iv_external_api_adaptor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ find_package(ament_cmake_auto REQUIRED)
ament_auto_find_build_dependencies()

ament_auto_add_library(${PROJECT_NAME} SHARED
src/cpu_usage.cpp
src/diagnostics.cpp
src/door.cpp
src/emergency.cpp
Expand All @@ -31,6 +32,7 @@ ament_auto_add_library(${PROJECT_NAME} SHARED
src/velocity.cpp
src/version.cpp
)
rclcpp_components_register_nodes(${PROJECT_NAME} "external_api::CpuUsage")
rclcpp_components_register_nodes(${PROJECT_NAME} "external_api::Diagnostics")
rclcpp_components_register_nodes(${PROJECT_NAME} "external_api::Door")
rclcpp_components_register_nodes(${PROJECT_NAME} "external_api::Emergency")
Expand Down
36 changes: 36 additions & 0 deletions autoware_iv_external_api_adaptor/src/cpu_usage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2021 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.

#include "cpu_usage.hpp"

#include <memory>

namespace external_api
{

CpuUsage::CpuUsage(const rclcpp::NodeOptions & options) : Node("cpu_usage", options)
{
pub_cpu_usage_ = create_publisher<tier4_external_api_msgs::msg::CpuUsage>(
"/api/external/get/cpu_usage", rclcpp::QoS(1));
sub_cpu_usage_ = create_subscription<tier4_external_api_msgs::msg::CpuUsage>(
"/system/system_monitor/cpu_monitor/cpu_usage", rclcpp::QoS(1),
[this](const tier4_external_api_msgs::msg::CpuUsage::SharedPtr msg) {
pub_cpu_usage_->publish(*msg);
});
}

} // namespace external_api

#include "rclcpp_components/register_node_macro.hpp"
RCLCPP_COMPONENTS_REGISTER_NODE(external_api::CpuUsage)
39 changes: 39 additions & 0 deletions autoware_iv_external_api_adaptor/src/cpu_usage.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2021 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 CPU_USAGE_HPP_
#define CPU_USAGE_HPP_

#include "rclcpp/rclcpp.hpp"
#include "tier4_api_utils/tier4_api_utils.hpp"

#include "tier4_external_api_msgs/msg/cpu_status.hpp"
#include "tier4_external_api_msgs/msg/cpu_usage.hpp"

namespace external_api
{

class CpuUsage : public rclcpp::Node
{
public:
explicit CpuUsage(const rclcpp::NodeOptions & options);

private:
rclcpp::Publisher<tier4_external_api_msgs::msg::CpuUsage>::SharedPtr pub_cpu_usage_;
rclcpp::Subscription<tier4_external_api_msgs::msg::CpuUsage>::SharedPtr sub_cpu_usage_;
};

} // namespace external_api

#endif // CPU_USAGE_HPP_

0 comments on commit a187a54

Please sign in to comment.