ros2_control - kilted
Loading...
Searching...
No Matches
introspection.hpp
1// Copyright 2024 PAL Robotics S.L.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
16
17#ifndef HARDWARE_INTERFACE__INTROSPECTION_HPP_
18#define HARDWARE_INTERFACE__INTROSPECTION_HPP_
19
20#include <string>
21
22#include "hardware_interface/types/statistics_types.hpp"
23#include "pal_statistics/pal_statistics_macros.hpp"
24#include "pal_statistics/pal_statistics_utils.hpp"
25
27{
28template <>
29inline IdType customRegister(
30 StatisticsRegistry & registry, const std::string & name,
31 const libstatistics_collector::moving_average_statistics::StatisticData * variable,
32 RegistrationsRAII * bookkeeping, bool enabled)
33{
34 registry.registerVariable(name + "/max", &variable->max, bookkeeping, enabled);
35 registry.registerVariable(name + "/min", &variable->min, bookkeeping, enabled);
36 registry.registerVariable(name + "/average", &variable->average, bookkeeping, enabled);
37 registry.registerVariable(
38 name + "/standard_deviation", &variable->standard_deviation, bookkeeping, enabled);
39 std::function<double()> sample_func = [variable]
40 { return static_cast<double>(variable->sample_count); };
41 return registry.registerFunction(name + "/sample_count", sample_func, bookkeeping, enabled);
42}
43} // namespace pal_statistics
44
45namespace hardware_interface
46{
47constexpr char DEFAULT_REGISTRY_KEY[] = "ros2_control";
48constexpr char DEFAULT_INTROSPECTION_TOPIC[] = "~/introspection_data";
49constexpr char CM_STATISTICS_KEY[] = "cm_execution_statistics";
50constexpr char CM_STATISTICS_TOPIC[] = "~/statistics";
51
52#define REGISTER_ROS2_CONTROL_INTROSPECTION(ID, ENTITY) \
53 REGISTER_ENTITY( \
54 hardware_interface::DEFAULT_REGISTRY_KEY, get_name() + "." + ID, ENTITY, \
55 &stats_registrations_, false);
56
57#define UNREGISTER_ROS2_CONTROL_INTROSPECTION(ID) \
58 UNREGISTER_ENTITY(DEFAULT_REGISTRY_KEY, get_name() + "." + ID);
59
60#define CLEAR_ALL_ROS2_CONTROL_INTROSPECTION_REGISTRIES() CLEAR_ALL_REGISTRIES();
61
62#define INITIALIZE_ROS2_CONTROL_INTROSPECTION_REGISTRY(node, topic, registry_key) \
63 INITIALIZE_REGISTRY(node, topic, registry_key);
64
65#define START_ROS2_CONTROL_INTROSPECTION_PUBLISHER_THREAD(registry_key) \
66 START_PUBLISH_THREAD(registry_key);
67
68#define PUBLISH_ROS2_CONTROL_INTROSPECTION_DATA_ASYNC(registry_key) \
69 PUBLISH_ASYNC_STATISTICS(registry_key);
70
71#define DEFAULT_REGISTER_ROS2_CONTROL_INTROSPECTION(ID, ENTITY) \
72 REGISTER_ENTITY(DEFAULT_REGISTRY_KEY, ID, ENTITY);
73
74#define DEFAULT_UNREGISTER_ROS2_CONTROL_INTROSPECTION(ID) \
75 UNREGISTER_ENTITY(DEFAULT_REGISTRY_KEY, ID);
76} // namespace hardware_interface
77
78#endif // HARDWARE_INTERFACE__INTROSPECTION_HPP_
Definition actuator.hpp:22
Definition introspection.hpp:27