ethercat_driver_ros2  main
C++ ROS test
ec_slave.hpp
Go to the documentation of this file.
1 // Copyright 2022 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 #ifndef ETHERCAT_INTERFACE__EC_SLAVE_HPP_
16 #define ETHERCAT_INTERFACE__EC_SLAVE_HPP_
17 
18 #include <ecrt.h>
19 #include <map>
20 #include <vector>
21 #include <unordered_map>
22 #include <iostream>
23 #include <cmath>
24 #include <string>
25 
27 
28 namespace ethercat_interface
29 {
30 
31 class EcSlave
32 {
33 public:
34  EcSlave(uint32_t vendor_id, uint32_t product_id)
35  : vendor_id_(vendor_id),
36  product_id_(product_id) {}
37  virtual ~EcSlave() {}
39  virtual void processData(size_t /*index*/, uint8_t * /*domain_address*/) {}
41  virtual const ec_sync_info_t * syncs() {return NULL;}
42  virtual bool initialized() {return true;}
43  virtual void set_state_is_operational(bool value) {is_operational_ = value;}
45  virtual int assign_activate_dc_sync() {return 0x00;}
47  virtual size_t syncSize() {return 0;}
49  virtual const ec_pdo_entry_info_t * channels() {return NULL;}
52  typedef std::map<unsigned int, std::vector<unsigned int>> DomainMap;
53  virtual void domains(DomainMap & /*domains*/) const {}
54  virtual bool setupSlave(
55  std::unordered_map<std::string, std::string> slave_paramters,
56  std::vector<double> * state_interface,
57  std::vector<double> * command_interface)
58  {
59  state_interface_ptr_ = state_interface;
60  command_interface_ptr_ = command_interface;
61  paramters_ = slave_paramters;
62  return true;
63  }
64  uint32_t vendor_id_;
65  uint32_t product_id_;
66 
67  std::vector<SdoConfigEntry> sdo_config;
68 
69 protected:
70  std::vector<double> * state_interface_ptr_;
71  std::vector<double> * command_interface_ptr_;
72  std::unordered_map<std::string, std::string> paramters_;
73  bool is_operational_ = false;
74 };
75 } // namespace ethercat_interface
76 #endif // ETHERCAT_INTERFACE__EC_SLAVE_HPP_
Definition: ec_slave.hpp:32
virtual int assign_activate_dc_sync()
Definition: ec_slave.hpp:45
virtual bool initialized()
Definition: ec_slave.hpp:42
virtual void processData(size_t, uint8_t *)
Definition: ec_slave.hpp:39
uint32_t product_id_
Definition: ec_slave.hpp:65
virtual const ec_pdo_entry_info_t * channels()
Definition: ec_slave.hpp:49
virtual size_t syncSize()
Definition: ec_slave.hpp:47
virtual void set_state_is_operational(bool value)
Definition: ec_slave.hpp:43
std::map< unsigned int, std::vector< unsigned int > > DomainMap
Definition: ec_slave.hpp:52
std::vector< double > * command_interface_ptr_
Definition: ec_slave.hpp:71
EcSlave(uint32_t vendor_id, uint32_t product_id)
Definition: ec_slave.hpp:34
std::vector< SdoConfigEntry > sdo_config
Definition: ec_slave.hpp:67
virtual const ec_sync_info_t * syncs()
Definition: ec_slave.hpp:41
std::vector< double > * state_interface_ptr_
Definition: ec_slave.hpp:70
virtual void domains(DomainMap &) const
Definition: ec_slave.hpp:53
bool is_operational_
Definition: ec_slave.hpp:73
uint32_t vendor_id_
Definition: ec_slave.hpp:64
std::unordered_map< std::string, std::string > paramters_
Definition: ec_slave.hpp:72
virtual ~EcSlave()
Definition: ec_slave.hpp:37
virtual bool setupSlave(std::unordered_map< std::string, std::string > slave_paramters, std::vector< double > *state_interface, std::vector< double > *command_interface)
Definition: ec_slave.hpp:54
Definition: ec_master.hpp:29