Protective Stop
Loading...
Searching...
No Matches
machine_bridge_node.hpp
1// SPDX-FileCopyrightText: 2026 Polymath Robotics, Inc.
2// SPDX-License-Identifier: Apache-2.0
3#pragma once
4
5#include <memory>
6#include <string>
7#include <vector>
8
9#include "diagnostic_updater/diagnostic_updater.hpp"
10#include "protective_stop_machine/announce.hpp"
11#include "protective_stop_machine/backend.hpp"
12#include "protective_stop_machine/fleet_checkin.hpp"
13#include "protective_stop_machine/protective_stop_machine_parameters.hpp"
14#include "protective_stop_msg/msg/bonded_remote_array.hpp"
15#include "protective_stop_msg/msg/machine_relay_status.hpp"
16#include "protective_stop_msg/msg/protective_stop_heartbeat.hpp"
17#include "protective_stop_msg/msg/protective_stop_status.hpp"
18#include "rcl_interfaces/msg/set_parameters_result.hpp"
19#include "rclcpp/rclcpp.hpp"
20#include "rclcpp_lifecycle/lifecycle_node.hpp"
21
22namespace protective_stop_machine
23{
24
28class MachineBridgeNode : public rclcpp_lifecycle::LifecycleNode
29{
30public:
32 using CallbackReturn = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
33
35 explicit MachineBridgeNode(const rclcpp::NodeOptions & options);
36
38 CallbackReturn on_configure(const rclcpp_lifecycle::State &) override;
40 CallbackReturn on_activate(const rclcpp_lifecycle::State &) override;
42 CallbackReturn on_deactivate(const rclcpp_lifecycle::State &) override;
44 CallbackReturn on_cleanup(const rclcpp_lifecycle::State &) override;
46 CallbackReturn on_shutdown(const rclcpp_lifecycle::State &) override;
48 CallbackReturn on_error(const rclcpp_lifecycle::State &) override;
49
50private:
51 bool build_backend(std::string & error);
52 void publish_tick();
53 void log_runtime_transitions(const MachineSnapshot & snapshot);
54 void publish_heartbeat(bool stop, const rclcpp::Time & stamp);
55 void diagnostics(diagnostic_updater::DiagnosticStatusWrapper & stat);
59 rcl_interfaces::msg::SetParametersResult on_set_parameters(const std::vector<rclcpp::Parameter> & params);
60
61 ParamListener param_listener_;
62 Params params_;
63
64 // config
65 std::string backend_kind_;
66 std::string frame_id_;
67 MachineTiming timing_;
68 MachineSnapshot last_snapshot_;
69
70 bool runtime_logged_{false};
71 bool last_reachable_{false};
72 uint32_t last_active_remotes_{0};
73 MachineState last_state_{MachineState::UNSTABLE};
74
77 AnnounceConfig announce_config_;
78 int announce_port_{0};
79 uint32_t machine_id_{0};
80
83 FleetCheckinConfig fleet_config_;
84
85 std::unique_ptr<IMachineBackend> backend_;
86 std::unique_ptr<MachineAnnouncer> announcer_;
87 std::unique_ptr<FleetCheckin> fleet_checkin_;
88
89 rclcpp_lifecycle::LifecyclePublisher<protective_stop_msg::msg::ProtectiveStopStatus>::SharedPtr state_pub_;
90 rclcpp_lifecycle::LifecyclePublisher<protective_stop_msg::msg::MachineRelayStatus>::SharedPtr relay_pub_;
91 rclcpp_lifecycle::LifecyclePublisher<protective_stop_msg::msg::BondedRemoteArray>::SharedPtr remotes_pub_;
92 rclcpp_lifecycle::LifecyclePublisher<protective_stop_msg::msg::ProtectiveStopHeartbeat>::SharedPtr heartbeat_pub_;
93 rclcpp::TimerBase::SharedPtr pub_timer_;
94 std::shared_ptr<diagnostic_updater::Updater> diagnostics_updater_;
95 rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr param_cb_handle_;
96};
97
98} // namespace protective_stop_machine
CallbackReturn on_configure(const rclcpp_lifecycle::State &) override
Builds the configured backend and validates parameters.
CallbackReturn on_shutdown(const rclcpp_lifecycle::State &) override
Stops everything, from any state.
CallbackReturn on_deactivate(const rclcpp_lifecycle::State &) override
Stops the backend, publishing and the fleet reporters.
CallbackReturn on_activate(const rclcpp_lifecycle::State &) override
Starts the backend, publishing and the fleet reporters.
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn CallbackReturn
Lifecycle transition result.
Definition machine_bridge_node.hpp:32
CallbackReturn on_cleanup(const rclcpp_lifecycle::State &) override
Releases the backend.
MachineBridgeNode(const rclcpp::NodeOptions &options)
Declares parameters and creates the ROS interfaces.
CallbackReturn on_error(const rclcpp_lifecycle::State &) override
Handles a failed transition.
One immutable read of machine state, mapped straight onto the ROS messages.
Definition backend.hpp:64
Runtime-settable timing envelope.
Definition backend.hpp:100