Program Listing for File system_interface.hpp
↰ Return to documentation for file (/tmp/ws/src/schunk_svh_ros_driver/schunk_svh_driver/include/schunk_svh_driver/system_interface.hpp
)
//
// © Copyright 2022 SCHUNK Mobile Greifsysteme GmbH, Lauffen/Neckar Germany
// © Copyright 2022 FZI Forschungszentrum Informatik, Karlsruhe, Germany
//
// This file is part of the Schunk SVH Driver.
//
// The Schunk SVH Driver is free software: you can redistribute it and/or
// modify it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
// The Schunk SVH Driver is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
// Public License for more details.
//
// You should have received a copy of the GNU General Public License along with
// the Schunk SVH Driver. If not, see <https://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#pragma once
#include <map>
#include <memory>
#include <thread>
#include "hardware_interface/handle.hpp"
#include "hardware_interface/hardware_info.hpp"
#include "hardware_interface/system_interface.hpp"
#include "rclcpp/macros.hpp"
#include "rclcpp/rclcpp.hpp"
#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
#include "rclcpp_lifecycle/state.hpp"
#include "schunk_svh_library/control/SVHFingerManager.h"
namespace schunk_svh_driver
{
// Additional hardware interfaces for the SVH:
constexpr char HW_IF_CURRENT[] = "current";
class SystemInterface : public hardware_interface::SystemInterface
{
public:
using return_type = hardware_interface::return_type;
RCLCPP_SHARED_PTR_DEFINITIONS(SystemInterface)
CallbackReturn on_init(const hardware_interface::HardwareInfo & info) override;
CallbackReturn on_activate(const rclcpp_lifecycle::State & previous_state) override;
CallbackReturn on_shutdown(const rclcpp_lifecycle::State & previous_state) override;
std::vector<hardware_interface::StateInterface> export_state_interfaces() override;
std::vector<hardware_interface::CommandInterface> export_command_interfaces() override;
return_type prepare_command_mode_switch(
const std::vector<std::string> & start_interfaces,
const std::vector<std::string> & stop_interfaces) override;
return_type read(const rclcpp::Time & time, const rclcpp::Duration & period) override;
return_type write(const rclcpp::Time & time, const rclcpp::Duration & period) override;
private:
// Initialization of the SVH in a separate thread to meet ROS2-control's
// timing requirements.
void init();
std::atomic<bool> m_initialized{false};
std::thread m_init_thread;
// Handle to the SVH driver library
std::unique_ptr<driver_svh::SVHFingerManager> m_svh;
// Command buffers for the controllers
std::vector<double> m_position_commands;
// State buffers for the controllers
std::vector<double> m_positions;
std::vector<double> m_velocities;
std::vector<double> m_efforts;
std::vector<double> m_currents;
// Parameters
std::string m_device_file;
};
} // namespace schunk_svh_driver