EtherCAT Client Library Code 0.0.1
EtherCAT Client library that uses different communication protocols with EtherCAT Master server.
Loading...
Searching...
No Matches
cia402_pdo.h
1#ifndef __CIA402_PDO__
2#define __CIA402_PDO__
3
4#include "mechanism/protobuf/motor/motor_pdo.h"
5
6template <class T>
7class Cia402Pdo: public MotorPdo<T>{
8
9public:
10
11 Cia402Pdo(const std::string ,int32_t id);
12 Cia402Pdo(const std::string ,int32_t id, uint32_t type);
13 ~Cia402Pdo();
14
15 void get_from_pb(void) override;
16
17 void set_to_pb(void) override;
18};
19
20template < class T >
21inline Cia402Pdo<T>::Cia402Pdo(std::string value,int id):
22 MotorPdo<T>(value,id)
23{
24 MotorPdo<T>::init_pb();
25};
26
27template < class T >
28inline Cia402Pdo<T>::Cia402Pdo(std::string value,int32_t id, uint32_t type):
29 MotorPdo<T>(value,id,type)
30{
31 MotorPdo<T>::init_pb();
32};
33
34template < class T >
35inline Cia402Pdo<T>::~Cia402Pdo()
36{
37
38};
39
40
41template < class T >
42inline void Cia402Pdo<T>::get_from_pb()
43{
44 std::get<0>(MotorPdo<T>::rx_pdo) = T::pb_rx_pdos.mutable_cia402_rx_pdo()->statusword();
45 std::get<1>(MotorPdo<T>::rx_pdo) = T::pb_rx_pdos.mutable_cia402_rx_pdo()->link_pos();
46 std::get<2>(MotorPdo<T>::rx_pdo) = T::pb_rx_pdos.mutable_cia402_rx_pdo()->motor_pos();
47 std::get<3>(MotorPdo<T>::rx_pdo) = T::pb_rx_pdos.mutable_cia402_rx_pdo()->link_vel();
48 std::get<4>(MotorPdo<T>::rx_pdo) = T::pb_rx_pdos.mutable_cia402_rx_pdo()->motor_vel();
49 std::get<5>(MotorPdo<T>::rx_pdo) = T::pb_rx_pdos.mutable_cia402_rx_pdo()->torque();
50 std::get<6>(MotorPdo<T>::rx_pdo) = T::pb_rx_pdos.mutable_cia402_rx_pdo()->current();
51 std::get<7>(MotorPdo<T>::rx_pdo) = T::pb_rx_pdos.mutable_cia402_rx_pdo()->motor_temp();
52 std::get<8>(MotorPdo<T>::rx_pdo) = T::pb_rx_pdos.mutable_cia402_rx_pdo()->drive_temp()*0.001;
53 std::get<9>(MotorPdo<T>::rx_pdo) = T::pb_rx_pdos.mutable_cia402_rx_pdo()->error_code();
54
55 auto& fault_info = std::get<10>(MotorPdo<T>::rx_pdo);
56 const auto& error_report = T::pb_rx_pdos.mutable_cia402_rx_pdo()->error_report();
57
58 const auto count = std::min(error_report.size(), fault_info.size() - 1);
59 std::copy_n(error_report.data(), count, fault_info.data());
60 fault_info[count] = '\0';
61
62 std::get<11>(MotorPdo<T>::rx_pdo) = 0;
63 std::get<12>(MotorPdo<T>::rx_pdo) = T::pb_rx_pdos.mutable_cia402_rx_pdo()->demanded_pos();
64 std::get<13>(MotorPdo<T>::rx_pdo) = T::pb_rx_pdos.mutable_cia402_rx_pdo()->demanded_vel();
65 std::get<14>(MotorPdo<T>::rx_pdo) = T::pb_rx_pdos.mutable_cia402_rx_pdo()->demanded_torque();
66 std::get<15>(MotorPdo<T>::rx_pdo) = T::pb_rx_pdos.mutable_cia402_rx_pdo()->demanded_current();
67
68 if(!MotorPdo<T>::init_rx_pdo){
69 MotorPdo<T>::init_rx_pdo=true;
70 }
71}
72
73template < class T >
74inline void Cia402Pdo<T>::set_to_pb()
75{
76 set_pbHeader(T::pb_tx_pdos.mutable_header(), T::name, 0);
77 // Type
78 T::pb_tx_pdos.set_type(iit::advr::Ec_slave_pdo::TX_CIA402);
79
80 T::pb_tx_pdos.mutable_cia402_tx_pdo()->set_target_pos(std::get<1>(MotorPdo<T>::tx_pdo));
81 T::pb_tx_pdos.mutable_cia402_tx_pdo()->set_target_vel(std::get<2>(MotorPdo<T>::tx_pdo));
82 T::pb_tx_pdos.mutable_cia402_tx_pdo()->set_target_torque(std::get<3>(MotorPdo<T>::tx_pdo));
83 T::pb_tx_pdos.mutable_cia402_tx_pdo()->set_target_current(std::get<3>(MotorPdo<T>::tx_pdo));
84
85 T::pb_tx_pdos.mutable_cia402_tx_pdo()->set_gain_0(std::get<4>(MotorPdo<T>::tx_pdo));
86 T::pb_tx_pdos.mutable_cia402_tx_pdo()->set_gain_1(std::get<5>(MotorPdo<T>::tx_pdo));
87 T::pb_tx_pdos.mutable_cia402_tx_pdo()->set_gain_2(std::get<6>(MotorPdo<T>::tx_pdo));
88 T::pb_tx_pdos.mutable_cia402_tx_pdo()->set_gain_3(std::get<7>(MotorPdo<T>::tx_pdo));
89 T::pb_tx_pdos.mutable_cia402_tx_pdo()->set_gain_4(std::get<8>(MotorPdo<T>::tx_pdo));
90}
91#endif
Definition motor_pdo.h:69