EtherCAT Control Framework v0.9
Implementation of EtherCAT protocol using IgH EtherCAT library for robot controller.
safety_node.hpp
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * $Id$
4 *
5 * Copyright (C) 2021 Veysi ADIN, UST KIST
6 *
7 * This file is part of the IgH EtherCAT master userspace program in the ROS2 environment.
8 *
9 * The IgH EtherCAT master userspace program in the ROS2 environment is free software; you can
10 * redistribute it and/or modify it under the terms of the GNU General
11 * Public License as published by the Free Software Foundation; version 2
12 * of the License.
13 *
14 * The IgH EtherCAT master userspace program in the ROS2 environment is distributed in the hope that
15 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with the IgH EtherCAT master userspace program in the ROS environment. If not, see
21 * <http://www.gnu.org/licenses/>.
22 *
23 * ---
24 *
25 * The license mentioned above concerns the source code only. Using the
26 * EtherCAT technology and brand is only permitted in compliance with the
27 * industrial property and similar rights of Beckhoff Automation GmbH.
28 *
29 * Contact information: veysi.adin@kist.re.kr
30 *****************************************************************************/
31/*****************************************************************************
32 * \file safety_node.hpp
33 * \brief Header file for the Safety Node which is a manager node for the
34 * EtherCAT life cycle node.
35 * This header file contains required include for lifecycle management and safety
36 * state data structure.
37 *******************************************************************************/
38#pragma once
39#include <chrono>
40#include <memory>
41#include <string>
42#include <thread>
43
44#include "lifecycle_msgs/msg/state.hpp"
45#include "lifecycle_msgs/msg/transition.hpp"
46#include "lifecycle_msgs/srv/change_state.hpp"
47#include "lifecycle_msgs/srv/get_state.hpp"
48#include "sensor_msgs/msg/joy.hpp"
49#include "ecat_msgs/msg/gui_button_data.hpp"
50#include "ecat_msgs/msg/data_received.hpp"
51#include "rclcpp/rclcpp.hpp"
52#include <std_srvs/srv/trigger.hpp>
53#include "std_msgs/msg/u_int16.hpp"
54#include "rcutils/logging_macros.h"
55#include "rclcpp/rclcpp.hpp"
56#include "ecat_globals.hpp"
57
58using namespace std::chrono_literals;
59
60// which node to handle
61static constexpr char const * lifecycle_node = "ecat_node";
62
63// Every lifecycle node has various services attached to it.
64// By convention, we use the format of <node name>/<service name>.
65// ecat_node/get_state
66// ecat_node/change_state
67static constexpr char const * node_get_state_topic = "ecat_node/get_state";
68static constexpr char const * node_change_state_topic = "ecat_node/change_state";
69
70
71template<typename FutureT, typename WaitTimeT>
72std::future_status
74 FutureT & future,
75 WaitTimeT time_to_wait)
76{
77 auto end = std::chrono::steady_clock::now() + time_to_wait;
78 std::chrono::milliseconds wait_period(100);
79 std::future_status status = std::future_status::timeout;
80 do {
81 auto now = std::chrono::steady_clock::now();
82 auto time_left = end - now;
83 if (time_left <= std::chrono::milliseconds(0)) {break;}
84 status = future.wait_for((time_left < wait_period) ? time_left : wait_period);
85 } while (status != std::future_status::ready);
86 return status;
87}
88
96};
std::future_status wait_for_result(FutureT &future, WaitTimeT time_to_wait)
Definition: safety_node.hpp:73
static constexpr char const * node_change_state_topic
Definition: safety_node.hpp:68
SafetyInfo
Definition: safety_node.hpp:89
@ kSafe
Definition: safety_node.hpp:90
@ kErrorInDrive
Definition: safety_node.hpp:94
@ kEmergencyStop
Definition: safety_node.hpp:95
@ kOverPositionLimit
Definition: safety_node.hpp:93
@ kOverSpeed
Definition: safety_node.hpp:92
@ kOverForce
Definition: safety_node.hpp:91
static constexpr char const * lifecycle_node
Definition: safety_node.hpp:61
static constexpr char const * node_get_state_topic
Definition: safety_node.hpp:67