ros2_control - rolling
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 <functional>
21#include <string>
22
23#include "libstatistics_collector/moving_average_statistics/types.hpp"
24#include "pal_statistics/pal_statistics_macros.hpp"
25#include "pal_statistics/pal_statistics_utils.hpp"
26
28{
29template <>
30inline IdType customRegister(
31 StatisticsRegistry & registry, const std::string & name,
32 const libstatistics_collector::moving_average_statistics::StatisticData * variable,
33 RegistrationsRAII * bookkeeping, bool enabled)
34{
35 registry.registerVariable(name + "/max", &variable->max, bookkeeping, enabled);
36 registry.registerVariable(name + "/min", &variable->min, bookkeeping, enabled);
37 registry.registerVariable(name + "/average", &variable->average, bookkeeping, enabled);
38 registry.registerVariable(
39 name + "/standard_deviation", &variable->standard_deviation, bookkeeping, enabled);
40 std::function<double()> sample_func = [variable]
41 { return static_cast<double>(variable->sample_count); };
42 return registry.registerFunction(name + "/sample_count", sample_func, bookkeeping, enabled);
43}
44} // namespace pal_statistics
45
46namespace hardware_interface
47{
48constexpr char DEFAULT_REGISTRY_KEY[] = "ros2_control";
49constexpr char DEFAULT_INTROSPECTION_TOPIC[] = "~/introspection_data";
50constexpr char CM_STATISTICS_KEY[] = "cm_execution_statistics";
51constexpr char CM_STATISTICS_TOPIC[] = "~/statistics";
52
53#define REGISTER_ROS2_CONTROL_INTROSPECTION(ID, ENTITY) \
54 REGISTER_ENTITY( \
55 hardware_interface::DEFAULT_REGISTRY_KEY, get_name() + "." + ID, ENTITY, \
56 &stats_registrations_, false);
57
58#define UNREGISTER_ROS2_CONTROL_INTROSPECTION(ID) \
59 UNREGISTER_ENTITY(DEFAULT_REGISTRY_KEY, get_name() + "." + ID);
60
61#define CLEAR_ALL_ROS2_CONTROL_INTROSPECTION_REGISTRIES() CLEAR_ALL_REGISTRIES();
62
63#define INITIALIZE_ROS2_CONTROL_INTROSPECTION_REGISTRY(node, topic, registry_key) \
64 INITIALIZE_REGISTRY(node, topic, registry_key);
65
66#define START_ROS2_CONTROL_INTROSPECTION_PUBLISHER_THREAD(registry_key) \
67 START_PUBLISH_THREAD(registry_key);
68
69#define PUBLISH_ROS2_CONTROL_INTROSPECTION_DATA_ASYNC(registry_key) \
70 PUBLISH_ASYNC_STATISTICS(registry_key);
71
72#define DEFAULT_REGISTER_ROS2_CONTROL_INTROSPECTION(ID, ENTITY) \
73 REGISTER_ENTITY(DEFAULT_REGISTRY_KEY, ID, ENTITY);
74
75#define DEFAULT_UNREGISTER_ROS2_CONTROL_INTROSPECTION(ID) \
76 UNREGISTER_ENTITY(DEFAULT_REGISTRY_KEY, ID);
77} // namespace hardware_interface
78
79#endif // HARDWARE_INTERFACE__INTROSPECTION_HPP_
Definition mujoco_system_interface.hpp:57
Definition introspection.hpp:28