Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00025 #include <sr_ronex_drivers/sr_board_0x.h>
00026
00027 #include <ros_ethercat_hardware/ethercat_hardware.h>
00028
00029 #include <sstream>
00030 #include <iomanip>
00031 #include <boost/foreach.hpp>
00032
00033 #include <math.h>
00034
00035
00036 #define ETHERCAT_COMMAND_DATA_ADDRESS 0x1000
00037
00038 PLUGINLIB_EXPORT_CLASS(SrBoard0X, EthercatDevice);
00039
00040 void SrBoard0X::construct(EtherCAT_SlaveHandler *sh, int &start_address)
00041 {
00042 sh_ = sh;
00043
00044
00045
00046
00047
00048
00049 n_digital_outputs = ((sh->get_product_code() & 0x00000F00) >> 8) * 2;
00050 n_digital_inputs = ((sh->get_product_code() & 0x00000F00) >> 8);
00051 n_analog_outputs = ((sh->get_product_code() & 0x000000F0) >> 4);
00052 n_analog_inputs = ((sh->get_product_code() & 0x0000000F));
00053 n_PWM_outputs = n_digital_outputs / 2;
00054
00055 command_base_ = start_address;
00056 command_size_ = ((n_digital_outputs/16 + 1) * 2) + (n_PWM_outputs * 4) + (n_analog_outputs * 2);
00057
00058 start_address += command_size_;
00059
00060 status_base_ = start_address;
00061 status_size_ = ((n_digital_inputs/16 + 1) * 2) + (n_analog_inputs * 2);
00062
00063 start_address += status_size_;
00064
00065
00066
00067
00068
00069
00070 ROS_INFO("First FMMU (command) : start_address : 0x%08X ; size : %3d bytes ; phy addr : 0x%08X", command_base_,
00071 command_size_, static_cast<int>(ETHERCAT_COMMAND_DATA_ADDRESS) );
00072 EC_FMMU *commandFMMU = new EC_FMMU( command_base_,
00073 command_size_,
00074 0x00,
00075 0x07,
00076 ETHERCAT_COMMAND_DATA_ADDRESS,
00077 0x00,
00078 false,
00079 true,
00080 true);
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 ROS_INFO("Second FMMU (status) : start_address : 0x%08X ; size : %3d bytes ; phy addr : 0x%08X", status_base_,
00094 status_size_, static_cast<int>(ETHERCAT_COMMAND_DATA_ADDRESS + command_size_) );
00095 EC_FMMU *statusFMMU = new EC_FMMU( status_base_,
00096 status_size_,
00097 0x00,
00098 0x07,
00099 ETHERCAT_COMMAND_DATA_ADDRESS + (command_size_ * 4),
00100 0x00,
00101 true,
00102 false,
00103 true);
00104
00105
00106 EtherCAT_FMMU_Config *fmmu = new EtherCAT_FMMU_Config(2);
00107
00108 (*fmmu)[0] = *commandFMMU;
00109 (*fmmu)[1] = *statusFMMU;
00110
00111 sh->set_fmmu_config(fmmu);
00112
00113 EtherCAT_PD_Config *pd = new EtherCAT_PD_Config(2);
00114
00115 (*pd)[0] = EC_SyncMan(ETHERCAT_COMMAND_DATA_ADDRESS, command_size_, EC_BUFFERED, EC_WRITTEN_FROM_MASTER);
00116 (*pd)[1] = EC_SyncMan(ETHERCAT_COMMAND_DATA_ADDRESS + (command_size_ * 4), status_size_, EC_BUFFERED);
00117
00118
00119 (*pd)[0].ChannelEnable = true;
00120 (*pd)[0].ALEventEnable = true;
00121 (*pd)[0].WriteEvent = true;
00122
00123 (*pd)[1].ChannelEnable = true;
00124
00125 sh->set_pd_config(pd);
00126
00127 ROS_INFO("status_size_ : %d ; command_size_ : %d", status_size_, command_size_);
00128
00129 ROS_INFO("Finished constructing the SrBoard0X driver");
00130 }
00131
00132 void SrBoard0X::packCommand(unsigned char *buffer, bool halt, bool reset)
00133 {
00134 cod_decod_manager_->build_command(buffer);
00135 }
00136
00137 bool SrBoard0X::unpackState(unsigned char *this_buffer, unsigned char *prev_buffer)
00138 {
00139 unsigned char *status_data_ptr;
00140
00141
00142 status_data_ptr = this_buffer + command_size_;
00143
00144 cod_decod_manager_->update(status_data_ptr);
00145
00146 return true;
00147 }
00148
00149