EtherCAT Client Library Code 0.0.1
EtherCAT Client library that uses different communication protocols with EtherCAT Master server.
Loading...
Searching...
No Matches
ft_pdo.h
1#ifndef __FT_PDO__
2#define __FT_PDO__
3
4#include <pb_utils.h>
5#include "mechanism/pipe/ec_pipe_pdo.h"
6#include "mechanism/zmq/ec_zmq_pdo.h"
7namespace FtPdoRx{
8 static const std::vector<std::string>name = {"force_x", "force_y", "force_z","torque_x", "torque_y","torque_z","fault","rtt"};
9 static const int pdo_size=8;
10 using pdo_t=std::tuple<float, float, float, float, float,float,uint16_t,uint16_t>;
11 template <typename T>
12 inline bool make_vector_from_tuple(const pdo_t &pdo_tuple,std::vector<T> &pdo_vector){
13 if(pdo_vector.size()!=pdo_size){
14 return false;
15 }
16 pdo_vector[0]= static_cast<T>(std::get<0>(pdo_tuple));
17 pdo_vector[1]= static_cast<T>(std::get<1>(pdo_tuple));
18 pdo_vector[2]= static_cast<T>(std::get<2>(pdo_tuple));
19 pdo_vector[3]= static_cast<T>(std::get<3>(pdo_tuple));
20 pdo_vector[4]= static_cast<T>(std::get<4>(pdo_tuple));
21 pdo_vector[5]= static_cast<T>(std::get<5>(pdo_tuple));
22 pdo_vector[6]= static_cast<T>(std::get<6>(pdo_tuple));
23 pdo_vector[7]= static_cast<T>(std::get<7>(pdo_tuple));
24 return true;
25 }
26};
27
28template <class T>
29class FtPdo: public T{
30
31public:
32
33 FtPdo(const std::string ,int32_t id, uint32_t type);
34 ~FtPdo();
35
36 void get_from_pb();
37
38 void set_to_pb();
39
40 FtPdoRx::pdo_t rx_pdo{};
41 bool init_rx_pdo=false;
42};
43
44template < class T >
45inline FtPdo<T>::FtPdo(const std::string value,int32_t id, uint32_t type):
46 T(id, type, value)
47{
48 T::init();
49 T::write_connect();
50};
51
52template < class T >
53inline FtPdo<T>::~FtPdo()
54{
55 T::write_quit();
56};
57
58template < class T >
59inline void FtPdo<T>::get_from_pb()
60{
61 std::get<0>(rx_pdo)= T::pb_rx_pdos.mutable_ft6_rx_pdo()->force_x();
62 std::get<1>(rx_pdo)= T::pb_rx_pdos.mutable_ft6_rx_pdo()->force_y();
63 std::get<2>(rx_pdo)= T::pb_rx_pdos.mutable_ft6_rx_pdo()->force_z();
64 std::get<3>(rx_pdo)= T::pb_rx_pdos.mutable_ft6_rx_pdo()->torque_x();
65 std::get<4>(rx_pdo)= T::pb_rx_pdos.mutable_ft6_rx_pdo()->torque_y();
66 std::get<5>(rx_pdo)= T::pb_rx_pdos.mutable_ft6_rx_pdo()->torque_z();
67 std::get<6>(rx_pdo)= T::pb_rx_pdos.mutable_ft6_rx_pdo()->fault();
68 std::get<7>(rx_pdo)= T::pb_rx_pdos.mutable_ft6_rx_pdo()->rtt();
69
70 if(!init_rx_pdo){
71 init_rx_pdo=true;
72 }
73}
74
75template < class T >
76inline void FtPdo<T>::set_to_pb()
77{
78}
79
80template class FtPdo<EcPipePdo>;
81template class FtPdo<EcZmqPdo>;
82
83
84#endif
Definition ft_pdo.h:29