.. _program_listing_file_include_hardware_interface_system_interface.hpp: Program Listing for File system_interface.hpp ============================================= |exhale_lsh| :ref:`Return to documentation for file ` (``include/hardware_interface/system_interface.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // Copyright 2020 - 2021 ros2_control Development Team // // 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 HARDWARE_INTERFACE__SYSTEM_INTERFACE_HPP_ #define HARDWARE_INTERFACE__SYSTEM_INTERFACE_HPP_ #include #include #include #include "hardware_interface/handle.hpp" #include "hardware_interface/hardware_info.hpp" #include "hardware_interface/types/hardware_interface_return_values.hpp" #include "hardware_interface/types/lifecycle_state_names.hpp" #include "lifecycle_msgs/msg/state.hpp" #include "rclcpp/duration.hpp" #include "rclcpp/time.hpp" #include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp" #include "rclcpp_lifecycle/state.hpp" namespace hardware_interface { using CallbackReturn = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn; class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface { public: SystemInterface() : lifecycle_state_(rclcpp_lifecycle::State( lifecycle_msgs::msg::State::PRIMARY_STATE_UNKNOWN, lifecycle_state_names::UNKNOWN)) { } SystemInterface(const SystemInterface & other) = delete; SystemInterface(SystemInterface && other) = default; virtual ~SystemInterface() = default; virtual CallbackReturn on_init(const HardwareInfo & hardware_info) { info_ = hardware_info; return CallbackReturn::SUCCESS; }; virtual std::vector export_state_interfaces() = 0; virtual std::vector export_command_interfaces() = 0; virtual return_type prepare_command_mode_switch( const std::vector & /*start_interfaces*/, const std::vector & /*stop_interfaces*/) { return return_type::OK; } // Perform switching to the new command interface. virtual return_type perform_command_mode_switch( const std::vector & /*start_interfaces*/, const std::vector & /*stop_interfaces*/) { return return_type::OK; } virtual return_type read(const rclcpp::Time & time, const rclcpp::Duration & period) = 0; virtual return_type write(const rclcpp::Time & time, const rclcpp::Duration & period) = 0; virtual std::string get_name() const { return info_.name; } virtual std::string get_group_name() const { return info_.group; } const rclcpp_lifecycle::State & get_state() const { return lifecycle_state_; } void set_state(const rclcpp_lifecycle::State & new_state) { lifecycle_state_ = new_state; } protected: HardwareInfo info_; rclcpp_lifecycle::State lifecycle_state_; }; } // namespace hardware_interface #endif // HARDWARE_INTERFACE__SYSTEM_INTERFACE_HPP_