EtherCAT Client Library Code 0.0.1
EtherCAT Client library that uses different communication protocols with EtherCAT Master server.
Loading...
Searching...
No Matches
pump_pdo.h
1#ifndef __PUMP_PDO__
2#define __PUMP_PDO__
3
4#include <pb_utils.h>
5#include "mechanism/pipe/ec_pipe_pdo.h"
6#include "mechanism/zmq/ec_zmq_pdo.h"
7
8namespace PumpPdoRx{
9 // not used tempExpansionBoard, vesc1SwVer, vesc2SwVer
10 static const std::vector<std::string>name = {"Motor_Current", "Motor_Speed","Pressure1", "Pressure2",
11 "temperature","MOSFET_temperature","motor_temperature",
12 "fault","rtt","op_idx_ack","aux"};
13 static const int pdo_size=11;
14 using pdo_t=std::tuple<float,float,float,float,
15 uint16_t,uint16_t,int16_t,
16 uint16_t,uint16_t,uint16_t,float>;
17 template <typename T>
18 inline bool make_vector_from_tuple(const pdo_t &pdo_tuple,std::vector<T> &pdo_vector){
19 if(pdo_vector.size()!=pdo_size){
20 return false;
21 }
22 pdo_vector[0]= static_cast<T>(std::get<0>(pdo_tuple));
23 pdo_vector[1]= static_cast<T>(std::get<1>(pdo_tuple));
24 pdo_vector[2]= static_cast<T>(std::get<2>(pdo_tuple));
25 pdo_vector[3]= static_cast<T>(std::get<3>(pdo_tuple));
26 pdo_vector[4]= static_cast<T>(std::get<4>(pdo_tuple));
27 pdo_vector[5]= static_cast<T>(std::get<5>(pdo_tuple));
28 pdo_vector[6]= static_cast<T>(std::get<6>(pdo_tuple));
29 pdo_vector[7]= static_cast<T>(std::get<7>(pdo_tuple));
30 pdo_vector[8]= static_cast<T>(std::get<8>(pdo_tuple));
31 pdo_vector[9]= static_cast<T>(std::get<9>(pdo_tuple));
32 pdo_vector[10]= static_cast<T>(std::get<10>(pdo_tuple));
33 return true;
34 }
35};
36
37namespace PumpPdoTx{
38 static const std::vector<std::string>name = {"Pump_Target",
39 "pressure_P_gain","pressure_I_gain", "pressure_D_gain","pressure_I_limit",
40 "fault_ack","SolenoidOut","ts","op_idx_aux","aux"};
41 static const int pdo_size=10;
42 using pdo_t=std::tuple<float,
43 float, float, float, float,
44 uint16_t,uint16_t,uint16_t,uint16_t,float>;
45 template <typename T>
46 inline bool make_vector_from_tuple(const pdo_t &pdo_tuple,std::vector<T> &pdo_vector){
47 if(pdo_vector.size()!=pdo_size){
48 return false;
49 }
50 pdo_vector[0]= static_cast<T>(std::get<0>(pdo_tuple));
51 pdo_vector[1]= static_cast<T>(std::get<1>(pdo_tuple));
52 pdo_vector[2]= static_cast<T>(std::get<2>(pdo_tuple));
53 pdo_vector[3]= static_cast<T>(std::get<3>(pdo_tuple));
54 pdo_vector[4]= static_cast<T>(std::get<4>(pdo_tuple));
55 pdo_vector[5]= static_cast<T>(std::get<5>(pdo_tuple));
56 pdo_vector[6]= static_cast<T>(std::get<6>(pdo_tuple));
57 pdo_vector[7]= static_cast<T>(std::get<7>(pdo_tuple));
58 pdo_vector[8]= static_cast<T>(std::get<8>(pdo_tuple));
59 pdo_vector[9]= static_cast<T>(std::get<9>(pdo_tuple));
60 return true;
61 }
62};
63
64template <class T>
65class PumpPdo: public T{
66
67public:
68
69 PumpPdo(const std::string value,int32_t id, uint32_t type);
70 ~PumpPdo();
71
72 void get_from_pb();
73
74 void set_to_pb();
75
76 PumpPdoRx::pdo_t rx_pdo{};
77 PumpPdoTx::pdo_t tx_pdo{};
78 bool init_rx_pdo=false;
79private:
80 void init_pb();
81};
82
83template < class T >
84inline void PumpPdo<T>::init_pb()
85{
86 uint8_t pb_buf[MAX_PB_SIZE];
87 uint32_t msg_size=0;
88
89 set_to_pb();
90 msg_size = T::pb_tx_pdos.ByteSizeLong();
91 T::pb_tx_pdos.SerializeToArray( (void*)(pb_buf+sizeof(msg_size)), msg_size);
92}
93
94template < class T >
95inline PumpPdo<T>::PumpPdo(const std::string value,int32_t id, uint32_t type):
96 T(id, type, value)
97{
98 init_pb();
99 T::init();
100 T::write_connect();
101};
102
103template < class T >
104inline PumpPdo<T>::~PumpPdo()
105{
106 T::write_quit();
107};
108
109
110template < class T >
111inline void PumpPdo<T>::get_from_pb()
112{
113 std::get<0>(rx_pdo) = T::pb_rx_pdos.mutable_hyqhpu_rx_pdo()->motor_current();
114 std::get<1>(rx_pdo) = T::pb_rx_pdos.mutable_hyqhpu_rx_pdo()->motor_speed();
115 std::get<2>(rx_pdo) = T::pb_rx_pdos.mutable_hyqhpu_rx_pdo()->pressure1();
116 std::get<3>(rx_pdo) = T::pb_rx_pdos.mutable_hyqhpu_rx_pdo()->pressure2();
117 std::get<4>(rx_pdo) = T::pb_rx_pdos.mutable_hyqhpu_rx_pdo()->temperature();
118 std::get<5>(rx_pdo) = T::pb_rx_pdos.mutable_hyqhpu_rx_pdo()->mosfet_temperature();
119 std::get<6>(rx_pdo) = T::pb_rx_pdos.mutable_hyqhpu_rx_pdo()->motor_temperature();
120 std::get<7>(rx_pdo) = T::pb_rx_pdos.mutable_hyqhpu_rx_pdo()->fault();
121 std::get<8>(rx_pdo) = T::pb_rx_pdos.mutable_hyqhpu_rx_pdo()->rtt();
122 std::get<9>(rx_pdo) = T::pb_rx_pdos.mutable_hyqhpu_rx_pdo()->op_idx_ack();
123 std::get<10>(rx_pdo) = T::pb_rx_pdos.mutable_hyqhpu_rx_pdo()->aux();
124
125 if(!init_rx_pdo){
126 init_rx_pdo=true;
127 }
128}
129
130template < class T >
131inline void PumpPdo<T>::set_to_pb()
132{
133 set_pbHeader(T::pb_tx_pdos.mutable_header(), T::name, 0);
134 // Type
135 T::pb_tx_pdos.set_type(iit::advr::Ec_slave_pdo::TX_HYQ_HPU);
136
137 T::pb_tx_pdos.mutable_hyqhpu_tx_pdo()->set_pump_target(std::get<0>(tx_pdo));
138 T::pb_tx_pdos.mutable_hyqhpu_tx_pdo()->set_pressure_p_gain(std::get<1>(tx_pdo));
139 T::pb_tx_pdos.mutable_hyqhpu_tx_pdo()->set_pressure_i_gain(std::get<2>(tx_pdo));
140 T::pb_tx_pdos.mutable_hyqhpu_tx_pdo()->set_pressure_d_gain(std::get<3>(tx_pdo));
141 T::pb_tx_pdos.mutable_hyqhpu_tx_pdo()->set_pressure_i_limit(std::get<4>(tx_pdo));
142 T::pb_tx_pdos.mutable_hyqhpu_tx_pdo()->set_fault_ack(std::get<5>(tx_pdo));
143 T::pb_tx_pdos.mutable_hyqhpu_tx_pdo()->set_solenoidout(std::get<6>(tx_pdo));
144 T::pb_tx_pdos.mutable_hyqhpu_tx_pdo()->set_ts(std::get<7>(tx_pdo));
145 T::pb_tx_pdos.mutable_hyqhpu_tx_pdo()->set_op_idx_aux(std::get<8>(tx_pdo));
146 T::pb_tx_pdos.mutable_hyqhpu_tx_pdo()->set_aux(std::get<9>(tx_pdo));
147}
148
149template class PumpPdo<EcPipePdo>;
150template class PumpPdo<EcZmqPdo>;
151
152#endif
Definition pump_pdo.h:65