12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025 |
- #include "global.h"
- #include "AllServoDrv.h"
- axis_object_t *axis_x;
- axis_object_t *axis_y;
- axis_object_t *axis_z;
- float XGearRatio = 1,YGearRatio = 1,ZGearRatio = 1;
- void SetDir(unsigned short axis, unsigned short dir)
- {
- switch(axis)
- {
- case X_AXIS:
- if(dir)
- axis_cw(axis_x);
- else
- axis_ccw(axis_x);
- break;
- case Y_AXIS:
- if(dir)
- axis_cw(axis_y);
- else
- axis_ccw(axis_y);
- break;
- case Z_AXIS:
- if(dir)
- axis_cw(axis_z);
- else
- axis_ccw(axis_z);
- break;
- default:;
- }
- }
- void SetDirReverse(unsigned short axis, int value)
- {
- switch(axis)
- {
- case X_AXIS:
- if(value)
- axis_set_parameter (axis_x,AXIS_DIR_REVERSE,1);
- else
- axis_set_parameter (axis_x,AXIS_DIR_REVERSE,0);
- break;
- case Y_AXIS:
- if(value)
- axis_set_parameter (axis_y,AXIS_DIR_REVERSE,1);
- else
- axis_set_parameter (axis_y,AXIS_DIR_REVERSE,0);
- break;
- case Z_AXIS:
- if(value)
- axis_set_parameter (axis_z,AXIS_DIR_REVERSE,1);
- else
- axis_set_parameter (axis_z,AXIS_DIR_REVERSE,0);
- break;
- default:;
- }
- }
- unsigned char GetDir(unsigned short axis)
- {
- switch(axis)
- {
- case X_AXIS: return axis_x->outputs.dir;break;
- case Y_AXIS: return axis_y->outputs.dir;break;
- case Z_AXIS: return axis_z->outputs.dir;break;
- default:return axis_x->outputs.dir;
- }
- }
- void SetEn(unsigned short axis, unsigned short ena)
- {
- switch(axis)
- {
- case X_AXIS:
- if(ena)
- axis_enable(axis_x);
- else
- axis_disable(axis_x);
- break;
- case Y_AXIS:
- if(ena)
- axis_enable(axis_y);
- else
- axis_disable(axis_y);
- break;
- case Z_AXIS:
- if(ena)
- axis_enable(axis_z);
- else
- axis_disable(axis_z);
- break;
- default:;
- }
- }
- void SetEnReverse(unsigned short axis, int value)
- {
- switch(axis)
- {
- case X_AXIS:
- if(value)
- axis_set_parameter (axis_x,AXIS_EN_REVERSE,1);
- else
- axis_set_parameter (axis_x,AXIS_EN_REVERSE,0);
- break;
- case Y_AXIS:
- if(value)
- axis_set_parameter (axis_y,AXIS_EN_REVERSE,1);
- else
- axis_set_parameter (axis_y,AXIS_EN_REVERSE,0);
- break;
- case Z_AXIS:
- if(value)
- axis_set_parameter (axis_z,AXIS_EN_REVERSE,1);
- else
- axis_set_parameter (axis_z,AXIS_EN_REVERSE,0);
- break;
- default:;
- }
- }
- //设置伺服告警的极性
- void SetAlarmReverse(unsigned short axis, int value)
- {
- switch(axis)
- {
- case X_AXIS:
- if(value){
- axis_set_parameter (axis_x,AXIS_ALARM_REVERSE,1);
- }
- else{
- axis_set_parameter (axis_x,AXIS_ALARM_REVERSE,0);
- }
- break;
- case Y_AXIS:
- if(value){
- axis_set_parameter (axis_y,AXIS_ALARM_REVERSE,1);
- }
- else{
- axis_set_parameter (axis_y,AXIS_ALARM_REVERSE,0);
- }
- break;
- case Z_AXIS:
- if(value){
- axis_set_parameter (axis_z,AXIS_ALARM_REVERSE,1);
- }
- else{
- axis_set_parameter (axis_z,AXIS_ALARM_REVERSE,0);
- }
- break;
- default:;
- }
- }
- unsigned char GetEn(unsigned short axis)
- {
- switch(axis)
- {
- case X_AXIS:return (axis_x->outputs.enable);break;
- case Y_AXIS:return (axis_y->outputs.enable);break;
- case Z_AXIS:return (axis_z->outputs.enable);break;
- default:return (axis_x->outputs.enable);
- }
-
- }
- unsigned char GetAlarm(unsigned short axis)
- {
- switch(axis)
- {
- case X_AXIS:
- if(axis_x->inputs.alarm_reverse){
- if(hw_pwm_get_alr(axis_x->axis_no))return 1;else return 0;
- }
- else {
- if(hw_pwm_get_alr(axis_x->axis_no))return 0;else return 1;
- }
- break;
- case Y_AXIS:
- if(axis_y->inputs.alarm_reverse){
- if(hw_pwm_get_alr(axis_y->axis_no))return 1;else return 0;
- }
- else {
- if(hw_pwm_get_alr(axis_y->axis_no))return 0;else return 1;
- }
- break;
- case Z_AXIS:
- if(axis_z->inputs.alarm_reverse){
- if(hw_pwm_get_alr(axis_z->axis_no))return 1;else return 0;
- }
- else {
- if(hw_pwm_get_alr(axis_z->axis_no))return 0;else return 1;
- }
- break;
- default:return hw_pwm_get_alr(axis_x->axis_no);
- }
- }
- void SetClr(unsigned short axis, unsigned short clr)
- {
- switch(axis)
- {
- case X_AXIS:
- hw_pwm_set_clr(axis_x->axis_no, clr);
- break;
- case Y_AXIS:
- hw_pwm_set_clr(axis_y->axis_no, clr);
- break;
- case Z_AXIS:
- hw_pwm_set_clr(axis_z->axis_no, clr);
- break;
- default:
- break;
- }
-
- }
- //脉冲转化为距离
- long PulseToPos(unsigned short axis, long pulse)
- {
- float pulse_buff;
- pulse_buff = pulse;
- switch(axis)
- {
- case X_AXIS: return (long)(pulse_buff/XGearRatio);break;
- case Y_AXIS: return (long)(pulse_buff/YGearRatio);break;
- case Z_AXIS: return (long)(pulse_buff/ZGearRatio);break;
- default:return (long)(pulse_buff/XGearRatio);;
- }
- }
- //距离转化为脉冲
- long PosToPulse(unsigned short axis, long pos)
- {
- float pos_buff;
- pos_buff = pos;
- switch(axis)
- {
- case X_AXIS: return (long)(pos_buff*XGearRatio);break;
- case Y_AXIS: return (long)(pos_buff*YGearRatio);break;
- case Z_AXIS: return (long)(pos_buff*ZGearRatio);break;
- default:return (long)(pos_buff*XGearRatio);
- }
- }
- //设置真实位置
- void SetPos(unsigned short axis, long pos)
- {
- switch(axis)
- {
- case X_AXIS:
- axis_set_parameter(axis_x, AXIS_POSITION, PosToPulse(axis, pos));
- break;
- case Y_AXIS:
- axis_set_parameter(axis_y, AXIS_POSITION, PosToPulse(axis, pos));
- break;
- case Z_AXIS:
- axis_set_parameter(axis_z, AXIS_POSITION, PosToPulse(axis, pos));
- break;
- default:;
- }
- }
- //获取真实位置
- long GetPos(unsigned short axis)
- {
- switch(axis)
- {
- case X_AXIS:
- {
- return PulseToPos(axis, axis_get_parameter(axis_x, AXIS_POSITION));
- }break;
- case Y_AXIS:
- {
- return PulseToPos(axis, axis_get_parameter(axis_y, AXIS_POSITION));
- }break;
- case Z_AXIS:
- {
- return PulseToPos(axis, axis_get_parameter(axis_z, AXIS_POSITION));
- }break;
- default:;
- }
- return 0;
- }
- //获取当前速度
- unsigned long GetCurSpeed(unsigned short axis)
- {
- switch(axis)
- {
- case X_AXIS:
- axis_x->cur_speed=axis_x->clock/axis_x->cur_reg_value;
- return axis_x->cur_speed; break;
- case Y_AXIS:
- axis_y->cur_speed=axis_y->clock/axis_y->cur_reg_value;
- return axis_y->cur_speed; break;
- case Z_AXIS:
- axis_z->cur_speed=axis_z->clock/axis_z->cur_reg_value;
- return axis_z->cur_speed; break;
- default:
- axis_x->cur_speed=axis_x->clock/axis_x->cur_reg_value;
- return axis_x->cur_speed; break;
- }
- // return 0;
- }
- //获取设置速度
- unsigned long GetSetSpeed(unsigned short axis)
- {
- return 0;
- }
- //获取脉冲状态
- unsigned long GetState(unsigned short axis)
- {
- return 0;
- }
- //获取脉冲状态
- unsigned long SetState(unsigned short axis,unsigned short state)
- {
- return 0;
- }
- //获取剩余脉冲数
- unsigned long GetRemainPulse(unsigned short axis)
- {
- return 0;
- }
- //设置脉冲数
- unsigned long SetPulse(unsigned short axis,unsigned long pulse)
- {
- return 0;
- }
- //设置起动速度
- void SetStartSpeed(unsigned short axis,unsigned short speed)
- {
- switch(axis)
- {
- case X_AXIS:axis_set_parameter(axis_x, AXIS_START_SPEED,speed);break;
- case Y_AXIS:axis_set_parameter(axis_y, AXIS_START_SPEED,speed);break;
- case Z_AXIS:axis_set_parameter(axis_z, AXIS_START_SPEED,speed);break;
- default:;
- }
- }
- //设置最低速度
- void SetMinSpeed(unsigned short axis,unsigned short speed)
- {
- }
- void SetAccTime(unsigned short axis,unsigned short acc_time)
- {
- switch(axis)
- {
- case X_AXIS:axis_set_parameter(axis_x, AXIS_ACC_TIME,acc_time);break;
- case Y_AXIS:axis_set_parameter(axis_y, AXIS_ACC_TIME,acc_time);break;
- case Z_AXIS:axis_set_parameter(axis_z, AXIS_ACC_TIME,acc_time);break;
- default:;
- }
- }
- void SetDecTime(unsigned short axis,unsigned short dec_time)
- {
- switch(axis)
- {
- case X_AXIS:axis_set_parameter(axis_x, AXIS_DEC_TIME,dec_time);break;
- case Y_AXIS:axis_set_parameter(axis_y, AXIS_DEC_TIME,dec_time);break;
- case Z_AXIS:axis_set_parameter(axis_z, AXIS_DEC_TIME,dec_time);break;
- default:;
- }
- }
- void SetStopSelect(unsigned short axis,unsigned short Select_Flag)
- {
- switch(axis)
- {
- case X_AXIS:axis_set_parameter(axis_x, AXIS_PP_STOP_SELECT,Select_Flag);break;
- case Y_AXIS:axis_set_parameter(axis_y, AXIS_PP_STOP_SELECT,Select_Flag);break;
- case Z_AXIS:axis_set_parameter(axis_z, AXIS_PP_STOP_SELECT,Select_Flag);break;
- default:;
- }
- }
- //运动当中改变速度
- void AxisChangeSpeed(unsigned short axis,unsigned short speed)
- {
- switch(axis)
- {
- case X_AXIS:
- axis_pv_change_speed(axis_x,speed);
- break;
- case Y_AXIS:
- axis_pv_change_speed(axis_y,speed);
- break;
- case Z_AXIS:
- axis_pv_change_speed(axis_z,speed);
- break;
- default:;
- }
- }
- //固定减速距离停止
- void AxisDecStopPos(unsigned short axis,unsigned long pos)
- {
- switch(axis)
- {
- case X_AXIS: axis_stop_at(axis_x,PosToPulse(X_AXIS,pos));break;
- case Y_AXIS: axis_stop_at(axis_y,PosToPulse(Y_AXIS,pos));break;
- case Z_AXIS: axis_stop_at(axis_z,PosToPulse(Z_AXIS,pos));break;
- default:;
- }
- }
- //减速停
- void AxisDecStop(unsigned short axis)
- {
- switch(axis)
- {
- case X_AXIS:
- axis_stop(axis_x);break;
- case Y_AXIS:
- axis_stop(axis_y);break;
- case Z_AXIS:
- axis_stop(axis_z);break;
- default:
- break;
- }
- }
- //急停
- void AxisEgmStop(unsigned short axis)
- {
- switch(axis)
- {
- case X_AXIS:
- {
- axis_emgstop(axis_x);
- }break;
- case Y_AXIS:
- {
- axis_emgstop(axis_y);
- }break;
- case Z_AXIS:
- {
- axis_emgstop(axis_z);
- }break;
- default:
- break;
- }
- }
- //移动绝对位置
- void AxisMovePoint(unsigned short axis,unsigned short speed,long pos)
- {
- switch(axis)
- {
- case X_AXIS: axis_pp(axis_x, 1, PosToPulse(X_AXIS,pos),speed,0);break;
- case Y_AXIS: axis_pp(axis_y, 1, PosToPulse(Y_AXIS,pos),speed,0);break;
- case Z_AXIS: axis_pp(axis_z, 1, PosToPulse(Z_AXIS,pos),speed,0);break;
- default:;
- }
- }
- //移动绝对位置带加减速
- void AxisMovePointAccDec(unsigned short axis,unsigned short speed,long pos,
- unsigned short start_speed,unsigned short stop_speed,
- unsigned short acc_pulse,unsigned short dec_pulse)
- {
- switch(axis)
- {
- case X_AXIS:
- axis_x->start_speed = start_speed * axis_x->speed_unit;
- axis_x->stop_speed = stop_speed * axis_x->speed_unit;
- axis_x->acc_time = acc_pulse;
- axis_x->dec_time = dec_pulse;
- SetStopSelect(X_AXIS,PP_Stop);
- axis_pp(axis_x, 1, PosToPulse(X_AXIS,pos),speed,0);break;
- case Y_AXIS:
- axis_y->start_speed = start_speed * axis_y->speed_unit;
- axis_y->stop_speed = stop_speed * axis_y->speed_unit;
- axis_y->acc_time = acc_pulse;
- axis_y->dec_time = dec_pulse;
- SetStopSelect(Y_AXIS,PP_Stop);
- axis_pp(axis_y, 1, PosToPulse(Y_AXIS,pos),speed,0);break;
- case Z_AXIS:
- axis_z->start_speed = start_speed * axis_z->speed_unit;
- axis_z->stop_speed = stop_speed * axis_z->speed_unit;
- axis_z->acc_time = acc_pulse;
- axis_z->dec_time = dec_pulse;
- SetStopSelect(Z_AXIS,PP_Stop);
- axis_pp(axis_z, 1, PosToPulse(Z_AXIS,pos),speed,0);break;
- default:;
- }
- }
- //移动距离
- void AxisMovePos(unsigned short axis,unsigned short speed,long pos)
- {
- switch(axis)
- {
- case X_AXIS:
- {
- SetStopSelect(X_AXIS,PP_Stop);
- axis_pp(axis_x, 0, PosToPulse(X_AXIS,pos),speed,0);
- }break;
- case Y_AXIS:
- {
- axis_pp(axis_y, 0, PosToPulse(Y_AXIS,pos),speed,0);
- }break;
- case Z_AXIS:
- {
- SetStopSelect(Y_AXIS,PP_Stop);
- axis_pp(axis_z, 0, PosToPulse(Z_AXIS,pos),speed,0);
- }break;
- default:;
- }
- }
- //移动距离
- /* 如果运动过程中调用,则start_speed参数无效,使用当前速度作为起始速度*/
- void AxisMovePosAccDec(unsigned short axis,unsigned short speed,long pos,
- unsigned short start_speed,unsigned short stop_speed,
- unsigned short acc_pulse,unsigned short dec_pulse,long slowpos)
- {
- switch(axis)
- {
- case X_AXIS:
- {
- if(axis_x->outputs.on)
- {
- axis_x->start_speed = GetCurSpeed(axis);
- axis_x->stop_speed = stop_speed * axis_x->speed_unit;
- axis_x->acc_time = acc_pulse;
- axis_x->dec_time = dec_pulse;
- axis_pp_change_speed(axis_x, 0, PosToPulse(X_AXIS,pos),speed,slowpos);
- SetStopSelect(X_AXIS,PP_Stop);
- }
- else
- {
- axis_x->start_speed = start_speed * axis_x->speed_unit;
- axis_x->stop_speed = stop_speed * axis_x->speed_unit;
- axis_x->acc_time = acc_pulse;
- axis_x->dec_time = dec_pulse;
- axis_pp(axis_x, 0, PosToPulse(X_AXIS,pos),speed,slowpos);
- SetStopSelect(X_AXIS,PP_Stop);
- }
- }
- break;
- case Y_AXIS:
- {
- if(axis_y->outputs.on)
- {
- axis_y->start_speed = GetCurSpeed(axis);
- axis_y->stop_speed = stop_speed * axis_y->speed_unit;
- axis_y->acc_time = acc_pulse;
- axis_y->dec_time = dec_pulse;
- axis_pp_change_speed(axis_y, 0, PosToPulse(Y_AXIS,pos),speed,slowpos);
- SetStopSelect(Y_AXIS,PP_Stop);
- }
- else
- {
- axis_y->start_speed = start_speed * axis_y->speed_unit;
- axis_y->stop_speed = stop_speed * axis_y->speed_unit;
- axis_y->acc_time = acc_pulse;
- axis_y->dec_time = dec_pulse;
- axis_pp(axis_y, 0, PosToPulse(Y_AXIS,pos),speed,slowpos);
- SetStopSelect(Y_AXIS,PP_Stop);
- }
-
- }break;
- case Z_AXIS:
- {
- if(axis_z->outputs.on)
- {
- axis_z->start_speed = GetCurSpeed(axis);
- axis_z->stop_speed = stop_speed * axis_z->speed_unit;
- axis_z->acc_time = acc_pulse;
- axis_z->dec_time = dec_pulse;
- axis_pp_change_speed(axis_z, 0, PosToPulse(Z_AXIS,pos),speed,slowpos);
- SetStopSelect(Z_AXIS,PP_Stop);
- }
- else
- {
- axis_z->start_speed = start_speed * axis_z->speed_unit;
- axis_z->stop_speed = stop_speed * axis_z->speed_unit;
- axis_z->acc_time = acc_pulse;
- axis_z->dec_time = dec_pulse;
- axis_pp(axis_z, 0, PosToPulse(Z_AXIS,pos),speed,slowpos);
- SetStopSelect(Z_AXIS,PP_Stop);
- }
- }
- break;
- default:;
- }
- }
- //移动距离不停止
- /*
- 参数
- axis 轴选择
- speed 最高速度位置
- pos 移动位置
- start_speed 启动速度,如果运动过程中调用,则start_speed参数无效,使用当前速度作为起始速度
- acc_pulse 加速度
- dec_pulse 减速度
- lastspeed 数控最后速度
- slowpos
- */
- void AxisMovePosAccDecNotStop(unsigned short axis,unsigned short speed,long pos,
- unsigned short start_speed,unsigned short lastspeed,
- unsigned short acc_pulse,unsigned short dec_pulse,long slowpos)
- {
- switch(axis)
- {
- case X_AXIS:
- {
- if(axis_x->outputs.on)
- {
- SetStopSelect(X_AXIS,PP_NoStop);
- axis_x->start_speed = GetCurSpeed(axis);;
- axis_x->stop_speed = lastspeed * axis_x->speed_unit;
- axis_x->acc_time = acc_pulse;
- axis_x->dec_time = dec_pulse;
- axis_pp_change_speed(axis_x, 0, PosToPulse(X_AXIS,pos),speed,slowpos);
- }
- else
- {
- SetStopSelect(X_AXIS,PP_NoStop);
- axis_x->start_speed = start_speed * axis_x->speed_unit;
- axis_x->stop_speed = lastspeed * axis_x->speed_unit;
- axis_x->acc_time = acc_pulse;
- axis_x->dec_time = dec_pulse;
- axis_pp(axis_x, 0, PosToPulse(X_AXIS,pos),speed,slowpos);
- }
- }
- break;
- case Y_AXIS:
- {
- if(axis_y->outputs.on)
- {
- SetStopSelect(Y_AXIS,PP_NoStop);
- axis_y->start_speed = GetCurSpeed(axis);;
- axis_y->stop_speed = lastspeed * axis_y->speed_unit;
- axis_y->acc_time = acc_pulse;
- axis_y->dec_time = dec_pulse;
- axis_pp_change_speed(axis_y, 0, PosToPulse(Y_AXIS,pos),speed,slowpos);
- }
- else
- {
- SetStopSelect(Y_AXIS,PP_NoStop);
- axis_y->start_speed = start_speed * axis_y->speed_unit;
- axis_y->stop_speed = lastspeed * axis_y->speed_unit;
- axis_y->acc_time = acc_pulse;
- axis_y->dec_time = dec_pulse;
- axis_pp(axis_y, 0, PosToPulse(Y_AXIS,pos),speed,slowpos);
- }
-
- }break;
- case Z_AXIS:
- {
- if(axis_z->outputs.on)
- {
- SetStopSelect(Z_AXIS,PP_NoStop);
- axis_z->start_speed = GetCurSpeed(axis);
- axis_z->stop_speed = lastspeed * axis_z->speed_unit;
- axis_z->acc_time = acc_pulse;
- axis_z->dec_time = dec_pulse;
- axis_pp_change_speed(axis_z, 0, PosToPulse(Z_AXIS,pos),speed,slowpos);
- }
- else
- {
- SetStopSelect(Z_AXIS,PP_NoStop);
- axis_z->start_speed = start_speed * axis_z->speed_unit;
- axis_z->stop_speed = lastspeed * axis_z->speed_unit;
- axis_z->acc_time = acc_pulse;
- axis_z->dec_time = dec_pulse;
- axis_pp(axis_z, 0, PosToPulse(Z_AXIS,pos),speed,slowpos);
- }
- }
- break;
- default:;
- }
- }
- //连续运动
- void AxisContinueMove(unsigned short axis,unsigned short speed,unsigned char dir)
- {
- switch(axis)
- {
- case X_AXIS:
- {
- axis_pv(axis_x,dir,speed);
- }break;
- case Y_AXIS:
- {
- axis_pv(axis_y,dir,speed);
- }break;
- case Z_AXIS:
- {
- axis_pv(axis_z,dir,speed);
- }break;
- default:;
- }
- }
- //连续运动带加减速参数
- void AxisContinueMoveAcc(unsigned short axis,unsigned short speed,unsigned char dir,
- unsigned short start_speed,unsigned short stop_speed,
- unsigned short acc,unsigned short dec)
- {
- switch(axis)
- {
- case X_AXIS:
- {
- axis_x->start_speed = start_speed * axis_x->speed_unit;
- axis_x->stop_speed = stop_speed * axis_x->speed_unit;
- axis_x->acc_time = acc;
- axis_x->dec_time = dec;
- axis_pv(axis_x,dir,speed);
- }break;
- case Y_AXIS:
- {
- axis_y->start_speed = start_speed * axis_y->speed_unit;
- axis_y->stop_speed = stop_speed * axis_y->speed_unit;
- axis_y->acc_time = acc;
- axis_y->dec_time = dec;
- axis_pv(axis_y,dir,speed);
- }break;
- case Z_AXIS:
- {
- axis_z->start_speed = start_speed * axis_z->speed_unit;
- axis_z->stop_speed = stop_speed * axis_z->speed_unit;
- axis_z->acc_time = acc;
- axis_z->dec_time = dec;
- axis_pv(axis_z,dir,speed);
- }break;
- default:;
- }
- }
- //连续运动带加减速参数--中途改变目标速度
- void AxisContinueMoveChangeSpeed(unsigned short axis,unsigned short speed,unsigned short stop_speed,
- unsigned short acc,unsigned short dec)
- {
- GetCurSpeed(axis);
- switch(axis)
- {
- case X_AXIS:
- {
- if(axis_x->outputs.on)
- {
- axis_x->start_speed = GetCurSpeed(axis);;
- axis_x->stop_speed = stop_speed * axis_x->speed_unit;
- axis_x->acc_time = acc;
- axis_x->dec_time = dec;
- axis_pv_change_speed_table(axis_x,speed);
- }
- }break;
- case Y_AXIS:
- {
- if(axis_y->outputs.on)
- {
- axis_y->start_speed = GetCurSpeed(axis);;
- axis_y->stop_speed = stop_speed * axis_y->speed_unit;
- axis_y->acc_time = acc;
- axis_y->dec_time = dec;
- axis_pv_change_speed_table(axis_y,speed);
- }
- }break;
- case Z_AXIS:
- {
- if(axis_z->outputs.on)
- {
- axis_z->start_speed = GetCurSpeed(axis);;
- axis_z->stop_speed = stop_speed * axis_z->speed_unit;
- axis_z->acc_time = acc;
- axis_z->dec_time = dec;
- axis_pv_change_speed_table(axis_z,speed);
- }
- }break;
- default:;
- }
- }
- //直接变速不经过加减速过程,支持PP、PV模式调用,调用后切换到连续运动PV模式
- void AxisChangeSpeedDirect(unsigned short axis,unsigned short speed)
- {
- switch(axis)
- {
- case X_AXIS:
- {
- if(axis_x->outputs.on)
- {
- axis_change_speed_direct(axis_x,speed);
- }
- }break;
- case Y_AXIS:
- {
- if(axis_y->outputs.on)
- {
- axis_change_speed_direct(axis_y,speed);
- }
- }break;
- case Z_AXIS:
- {
- if(axis_z->outputs.on)
- {
- axis_change_speed_direct(axis_z,speed);
- }
- }break;
- default:;
- }
- }
- //两段速度移动距离
- void AxisMoveTwoPos(unsigned short axis,unsigned short speed1,long pos1,
- unsigned short speed2,long pos2,int dir,
- unsigned short start_speed,unsigned short stop_speed,
- unsigned short acc_pulse,unsigned short dec_pulse)
- {
- switch(axis)
- {
- case X_AXIS:
- {
- axis_init_task(axis_x,dir);
- SetStopSelect(X_AXIS,PP_Stop);
- axis_x->start_speed = start_speed * axis_x->speed_unit;
- axis_x->stop_speed = stop_speed * axis_x->speed_unit;
- axis_x->acc_time = acc_pulse;
- axis_x->dec_time = dec_pulse;
- axis_add_pp_task(axis_x, PosToPulse(X_AXIS,pos1), speed1);
- axis_add_pp_task(axis_x, PosToPulse(X_AXIS,pos2), speed2);
- axis_start_pp_task(axis_x);
- }
- break;
- case Y_AXIS:
- {
- SetStopSelect(Y_AXIS,PP_Stop);
- axis_init_task(axis_y,dir);
- axis_y->start_speed = start_speed * axis_y->speed_unit;
- axis_y->stop_speed = stop_speed * axis_y->speed_unit;
- axis_y->acc_time = acc_pulse;
- axis_y->dec_time = dec_pulse;
- axis_add_pp_task(axis_y, PosToPulse(Y_AXIS,pos1), speed1);
- axis_add_pp_task(axis_y, PosToPulse(Y_AXIS,pos2), speed2);
- axis_start_pp_task(axis_y);
-
- }
- break;
- case Z_AXIS:
- {
- SetStopSelect(Z_AXIS,PP_Stop);
- axis_init_task(axis_z,dir);
- axis_z->start_speed = start_speed * axis_z->speed_unit;
- axis_z->stop_speed = stop_speed * axis_z->speed_unit;
- axis_z->acc_time = acc_pulse;
- axis_z->dec_time = dec_pulse;
- axis_add_pp_task(axis_z, PosToPulse(Z_AXIS,pos1), speed1);
- axis_add_pp_task(axis_z, PosToPulse(Z_AXIS,pos2), speed2);
- axis_start_pp_task(axis_z);
- }
- break;
- default:
- break;
- }
- }
- //两段速度移动距离 (到位不停)
- void AxisMoveTwoPosNoStop(unsigned short axis,unsigned short speed1,long pos1,
- unsigned short speed2,long pos2,int dir,
- unsigned short start_speed,unsigned short stop_speed,
- unsigned short acc_pulse,unsigned short dec_pulse)
- {
- switch(axis)
- {
- case X_AXIS:
- {
- axis_init_task(axis_x,dir);
- SetStopSelect(X_AXIS,PP_NoStop);
- axis_x->start_speed = start_speed * axis_x->speed_unit;
- axis_x->stop_speed = stop_speed * axis_x->speed_unit;
- axis_x->acc_time = acc_pulse;
- axis_x->dec_time = dec_pulse;
- axis_add_pp_task(axis_x, PosToPulse(X_AXIS,pos1), speed1);
- axis_add_pp_task(axis_x, PosToPulse(X_AXIS,pos2), speed2);
- axis_start_pp_task(axis_x);
- }
- break;
- case Y_AXIS:
- {
- SetStopSelect(Y_AXIS,PP_NoStop);
- axis_init_task(axis_y,dir);
- axis_y->start_speed = start_speed * axis_y->speed_unit;
- axis_y->stop_speed = stop_speed * axis_y->speed_unit;
- axis_y->acc_time = acc_pulse;
- axis_y->dec_time = dec_pulse;
- axis_add_pp_task(axis_y, PosToPulse(Y_AXIS,pos1), speed1);
- axis_add_pp_task(axis_y, PosToPulse(Y_AXIS,pos2), speed2);
- axis_start_pp_task(axis_y);
-
- }
- break;
- case Z_AXIS:
- {
- SetStopSelect(Z_AXIS,PP_NoStop);
- axis_init_task(axis_z,dir);
- axis_z->start_speed = start_speed * axis_z->speed_unit;
- axis_z->stop_speed = stop_speed * axis_z->speed_unit;
- axis_z->acc_time = acc_pulse;
- axis_z->dec_time = dec_pulse;
- axis_add_pp_task(axis_z, PosToPulse(Z_AXIS,pos1), speed1);
- axis_add_pp_task(axis_z, PosToPulse(Z_AXIS,pos2), speed2);
- axis_start_pp_task(axis_z);
- }
- break;
- default:
- break;
- }
- }
- //三段速度移动距离
- void AxisMoveThreePos(unsigned short axis,unsigned short speed1,long pos1,unsigned short speed2,long pos2,unsigned short speed3,long pos3,int dir)
- {
- switch(axis)
- {
- case X_AXIS:
- {
- axis_init_task(axis_x,dir);
- SetStopSelect(X_AXIS,PP_Stop);
- axis_add_pp_task(axis_x, PosToPulse(X_AXIS,pos1), speed1);
- axis_add_pp_task(axis_x, PosToPulse(X_AXIS,pos2), speed2);
- axis_add_pp_task(axis_x, PosToPulse(X_AXIS,pos3), speed3);
- axis_start_pp_task(axis_x);
- }break;
- case Y_AXIS:
- {
- axis_init_task(axis_y,dir);
- SetStopSelect(Y_AXIS,PP_Stop);
- axis_add_pp_task(axis_y, PosToPulse(Y_AXIS,pos1), speed1);
- axis_add_pp_task(axis_y, PosToPulse(Y_AXIS,pos2), speed2);
- axis_add_pp_task(axis_y, PosToPulse(Y_AXIS,pos3), speed3);
- axis_start_pp_task(axis_y);
- }
- break;
- case Z_AXIS:
- {
- axis_init_task(axis_z,dir);
- SetStopSelect(Z_AXIS,PP_Stop);
- axis_add_pp_task(axis_z, PosToPulse(Z_AXIS,pos1), speed1);
- axis_add_pp_task(axis_z, PosToPulse(Z_AXIS,pos2), speed2);
- axis_add_pp_task(axis_z, PosToPulse(Z_AXIS,pos3), speed3);
- axis_start_pp_task(axis_z);
- }
- break;
- default:;
- }
- }
- //三段速度移动距离不停止
- void AxisMoveThreePosNoStop(unsigned short axis,unsigned short speed1,long pos1,unsigned short speed2,long pos2,unsigned short speed3,long pos3,int dir)
- {
- switch(axis)
- {
- case X_AXIS:
- {
- axis_init_task(axis_x,dir);
- SetStopSelect(X_AXIS,PP_NoStop);
- axis_add_pp_task(axis_x, PosToPulse(X_AXIS,pos1), speed1);
- axis_add_pp_task(axis_x, PosToPulse(X_AXIS,pos2), speed2);
- axis_add_pp_task(axis_x, PosToPulse(X_AXIS,pos3), speed3);
- axis_start_pp_task(axis_x);
- }break;
- case Y_AXIS:
- {
- axis_init_task(axis_y,dir);
- SetStopSelect(Y_AXIS,PP_NoStop);
- axis_add_pp_task(axis_y, PosToPulse(Y_AXIS,pos1), speed1);
- axis_add_pp_task(axis_y, PosToPulse(Y_AXIS,pos2), speed2);
- axis_add_pp_task(axis_y, PosToPulse(Y_AXIS,pos3), speed3);
- axis_start_pp_task(axis_y);
- }break;
- case Z_AXIS:
- {
- axis_init_task(axis_z,dir);
- SetStopSelect(Z_AXIS,PP_NoStop);
- axis_add_pp_task(axis_z, PosToPulse(Z_AXIS,pos1), speed1);
- axis_add_pp_task(axis_z, PosToPulse(Z_AXIS,pos2), speed2);
- axis_add_pp_task(axis_z, PosToPulse(Z_AXIS,pos3), speed3);
- axis_start_pp_task(axis_z);
- }break;
- default:;
- }
- }
|