-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbmark_controllers.cpp
99 lines (84 loc) · 3.04 KB
/
bmark_controllers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2022, ICube Laboratory, University of Strasbourg
//
// 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 "bmark_controllers/bmark_controllers.hpp"
#include <memory>
#include <string>
namespace bmark_controllers
{
DurationBroadcaster::DurationBroadcaster()
: controller_interface::ControllerInterface()
{
}
CallbackReturn DurationBroadcaster::on_init()
{
return CallbackReturn::SUCCESS;
}
CallbackReturn DurationBroadcaster::on_configure(
const rclcpp_lifecycle::State & /*previous_state*/)
{
try
{
// register ft sensor data publisher
duration_publisher_ = get_node()->create_publisher<BMsgType>(
"~/duration", rclcpp::SystemDefaultsQoS());
realtime_publisher_ = std::make_unique<realtime_tools::RealtimePublisher<BMsgType>>(duration_publisher_);
}
catch (const std::exception & e)
{
fprintf(
stderr, "Exception thrown during publisher creation at configure stage with message : %s \n",
e.what());
return CallbackReturn::ERROR;
}
RCLCPP_DEBUG(get_node()->get_logger(), "configure successful");
return CallbackReturn::SUCCESS;
}
controller_interface::InterfaceConfiguration
DurationBroadcaster::command_interface_configuration() const
{
controller_interface::InterfaceConfiguration command_interfaces_config;
command_interfaces_config.type = controller_interface::interface_configuration_type::NONE;
return command_interfaces_config;
}
controller_interface::InterfaceConfiguration
DurationBroadcaster::state_interface_configuration() const
{
controller_interface::InterfaceConfiguration state_interfaces_config;
state_interfaces_config.type = controller_interface::interface_configuration_type::NONE;
return state_interfaces_config;
}
CallbackReturn DurationBroadcaster::on_activate(
const rclcpp_lifecycle::State & /*previous_state*/)
{
return CallbackReturn::SUCCESS;
}
CallbackReturn DurationBroadcaster::on_deactivate(
const rclcpp_lifecycle::State & /*previous_state*/)
{
return CallbackReturn::SUCCESS;
}
controller_interface::return_type DurationBroadcaster::update(const rclcpp::Time & time, const rclcpp::Duration & period)
{
if (realtime_publisher_ && realtime_publisher_->trylock())
{
realtime_publisher_->msg_.header.stamp = time;
realtime_publisher_->msg_.duration = period.nanoseconds();
realtime_publisher_->unlockAndPublish();
}
return controller_interface::return_type::OK;
}
} // namespace bmark_controllers
#include "pluginlib/class_list_macros.hpp"
PLUGINLIB_EXPORT_CLASS(
bmark_controllers::DurationBroadcaster, controller_interface::ControllerInterface)