EtherCAT Client Library Code 0.0.1
EtherCAT Client library that uses different communication protocols with EtherCAT Master server.
Loading...
Searching...
No Matches
ec_utils.h
1#ifndef __EC_UTILS__
2#define __EC_UTILS__
3
4#include <yaml-cpp/yaml.h>
5#include <thread>
6#include "protocol/udp/ec_udp.h"
7#include "protocol/tcp/ec_tcp.h"
8#include "protocol/ipc/iddp/ec_iddp.h"
9#include "protocol/ipc/zipc/ec_zipc.h"
10#include <ecat_core/trajectory.h>
11
12enum class TrjType : uint8_t
13{
14 zero,
15 start,
16 trj1,
17 trj2
18};
19
20struct TRJ_INFO{
21 std::string type;
22 std::vector<std::string> limits;
23};
24
25using TrjInfoMap = std::map<int, TRJ_INFO>;
26extern const std::map<std::string, TrjInfoMap> esc_trj_map;
27
28typedef struct ESC_TRJ_t{
29 int32_t esc_id;
30
31 double trj1;
32 double trj2;
33 double set_zero;
34 std::vector<double> trj_limit;
35
36 double start;
37 double set_ref;
38 double set_trj;
39
40 Trj_ptr general_trj;
41
42 bool check_limit(double v);
43 void set_trj_limit(const std::vector<double>& limits);
44 void setup_trj(TrjType type);
45 void set_target(double ref);
46}ESC_TRJ;
47
48using EscTrjMap= std::map<int32_t, ESC_TRJ >;
49
50class EcUtils
51{
52public:
53
54 typedef struct DEVICE_CONFIG_t{
55 std::string device_name;
56 uint32_t type;
57 int control_mode_type;
58 std::vector<float> gains;
59 bool brake_present; // only for motor
60 }DEVICE_CONFIG;
61
62 typedef struct TRAJECTORY_CONFIG_t{
63 std::map<int,std::map<std::string,double>> set_point;
64 std::map<int,double> homing;
65 std::map<int,double> trajectory;
66 std::map<int,std::map<std::string,Trj_ptr>> trj_generator;
68
69 typedef struct EC_CONFIG_t{
70
71 std::string protocol;
72 std::string host_name;
73 uint32_t host_port;
74 int period_ms;
75 bool logging;
76
77 std::map<int,DEVICE_CONFIG> device_config_map;
78
79 std::string trj_type="";
80 float trj_time=0;
81 int repeat_trj=1;
82 std::map<std::string,TRAJECTORY_CONFIG_t> trj_config_map;
83 SSI fake_slave_info;
84
85 }EC_CONFIG;
86
87 typedef std::shared_ptr<EcUtils> Ptr;
88
89 EcUtils(EC_CONFIG ec_cfg);
90 EcUtils();
91
92 ~EcUtils();
93
94 EC_CONFIG get_ec_cfg();
95 std::string get_ec_cfg_file();
96 EcIface::Ptr make_ec_iface(); // EtherCAT Client Interface
97private:
98
99 std::string _control_mode;
100 EC_CONFIG _ec_cfg;
101 std::string _ec_cfg_file;
102
103 void compute_absolute_path(std::string dir_path,std::string &file_path);
104 void generate_fake_slave_info();
105 void device_config_map(const YAML::Node & device_config_node,std::string device_type);
106 void config_trajectory();
107 void config_device();
108 void trajectory_generator();
109
110 std::vector<std::string> _device_type_vector={"motor","valve","pump","gripper","imu"};
111 std::vector<std::string> _robot_path_v={"robot_id_map_path","robot_control_path"};
112 std::vector<std::string> _robot_abs_path={"",""};
113 YAML::Node _robot_id_map_node;
114 YAML::Node _robot_control_node;
115};
116
117#endif
Definition ec_utils.h:28
Definition ec_utils.h:54
Definition ec_utils.h:69
Definition ec_utils.h:62
Definition ec_utils.h:20