ethercat_driver_ros2  main
C++ ROS test
ec_sync_manager.hpp
Go to the documentation of this file.
1 // Copyright 2023 ICUBE Laboratory, University of Strasbourg
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // Author: Maciej Bednarczyk (macbednarczyk@gmail.com)
16 
17 #ifndef ETHERCAT_INTERFACE__EC_SYNC_MANAGER_HPP_
18 #define ETHERCAT_INTERFACE__EC_SYNC_MANAGER_HPP_
19 
20 #include <ecrt.h>
21 #include <string>
22 #include <vector>
23 #include <limits>
24 
25 #include "yaml-cpp/yaml.h"
26 
27 namespace ethercat_interface
28 {
29 
30 class SMConfig
31 {
32 public:
33  SMConfig() {}
34  ~SMConfig() {}
35 
36  bool load_from_config(YAML::Node sm_config)
37  {
38  // index
39  if (sm_config["index"]) {
40  index = sm_config["index"].as<uint8_t>();
41  } else {
42  std::cerr << "missing sdo index info" << std::endl;
43  return false;
44  }
45  // type
46  if (sm_config["type"]) {
47  if (sm_config["type"].as<std::string>() == "input") {
48  type = EC_DIR_INPUT;
49  } else if (sm_config["type"].as<std::string>() == "output") {
50  type = EC_DIR_OUTPUT;
51  } else {
52  std::cerr << "sm " << index << ": type should be input/output" << std::endl;
53  return false;
54  }
55  } else {
56  std::cerr << "sm " << index << ": missing type info" << std::endl;
57  return false;
58  }
59  // pdo name
60  if (sm_config["pdo"]) {
61  if (sm_config["pdo"].as<std::string>() == "rpdo") {
62  pdo_name = "rpdo";
63  } else if (sm_config["pdo"].as<std::string>() == "tpdo") {
64  pdo_name = "tpdo";
65  }
66  }
67  // watchdog
68  if (sm_config["watchdog"]) {
69  if (sm_config["watchdog"].as<std::string>() == "enable") {
70  watchdog = EC_WD_ENABLE;
71  } else if (sm_config["watchdog"].as<std::string>() == "disable") {
72  watchdog = EC_WD_DISABLE;
73  }
74  }
75 
76  return true;
77  }
78 
79  uint8_t index;
80  ec_direction_t type;
81  std::string pdo_name = "null";
82  ec_watchdog_mode_t watchdog = EC_WD_DEFAULT;
83 };
84 
85 } // namespace ethercat_interface
86 #endif // ETHERCAT_INTERFACE__EC_SYNC_MANAGER_HPP_
Definition: ec_sync_manager.hpp:31
bool load_from_config(YAML::Node sm_config)
Definition: ec_sync_manager.hpp:36
~SMConfig()
Definition: ec_sync_manager.hpp:34
ec_direction_t type
Definition: ec_sync_manager.hpp:80
SMConfig()
Definition: ec_sync_manager.hpp:33
uint8_t index
Definition: ec_sync_manager.hpp:79
std::string pdo_name
Definition: ec_sync_manager.hpp:81
ec_watchdog_mode_t watchdog
Definition: ec_sync_manager.hpp:82
Definition: ec_master.hpp:29