#ifndef __SERVOCOM__APP_H__ #define __SERVOCOM__APP_H__ #define SERVO_AXISNUM 3 #define X_USERING_TARR 1 #define Y_USERING_TARR 1 #define Z_USERING_TARR 1 #define SERVO_COM_CMD_NUMBER 15 #define SERVO_X_COM_ID 1 //x轴,Y轴同时用时ID,不能一样。 #define SERVO_Y_COM_ID 2 #define SERVO_Z_COM_ID 3 #define SERVO_ADDR_HAND 0x0200+0 //伺服握手地址 #define SERVO_ADDR_DI_MODE_SW 0x0300+4 //模式切换功能配置,原故障清除的功能更过来的,极性修改0x0309,一起修改 #define SERVO_ADDR_DO_TARR_OV 0x0300+24 //转矩到达功能设置,原故障告警的功能更改过来,极性修改0x0325,一起修改 #define SERVO_ADDR_MODE_SET 0x0400+0 //模式设置,要用扭矩模式+位置模式4,正常时位置模式1 #define SERVO_ADDR_MOTOR_DIR 0x0400+1 //电机旋转方向 #define SERVO_ADDR_ENCODE_FB 0x0900+36 //位置反馈计数(编码器),32位。 #define SERVO_ADDR_TARR_SEL 0x1500+0 //转矩指令来源选择,设置为0;0x1501,设置为,0,内部限制; #define SERVO_ADDR_LIMIT_SET 0x1500+5 //转矩下的转矩限制1和2 #define SERVO_ADDR_SPEED_SET 0x1500+11 //转矩模式下正向速度限制。0x1512,负向速度选择。 #define SERVO_ADDR_TARBASE_SET 0x1500+16 //转矩模式下的转矩基准值设置 #define SERVO_ADDR_ALARM_REST 0x2000+3 //伺服故障复位,(有些故障无法复位) #define SERVO_ADDR_SERVO_RESTART 0x2000+4 //伺服软件重启 #define SERVO_ADDR_ALARM_CODE 0x2100+8 //当前故障码 #define SERVO_ADDR_VDI_VALUE 0x2000+50 //VDI的设置数值 2050 #define SERVO_ADDR_VDI_USE 0x2300+0 //VDI使能,2300~23013 #define DI__FUNCTION_POSTARRSEL 24 //位置+转矩切换 #define DI__FUNCTION_TARRSEL 14 //转矩选择 #define DI_NCLOSE 1 //常闭 #define DI_NOPEN 0 //常开 #define DO_FUNCTION_VALUE 9 //扭矩达到输出 #define VDI_SON_FUNCTION 1 //VDI伺服使能 #define VDI_CLRENCODE_FUNCTION 4 //VDI清除位置超差 #define RUN_MODE 0 //1 //0为扭矩+位置模式、1为扭矩模式 #define CTRL_TARR_MODE 2 //模式设置为2,转矩模式 #define CTRL_POSTOTARR_MODE 5 //模式设置为5,扭矩+位置模式 #define HANDSHAKE 1 //伺服握手 #define DI_MODE_SW 2 //配置DI5为转矩模式+位置模式的切换输入。 #define DO_TARR_SW 3 //配置DO3为转矩到达输出 #define CTRL_MODE_SET 4 //伺服控制模式设置 #define MOTOR_DIR_SET 5 //电机旋转方向设置。 #define TARR_SOURCE_SEL 6 //转矩指令来源 #define TARR_LIMIT12_SET 7 //转矩下速度选择 #define SPEED_LIMIT_SET 8 //转矩下速度限制 #define TARR_BASE_SET 9 //转矩基准值 #define ALARM_REST 10 //伺服故障复位 #define SERVO_RESTART 11 //伺服软件重启 #define ALARM_CODE 12 //伺服故障码 #define ENCODE_FB 13 //编码器反馈 #define VDI_VALUE_SET 14 //VDI数值设置 #define VDI_CONFIG_SET 15 //VDI配置 #define START_SPEED user_datas[600] #define STOP_SPEED user_datas[601] #define LOW_SPEED user_datas[602] #define HIGH_SPEED user_datas[603] #define CHANGE_SPEED user_datas[604] #define SERVO_STEP user_datas[605] #define TARR_VALUE user_datas[606] #define LIMIT_SPEED user_datas[607] #define CUR_SPEED user_datas[608] #define ACCDECPULSE user_datas[609] #define SERVO_X_ALARMCODE user_datas[610] #define SERVO_POSTOTARR_MODE 0//伺服位置模式+转矩模式,转矩切换用 #define SERVO_TARR_MODE 1//伺服转矩模式,用IO切换,转矩限制 #define POS_MODE 0 //位置模式 #define TARR_MODE 1 //转矩模式 #define TARR_MODE_MAXLIMIT 1 #define TARR_MODE_MINLIMIT 0 #define ENCODE_17BIT 0x20000 //17位编码值 #define SERVO_TARR_CW 0 //扭矩方式正转 #define SERVO_TARR_CCW 1 //扭矩方式正转 typedef struct servo_com_cmd_t { char cmdcode; //命令编号 unsigned short address; //读、写的目标地址 unsigned short number; //读、写长度 unsigned char * value; //对于读操作,是数值,对于写操作是要发送的值 char id; //设备ID char cmd; //发送的命令 char dir; //0单次,1循环 int respone_timeout; //响应超时时间 void (* servo_on_respone)(struct modbus_master_cmd * cmd, unsigned char * respone, int length); //回调函数 } servo_com_cmd_t; typedef struct servo_param_t { unsigned short handshake; //握手数值,读取伺服版本-1 unsigned short di_function_set; //设置DI功能码,-2 unsigned short di_polarity; //设置DI极性,0为常开、1为常闭。-3 unsigned short do_function_set; //设置DO功能码, unsigned short do_polarity; //设置DO极性,0为常开、1为常闭。 unsigned short ctrl_mode_set; //模式设置,扭矩模式+位置模式4,正常时位置模式1。 unsigned short motor_dir_set; //电机方向设置 unsigned short tarr_source_sel; //转矩指令来源选择 unsigned short tarr_modea_sel; //转矩指令A来源选择 unsigned short tarr_modeb_sel; //转矩指令B来源选择 unsigned short tarr_limit_sel; //转矩限制源的选择 unsigned short tarr_ai_sel; //转矩模拟量的选择 unsigned short tarr_Plimit1_sel; //正转转矩限制1; unsigned short tarr_Nlimit1_sel; //反转转矩限制1; unsigned short tarr_Plimit2_sel; //正转转矩限制2; unsigned short tarr_Nlimit2_sel; //反转转矩限制2; unsigned short speed_limit_sel; //转速模式下速度限制来源选择 unsigned short speed_ai_sel; unsigned short speed_plimit_set; //转矩模式下正向速度限制。 unsigned short speed_nlimit_set; //转矩模式下正向速度限制。 int tarr_limit_set; //转矩模式下的转矩限制设置。 unsigned short tarr_basis; //转矩基准值; unsigned short tarr_basis_up; //tarr_basis+tarr_basis_up为有效值 unsigned short tarr_basis_dw; //tarr_basi+starr_basis_dw为无效 unsigned short alarmrest; //伺服故障复位,(有些故障无法复位) unsigned short restart; //伺服重新启动; unsigned short alarmcode; //告警编码 unsigned short vdi_value; //VDI的输入数值 unsigned short vdi_use; //vdi使用 unsigned short vdi_init; //vdi上电初始值 unsigned short vdo_use; //vdo使用 unsigned short vdo_init; //vdo默认值 unsigned short vdi1_function_set; //vdi1-功能 unsigned short vdi1_polarity; //vdi1-极性 unsigned short vdi2_function_set; //vdi2-功能 unsigned short vdi2_polarity; //vdi2-极性 unsigned short vdi3_function_set; //vdi3-功能 unsigned short vdi3_polarity; //vdi3-极性 unsigned short vdi4_function_set; //vdi4-功能 unsigned short vdi4_polarity; //vdi4-极性 long encode; //编码器反馈; long precode; //编码器反馈上一次的值 unsigned short init_step; //初始话步骤 unsigned char cmd_fb[SERVO_COM_CMD_NUMBER+1];//命令通讯反馈 unsigned char IO_TO_COM; //IO与伺服通讯标志 sw_timer_t timer; //定时器 unsigned char com_number; //通讯次数 unsigned char com_ok_number; //通讯连接次数 unsigned char alarm_flag; //伺服故障标志 unsigned char set_tarr_OKflag; ////0失败,为1为设置1个,2为成功 unsigned short cycle_pulse; //细分 unsigned short cycle_length; //周长 unsigned char alarm_Reverse; //伺服告警电平,0,为常开,1为常闭。 unsigned char run_mode; //0为扭矩+位置模式、1为扭矩模式 unsigned char read_alarm_en; //告警读取使能; unsigned char read_encode_en; //告警编码使能; } servo_param_t; void set_com_servo_param(unsigned short axis,unsigned short cycle_pluse,unsigned short cycle_length); void servo_com_respone(modbus_master_cmd_t *cmd, unsigned char *respone, int length); void read_encode_value_cmd(unsigned short axis,unsigned short times); int axis_set_com_pos(unsigned short axis,long pos ); int set_servo_postotarr_limit(unsigned short axis,int tarr, unsigned short P_freq,unsigned short N_freq, unsigned short dir); int set_servo_tarr_limit(unsigned short axis,int maxtarr,int mintarr, unsigned short P_freq,unsigned short N_freq, unsigned short dir); int servo_com_run(void); int get_alarm_code(unsigned short axis); int servo_com_get_alarm(unsigned short axis); int clr_com_servo_alarm(unsigned short axis); long get_encode_value(unsigned short axis); int get_tarr_set(unsigned short axis); void set_com_alarm_reverse(unsigned short axis,int value); int GetServoComState(unsigned short axis); void SetServoComUse(unsigned short axis,unsigned short enable); void ReadServoAlarm_Enable(unsigned short axis,unsigned short en); void ReadServoEncode_Enable(unsigned short axis,unsigned short en); void Set_VDI_Value(unsigned short axis,unsigned short vdi_value); extern servo_param_t servo_x,servo_y,servo_z; #endif