00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00032 #include <termios.h>
00033 #include <sys/ioctl.h>
00034 #include <unistd.h>
00035 #include <termio.h>
00036 #include <fcntl.h>
00037 #include <string.h>
00038 #include <stdio.h>
00039 #include <crc.h>
00040 #include <timer.h>
00041
00045 typedef struct{
00047 int baudrate;
00048
00050 int sys_config;
00052 int cur_reg_gain_p;
00054 int cur_reg_gain_i;
00056 int max_cur_output;
00058 int speed_reg_gain_p;
00060 int speed_reg_gain_i;
00062 int internal_param1;
00064 int internal_param2;
00066 int internal_param3;
00068 int max_speed_error;
00070 int setting_unit_gain;
00072 int setting_unit_offset;
00074 int setting_unit_delay;
00076 int peak_current;
00078 int max_cont_current;
00080 int therm_const;
00082 int max_speed;
00084 int acceleration;
00086 int speed_constant;
00088 int enc_resolution;
00090 int pole_pair_number;
00092 int internal_param4;
00094 int rpm2qc_factor;
00096 int index_offset;
00098 int pwm_period;
00100 int max_duty_cycle;
00102 int cur_det_ph_u_offset;
00104 int cur_det_ph_v_offset;
00106 int ad_conv_offset;
00108 int can_module_id;
00110 int can_service_id;
00112 int can_rx_pdo_id;
00114 int can_tx_pdo_id;
00116 int can_bcr1;
00118 int can_bcr2;
00120 int can_op_mode;
00122 int can_rx_sdo_id;
00124 int can_tx_sdo_id;
00126 int can_rtr0_id;
00128 int can_rtr1_id;
00130 int can_config;
00132 int internal_param5;
00134 int error_proc;
00136 int max_speed_curr;
00138 int hall_angle_offs;
00139 }TYPE_des_sysparam;
00140
00144 enum ENUM_DES_SYS_PARAMS
00145 {
00146 BAUDRATE = 0,
00147 SYS_CONFIG = 1,
00148 CUR_REG_GAIN_P = 2,
00149 CUR_REG_GAIN_I = 3,
00150 MAX_CUR_OUTPUT = 4,
00151 SPEED_REG_GAIN_P = 5,
00152 SPEED_REG_GAIN_I = 6,
00153 INTERNAL_PARAM1 = 7,
00154 INTERNAL_PARAM2 = 8,
00155 INTERNAL_PARAM3 = 9,
00156 MAX_SPEED_ERROR = 10,
00157 SETTING_UNIT_GAIN = 11,
00158 SETTING_UNIT_OFFSET = 12,
00159 SETTING_UNIT_DELAY = 13,
00160 PEAK_CURRENT = 14,
00161 MAX_CONT_CURRENT = 15,
00162 THERM_CONST = 16,
00163 MAX_SPEED = 17,
00164 ACCELERATION = 18,
00165 SPEED_CONSTANT = 19,
00166 ENC_RESOLUTION = 20,
00167 POLE_PAIR_NUMBER = 21,
00168 INTERNAL_PARAM4 = 22,
00169 RPM_2QC_FACTOR = 23,
00170 INDEX_OFFSET = 24,
00171 PWM_PERIOD = 25,
00172 MAX_DUTY_CYCLE = 26,
00173 CUR_DET_PH_U_OFFSET = 27,
00174 CUR_DET_PH_V_OFFSET = 28,
00175 AD_CONV_OFFSET = 29,
00176 CAN_MODULE_ID = 30,
00177 CAN_SERVICE_ID = 31,
00178 CAN_RX_PDO_ID = 32,
00179 CAN_TX_PDO_ID = 33,
00180 CAN_BCR1 = 34,
00181 CAN_BCR2 = 35,
00182 CAN_OP_MODE = 36,
00183 CAN_RX_SDO_ID = 37,
00184 CAN_TX_SDO_ID = 38,
00185 CAN_RTR0_ID = 39,
00186 CAN_RTR1_ID = 40,
00187 CAN_CONFIG = 41,
00188 INTERNAL_PARAM5 = 42,
00189 ERROR_PROC = 43,
00190 MAX_SPEED_CURR = 44,
00191 HALL_ANGLE_OFFS = 45
00192 };
00193
00197 typedef struct{
00199 int sys_op_status;
00201 int actual_mean_cur_d;
00203 int actual_mean_cur_q;
00205 int cur_setting_val;
00207 int rel_rot_pos_rev;
00209 int speed_setting_val;
00211 int actual_mean_speed_val;
00213 int abs_rotor_pos;
00215 int standard_error;
00217 int can_error;
00219 int actual_cur_q;
00221 int actual_speed_val;
00223 int error_hist1;
00225 int error_hist2;
00227 int enc_counter;
00229 int enc_counter_last_ind;
00231 int hall_sens_pat;
00232 }TYPE_DES_status_var;
00233
00237 enum ENUM_DES_STATUS_VAR
00238 {
00239 SYS_OP_STATUS = 128,
00240 ACTUAL_MEAN_CUR_D = 129,
00241 ACTUAL_MEAN_CUR_Q = 130,
00242 CUR_SETTING_VAL = 131,
00243 REL_ROT_POS_REV = 132,
00244 SPEED_SETTING_VAL = 133,
00245 ACTUAL_MEAN_SPEED_VAL = 134,
00246 ABS_ROTOR_POS = 135,
00247 STANDARD_ERROR = 136,
00248 CAN_ERROR = 137,
00249 ACTUAL_CUR_Q = 138,
00250 ACTUAL_SPEED_VAL = 139,
00251 ERROR_HIST1 = 140,
00252 ERROR_HIST2 = 141,
00253 ENC_COUNTER = 142,
00254 ENC_COUNTER_LAST_IND = 143,
00255 HALL_SENS_PAT = 144,
00256 };
00257
00261 typedef struct{
00263 unsigned char OpCode;
00265 unsigned char data[520];
00267 int size;
00269 int crc;
00270 }TYPE_msg_frame;
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282 int InitDES_communication(std::string com_device, int* port);
00283
00284
00285 int calc_crc_16(TYPE_msg_frame* msg);
00286 int write_msg_inbuf(const int port, unsigned char* data, int size);
00287 int check_msg_aceptance(const int port, float wait_time, unsigned char* msg);
00288 int send_OpCode(const int port, unsigned char tries, unsigned char OpCode, char flg);
00289 int send_data(const int port, TYPE_msg_frame* msg, char flg);
00290 int read_buffer(const int port, TYPE_msg_frame* msg, char flg);
00291 int send_msg_frame(const int port, TYPE_msg_frame* msg, char flg);
00292 int DES_ST_read_sys_status(const int port, int* sys_status, char flg);
00293 int DES_ST_read_error(const int port, int* errors, char flg);
00294 int DES_ST_clear_errors(const int port, char flg);
00295 int DES_ST_reset(const int port, char flg);
00296 int DES_ST_enable(const int port, int* newState, char flg);
00297 int DES_SPF_read_temp_param(const int port, int paramNb, int dataFormat, int* response, char flg);
00298 int DES_SPF_set_temp_param(const int port, int paramNb, int dataFormat, int* newValue, char flg);
00299 int DES_SPF_read_all_temp_param(const int port, TYPE_des_sysparam* sysparam, char flg);
00300 int DES_SF_set_velocity(const int port, int newVelocity, char flg);
00301 int DES_SF_set_current(const int port, int newCurrent, char flg);
00302 int DES_SF_stop_motion(const int port, char flg);
00303 int DES_MF_read_velocity_is_must(const int port, int vel_type, int* velocity, int* requested_vel, char flg);
00304 int InitDES(const int port, TYPE_des_sysparam* newSysParam, char, char, char flg);
00305 int stopDES(const int port, char flg);
00306 int DES_set_new_baud(int* port, int baud, char flg);