AllSeroDrv.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. #include "global.h"
  2. #include "AllServoDrv.h"
  3. axis_object_t *axis_x;
  4. axis_object_t *axis_y;
  5. axis_object_t *axis_z;
  6. float XGearRatio = 1,YGearRatio = 1,ZGearRatio = 1;
  7. void SetDir(unsigned short axis, unsigned short dir)
  8. {
  9. switch(axis)
  10. {
  11. case X_AXIS:
  12. if(dir)
  13. axis_cw(axis_x);
  14. else
  15. axis_ccw(axis_x);
  16. break;
  17. case Y_AXIS:
  18. if(dir)
  19. axis_cw(axis_y);
  20. else
  21. axis_ccw(axis_y);
  22. break;
  23. case Z_AXIS:
  24. if(dir)
  25. axis_cw(axis_z);
  26. else
  27. axis_ccw(axis_z);
  28. break;
  29. default:;
  30. }
  31. }
  32. void SetDirReverse(unsigned short axis, int value)
  33. {
  34. switch(axis)
  35. {
  36. case X_AXIS:
  37. if(value)
  38. axis_set_parameter (axis_x,AXIS_DIR_REVERSE,1);
  39. else
  40. axis_set_parameter (axis_x,AXIS_DIR_REVERSE,0);
  41. break;
  42. case Y_AXIS:
  43. if(value)
  44. axis_set_parameter (axis_y,AXIS_DIR_REVERSE,1);
  45. else
  46. axis_set_parameter (axis_y,AXIS_DIR_REVERSE,0);
  47. break;
  48. case Z_AXIS:
  49. if(value)
  50. axis_set_parameter (axis_z,AXIS_DIR_REVERSE,1);
  51. else
  52. axis_set_parameter (axis_z,AXIS_DIR_REVERSE,0);
  53. break;
  54. default:;
  55. }
  56. }
  57. unsigned char GetDir(unsigned short axis)
  58. {
  59. switch(axis)
  60. {
  61. case X_AXIS: return axis_x->outputs.dir;break;
  62. case Y_AXIS: return axis_y->outputs.dir;break;
  63. case Z_AXIS: return axis_z->outputs.dir;break;
  64. default:return axis_x->outputs.dir;
  65. }
  66. }
  67. void SetEn(unsigned short axis, unsigned short ena)
  68. {
  69. switch(axis)
  70. {
  71. case X_AXIS:
  72. if(ena)
  73. axis_enable(axis_x);
  74. else
  75. axis_disable(axis_x);
  76. break;
  77. case Y_AXIS:
  78. if(ena)
  79. axis_enable(axis_y);
  80. else
  81. axis_disable(axis_y);
  82. break;
  83. case Z_AXIS:
  84. if(ena)
  85. axis_enable(axis_z);
  86. else
  87. axis_disable(axis_z);
  88. break;
  89. default:;
  90. }
  91. }
  92. void SetEnReverse(unsigned short axis, int value)
  93. {
  94. switch(axis)
  95. {
  96. case X_AXIS:
  97. if(value)
  98. axis_set_parameter (axis_x,AXIS_EN_REVERSE,1);
  99. else
  100. axis_set_parameter (axis_x,AXIS_EN_REVERSE,0);
  101. break;
  102. case Y_AXIS:
  103. if(value)
  104. axis_set_parameter (axis_y,AXIS_EN_REVERSE,1);
  105. else
  106. axis_set_parameter (axis_y,AXIS_EN_REVERSE,0);
  107. break;
  108. case Z_AXIS:
  109. if(value)
  110. axis_set_parameter (axis_z,AXIS_EN_REVERSE,1);
  111. else
  112. axis_set_parameter (axis_z,AXIS_EN_REVERSE,0);
  113. break;
  114. default:;
  115. }
  116. }
  117. //设置伺服告警的极性
  118. void SetAlarmReverse(unsigned short axis, int value)
  119. {
  120. switch(axis)
  121. {
  122. case X_AXIS:
  123. if(value){
  124. axis_set_parameter (axis_x,AXIS_ALARM_REVERSE,1);
  125. }
  126. else{
  127. axis_set_parameter (axis_x,AXIS_ALARM_REVERSE,0);
  128. }
  129. break;
  130. case Y_AXIS:
  131. if(value){
  132. axis_set_parameter (axis_y,AXIS_ALARM_REVERSE,1);
  133. }
  134. else{
  135. axis_set_parameter (axis_y,AXIS_ALARM_REVERSE,0);
  136. }
  137. break;
  138. case Z_AXIS:
  139. if(value){
  140. axis_set_parameter (axis_z,AXIS_ALARM_REVERSE,1);
  141. }
  142. else{
  143. axis_set_parameter (axis_z,AXIS_ALARM_REVERSE,0);
  144. }
  145. break;
  146. default:;
  147. }
  148. }
  149. unsigned char GetEn(unsigned short axis)
  150. {
  151. switch(axis)
  152. {
  153. case X_AXIS:return (axis_x->outputs.enable);break;
  154. case Y_AXIS:return (axis_y->outputs.enable);break;
  155. case Z_AXIS:return (axis_z->outputs.enable);break;
  156. default:return (axis_x->outputs.enable);
  157. }
  158. }
  159. unsigned char GetAlarm(unsigned short axis)
  160. {
  161. switch(axis)
  162. {
  163. case X_AXIS:
  164. if(axis_x->inputs.alarm_reverse){
  165. if(hw_pwm_get_alr(axis_x->axis_no))return 1;else return 0;
  166. }
  167. else {
  168. if(hw_pwm_get_alr(axis_x->axis_no))return 0;else return 1;
  169. }
  170. break;
  171. case Y_AXIS:
  172. if(axis_y->inputs.alarm_reverse){
  173. if(hw_pwm_get_alr(axis_y->axis_no))return 1;else return 0;
  174. }
  175. else {
  176. if(hw_pwm_get_alr(axis_y->axis_no))return 0;else return 1;
  177. }
  178. break;
  179. case Z_AXIS:
  180. if(axis_z->inputs.alarm_reverse){
  181. if(hw_pwm_get_alr(axis_z->axis_no))return 1;else return 0;
  182. }
  183. else {
  184. if(hw_pwm_get_alr(axis_z->axis_no))return 0;else return 1;
  185. }
  186. break;
  187. default:return hw_pwm_get_alr(axis_x->axis_no);
  188. }
  189. }
  190. void SetClr(unsigned short axis, unsigned short clr)
  191. {
  192. switch(axis)
  193. {
  194. case X_AXIS:
  195. hw_pwm_set_clr(axis_x->axis_no, clr);
  196. break;
  197. case Y_AXIS:
  198. hw_pwm_set_clr(axis_y->axis_no, clr);
  199. break;
  200. case Z_AXIS:
  201. hw_pwm_set_clr(axis_z->axis_no, clr);
  202. break;
  203. default:
  204. break;
  205. }
  206. }
  207. //脉冲转化为距离
  208. long PulseToPos(unsigned short axis, long pulse)
  209. {
  210. float pulse_buff;
  211. pulse_buff = pulse;
  212. switch(axis)
  213. {
  214. case X_AXIS: return (long)(pulse_buff/XGearRatio);break;
  215. case Y_AXIS: return (long)(pulse_buff/YGearRatio);break;
  216. case Z_AXIS: return (long)(pulse_buff/ZGearRatio);break;
  217. default:return (long)(pulse_buff/XGearRatio);;
  218. }
  219. }
  220. //距离转化为脉冲
  221. long PosToPulse(unsigned short axis, long pos)
  222. {
  223. float pos_buff;
  224. pos_buff = pos;
  225. switch(axis)
  226. {
  227. case X_AXIS: return (long)(pos_buff*XGearRatio);break;
  228. case Y_AXIS: return (long)(pos_buff*YGearRatio);break;
  229. case Z_AXIS: return (long)(pos_buff*ZGearRatio);break;
  230. default:return (long)(pos_buff*XGearRatio);
  231. }
  232. }
  233. //设置真实位置
  234. void SetPos(unsigned short axis, long pos)
  235. {
  236. switch(axis)
  237. {
  238. case X_AXIS:
  239. axis_set_parameter(axis_x, AXIS_POSITION, PosToPulse(axis, pos));
  240. break;
  241. case Y_AXIS:
  242. axis_set_parameter(axis_y, AXIS_POSITION, PosToPulse(axis, pos));
  243. break;
  244. case Z_AXIS:
  245. axis_set_parameter(axis_z, AXIS_POSITION, PosToPulse(axis, pos));
  246. break;
  247. default:;
  248. }
  249. }
  250. //获取真实位置
  251. long GetPos(unsigned short axis)
  252. {
  253. switch(axis)
  254. {
  255. case X_AXIS:
  256. {
  257. return PulseToPos(axis, axis_get_parameter(axis_x, AXIS_POSITION));
  258. }break;
  259. case Y_AXIS:
  260. {
  261. return PulseToPos(axis, axis_get_parameter(axis_y, AXIS_POSITION));
  262. }break;
  263. case Z_AXIS:
  264. {
  265. return PulseToPos(axis, axis_get_parameter(axis_z, AXIS_POSITION));
  266. }break;
  267. default:;
  268. }
  269. return 0;
  270. }
  271. //获取当前速度
  272. unsigned long GetCurSpeed(unsigned short axis)
  273. {
  274. switch(axis)
  275. {
  276. case X_AXIS:
  277. axis_x->cur_speed=axis_x->clock/axis_x->cur_reg_value;
  278. return axis_x->cur_speed; break;
  279. case Y_AXIS:
  280. axis_y->cur_speed=axis_y->clock/axis_y->cur_reg_value;
  281. return axis_y->cur_speed; break;
  282. case Z_AXIS:
  283. axis_z->cur_speed=axis_z->clock/axis_z->cur_reg_value;
  284. return axis_z->cur_speed; break;
  285. default:
  286. axis_x->cur_speed=axis_x->clock/axis_x->cur_reg_value;
  287. return axis_x->cur_speed; break;
  288. }
  289. // return 0;
  290. }
  291. //获取设置速度
  292. unsigned long GetSetSpeed(unsigned short axis)
  293. {
  294. return 0;
  295. }
  296. //获取脉冲状态
  297. unsigned long GetState(unsigned short axis)
  298. {
  299. return 0;
  300. }
  301. //获取脉冲状态
  302. unsigned long SetState(unsigned short axis,unsigned short state)
  303. {
  304. return 0;
  305. }
  306. //获取剩余脉冲数
  307. unsigned long GetRemainPulse(unsigned short axis)
  308. {
  309. return 0;
  310. }
  311. //设置脉冲数
  312. unsigned long SetPulse(unsigned short axis,unsigned long pulse)
  313. {
  314. return 0;
  315. }
  316. //设置起动速度
  317. void SetStartSpeed(unsigned short axis,unsigned short speed)
  318. {
  319. switch(axis)
  320. {
  321. case X_AXIS:axis_set_parameter(axis_x, AXIS_START_SPEED,speed);break;
  322. case Y_AXIS:axis_set_parameter(axis_y, AXIS_START_SPEED,speed);break;
  323. case Z_AXIS:axis_set_parameter(axis_z, AXIS_START_SPEED,speed);break;
  324. default:;
  325. }
  326. }
  327. //设置最低速度
  328. void SetMinSpeed(unsigned short axis,unsigned short speed)
  329. {
  330. }
  331. void SetAccTime(unsigned short axis,unsigned short acc_time)
  332. {
  333. switch(axis)
  334. {
  335. case X_AXIS:axis_set_parameter(axis_x, AXIS_ACC_TIME,acc_time);break;
  336. case Y_AXIS:axis_set_parameter(axis_y, AXIS_ACC_TIME,acc_time);break;
  337. case Z_AXIS:axis_set_parameter(axis_z, AXIS_ACC_TIME,acc_time);break;
  338. default:;
  339. }
  340. }
  341. void SetDecTime(unsigned short axis,unsigned short dec_time)
  342. {
  343. switch(axis)
  344. {
  345. case X_AXIS:axis_set_parameter(axis_x, AXIS_DEC_TIME,dec_time);break;
  346. case Y_AXIS:axis_set_parameter(axis_y, AXIS_DEC_TIME,dec_time);break;
  347. case Z_AXIS:axis_set_parameter(axis_z, AXIS_DEC_TIME,dec_time);break;
  348. default:;
  349. }
  350. }
  351. void SetStopSelect(unsigned short axis,unsigned short Select_Flag)
  352. {
  353. switch(axis)
  354. {
  355. case X_AXIS:axis_set_parameter(axis_x, AXIS_PP_STOP_SELECT,Select_Flag);break;
  356. case Y_AXIS:axis_set_parameter(axis_y, AXIS_PP_STOP_SELECT,Select_Flag);break;
  357. case Z_AXIS:axis_set_parameter(axis_z, AXIS_PP_STOP_SELECT,Select_Flag);break;
  358. default:;
  359. }
  360. }
  361. //运动当中改变速度
  362. void AxisChangeSpeed(unsigned short axis,unsigned short speed)
  363. {
  364. switch(axis)
  365. {
  366. case X_AXIS:
  367. axis_pv_change_speed(axis_x,speed);
  368. break;
  369. case Y_AXIS:
  370. axis_pv_change_speed(axis_y,speed);
  371. break;
  372. case Z_AXIS:
  373. axis_pv_change_speed(axis_z,speed);
  374. break;
  375. default:;
  376. }
  377. }
  378. //固定减速距离停止
  379. void AxisDecStopPos(unsigned short axis,unsigned long pos)
  380. {
  381. switch(axis)
  382. {
  383. case X_AXIS: axis_stop_at(axis_x,PosToPulse(X_AXIS,pos));break;
  384. case Y_AXIS: axis_stop_at(axis_y,PosToPulse(Y_AXIS,pos));break;
  385. case Z_AXIS: axis_stop_at(axis_z,PosToPulse(Z_AXIS,pos));break;
  386. default:;
  387. }
  388. }
  389. //减速停
  390. void AxisDecStop(unsigned short axis)
  391. {
  392. switch(axis)
  393. {
  394. case X_AXIS:
  395. axis_stop(axis_x);break;
  396. case Y_AXIS:
  397. axis_stop(axis_y);break;
  398. case Z_AXIS:
  399. axis_stop(axis_z);break;
  400. default:
  401. break;
  402. }
  403. }
  404. //急停
  405. void AxisEgmStop(unsigned short axis)
  406. {
  407. switch(axis)
  408. {
  409. case X_AXIS:
  410. {
  411. axis_emgstop(axis_x);
  412. }break;
  413. case Y_AXIS:
  414. {
  415. axis_emgstop(axis_y);
  416. }break;
  417. case Z_AXIS:
  418. {
  419. axis_emgstop(axis_z);
  420. }break;
  421. default:
  422. break;
  423. }
  424. }
  425. //移动绝对位置
  426. void AxisMovePoint(unsigned short axis,unsigned short speed,long pos)
  427. {
  428. switch(axis)
  429. {
  430. case X_AXIS: axis_pp(axis_x, 1, PosToPulse(X_AXIS,pos),speed,0);break;
  431. case Y_AXIS: axis_pp(axis_y, 1, PosToPulse(Y_AXIS,pos),speed,0);break;
  432. case Z_AXIS: axis_pp(axis_z, 1, PosToPulse(Z_AXIS,pos),speed,0);break;
  433. default:;
  434. }
  435. }
  436. //移动绝对位置带加减速
  437. void AxisMovePointAccDec(unsigned short axis,unsigned short speed,long pos,
  438. unsigned short start_speed,unsigned short stop_speed,
  439. unsigned short acc_pulse,unsigned short dec_pulse)
  440. {
  441. switch(axis)
  442. {
  443. case X_AXIS:
  444. axis_x->start_speed = start_speed * axis_x->speed_unit;
  445. axis_x->stop_speed = stop_speed * axis_x->speed_unit;
  446. axis_x->acc_time = acc_pulse;
  447. axis_x->dec_time = dec_pulse;
  448. SetStopSelect(X_AXIS,PP_Stop);
  449. axis_pp(axis_x, 1, PosToPulse(X_AXIS,pos),speed,0);break;
  450. case Y_AXIS:
  451. axis_y->start_speed = start_speed * axis_y->speed_unit;
  452. axis_y->stop_speed = stop_speed * axis_y->speed_unit;
  453. axis_y->acc_time = acc_pulse;
  454. axis_y->dec_time = dec_pulse;
  455. SetStopSelect(Y_AXIS,PP_Stop);
  456. axis_pp(axis_y, 1, PosToPulse(Y_AXIS,pos),speed,0);break;
  457. case Z_AXIS:
  458. axis_z->start_speed = start_speed * axis_z->speed_unit;
  459. axis_z->stop_speed = stop_speed * axis_z->speed_unit;
  460. axis_z->acc_time = acc_pulse;
  461. axis_z->dec_time = dec_pulse;
  462. SetStopSelect(Z_AXIS,PP_Stop);
  463. axis_pp(axis_z, 1, PosToPulse(Z_AXIS,pos),speed,0);break;
  464. default:;
  465. }
  466. }
  467. //移动距离
  468. void AxisMovePos(unsigned short axis,unsigned short speed,long pos)
  469. {
  470. switch(axis)
  471. {
  472. case X_AXIS:
  473. {
  474. SetStopSelect(X_AXIS,PP_Stop);
  475. axis_pp(axis_x, 0, PosToPulse(X_AXIS,pos),speed,0);
  476. }break;
  477. case Y_AXIS:
  478. {
  479. axis_pp(axis_y, 0, PosToPulse(Y_AXIS,pos),speed,0);
  480. }break;
  481. case Z_AXIS:
  482. {
  483. SetStopSelect(Y_AXIS,PP_Stop);
  484. axis_pp(axis_z, 0, PosToPulse(Z_AXIS,pos),speed,0);
  485. }break;
  486. default:;
  487. }
  488. }
  489. //移动距离
  490. /* 如果运动过程中调用,则start_speed参数无效,使用当前速度作为起始速度*/
  491. void AxisMovePosAccDec(unsigned short axis,unsigned short speed,long pos,
  492. unsigned short start_speed,unsigned short stop_speed,
  493. unsigned short acc_pulse,unsigned short dec_pulse,long slowpos)
  494. {
  495. switch(axis)
  496. {
  497. case X_AXIS:
  498. {
  499. if(axis_x->outputs.on)
  500. {
  501. axis_x->start_speed = GetCurSpeed(axis);
  502. axis_x->stop_speed = stop_speed * axis_x->speed_unit;
  503. axis_x->acc_time = acc_pulse;
  504. axis_x->dec_time = dec_pulse;
  505. axis_pp_change_speed(axis_x, 0, PosToPulse(X_AXIS,pos),speed,slowpos);
  506. SetStopSelect(X_AXIS,PP_Stop);
  507. }
  508. else
  509. {
  510. axis_x->start_speed = start_speed * axis_x->speed_unit;
  511. axis_x->stop_speed = stop_speed * axis_x->speed_unit;
  512. axis_x->acc_time = acc_pulse;
  513. axis_x->dec_time = dec_pulse;
  514. axis_pp(axis_x, 0, PosToPulse(X_AXIS,pos),speed,slowpos);
  515. SetStopSelect(X_AXIS,PP_Stop);
  516. }
  517. }
  518. break;
  519. case Y_AXIS:
  520. {
  521. if(axis_y->outputs.on)
  522. {
  523. axis_y->start_speed = GetCurSpeed(axis);
  524. axis_y->stop_speed = stop_speed * axis_y->speed_unit;
  525. axis_y->acc_time = acc_pulse;
  526. axis_y->dec_time = dec_pulse;
  527. axis_pp_change_speed(axis_y, 0, PosToPulse(Y_AXIS,pos),speed,slowpos);
  528. SetStopSelect(Y_AXIS,PP_Stop);
  529. }
  530. else
  531. {
  532. axis_y->start_speed = start_speed * axis_y->speed_unit;
  533. axis_y->stop_speed = stop_speed * axis_y->speed_unit;
  534. axis_y->acc_time = acc_pulse;
  535. axis_y->dec_time = dec_pulse;
  536. axis_pp(axis_y, 0, PosToPulse(Y_AXIS,pos),speed,slowpos);
  537. SetStopSelect(Y_AXIS,PP_Stop);
  538. }
  539. }break;
  540. case Z_AXIS:
  541. {
  542. if(axis_z->outputs.on)
  543. {
  544. axis_z->start_speed = GetCurSpeed(axis);
  545. axis_z->stop_speed = stop_speed * axis_z->speed_unit;
  546. axis_z->acc_time = acc_pulse;
  547. axis_z->dec_time = dec_pulse;
  548. axis_pp_change_speed(axis_z, 0, PosToPulse(Z_AXIS,pos),speed,slowpos);
  549. SetStopSelect(Z_AXIS,PP_Stop);
  550. }
  551. else
  552. {
  553. axis_z->start_speed = start_speed * axis_z->speed_unit;
  554. axis_z->stop_speed = stop_speed * axis_z->speed_unit;
  555. axis_z->acc_time = acc_pulse;
  556. axis_z->dec_time = dec_pulse;
  557. axis_pp(axis_z, 0, PosToPulse(Z_AXIS,pos),speed,slowpos);
  558. SetStopSelect(Z_AXIS,PP_Stop);
  559. }
  560. }
  561. break;
  562. default:;
  563. }
  564. }
  565. //移动距离不停止
  566. /*
  567. 参数
  568. axis 轴选择
  569. speed 最高速度位置
  570. pos 移动位置
  571. start_speed 启动速度,如果运动过程中调用,则start_speed参数无效,使用当前速度作为起始速度
  572. acc_pulse 加速度
  573. dec_pulse 减速度
  574. lastspeed 数控最后速度
  575. slowpos
  576. */
  577. void AxisMovePosAccDecNotStop(unsigned short axis,unsigned short speed,long pos,
  578. unsigned short start_speed,unsigned short lastspeed,
  579. unsigned short acc_pulse,unsigned short dec_pulse,long slowpos)
  580. {
  581. switch(axis)
  582. {
  583. case X_AXIS:
  584. {
  585. if(axis_x->outputs.on)
  586. {
  587. SetStopSelect(X_AXIS,PP_NoStop);
  588. axis_x->start_speed = GetCurSpeed(axis);;
  589. axis_x->stop_speed = lastspeed * axis_x->speed_unit;
  590. axis_x->acc_time = acc_pulse;
  591. axis_x->dec_time = dec_pulse;
  592. axis_pp_change_speed(axis_x, 0, PosToPulse(X_AXIS,pos),speed,slowpos);
  593. }
  594. else
  595. {
  596. SetStopSelect(X_AXIS,PP_NoStop);
  597. axis_x->start_speed = start_speed * axis_x->speed_unit;
  598. axis_x->stop_speed = lastspeed * axis_x->speed_unit;
  599. axis_x->acc_time = acc_pulse;
  600. axis_x->dec_time = dec_pulse;
  601. axis_pp(axis_x, 0, PosToPulse(X_AXIS,pos),speed,slowpos);
  602. }
  603. }
  604. break;
  605. case Y_AXIS:
  606. {
  607. if(axis_y->outputs.on)
  608. {
  609. SetStopSelect(Y_AXIS,PP_NoStop);
  610. axis_y->start_speed = GetCurSpeed(axis);;
  611. axis_y->stop_speed = lastspeed * axis_y->speed_unit;
  612. axis_y->acc_time = acc_pulse;
  613. axis_y->dec_time = dec_pulse;
  614. axis_pp_change_speed(axis_y, 0, PosToPulse(Y_AXIS,pos),speed,slowpos);
  615. }
  616. else
  617. {
  618. SetStopSelect(Y_AXIS,PP_NoStop);
  619. axis_y->start_speed = start_speed * axis_y->speed_unit;
  620. axis_y->stop_speed = lastspeed * axis_y->speed_unit;
  621. axis_y->acc_time = acc_pulse;
  622. axis_y->dec_time = dec_pulse;
  623. axis_pp(axis_y, 0, PosToPulse(Y_AXIS,pos),speed,slowpos);
  624. }
  625. }break;
  626. case Z_AXIS:
  627. {
  628. if(axis_z->outputs.on)
  629. {
  630. SetStopSelect(Z_AXIS,PP_NoStop);
  631. axis_z->start_speed = GetCurSpeed(axis);
  632. axis_z->stop_speed = lastspeed * axis_z->speed_unit;
  633. axis_z->acc_time = acc_pulse;
  634. axis_z->dec_time = dec_pulse;
  635. axis_pp_change_speed(axis_z, 0, PosToPulse(Z_AXIS,pos),speed,slowpos);
  636. }
  637. else
  638. {
  639. SetStopSelect(Z_AXIS,PP_NoStop);
  640. axis_z->start_speed = start_speed * axis_z->speed_unit;
  641. axis_z->stop_speed = lastspeed * axis_z->speed_unit;
  642. axis_z->acc_time = acc_pulse;
  643. axis_z->dec_time = dec_pulse;
  644. axis_pp(axis_z, 0, PosToPulse(Z_AXIS,pos),speed,slowpos);
  645. }
  646. }
  647. break;
  648. default:;
  649. }
  650. }
  651. //连续运动
  652. void AxisContinueMove(unsigned short axis,unsigned short speed,unsigned char dir)
  653. {
  654. switch(axis)
  655. {
  656. case X_AXIS:
  657. {
  658. axis_pv(axis_x,dir,speed);
  659. }break;
  660. case Y_AXIS:
  661. {
  662. axis_pv(axis_y,dir,speed);
  663. }break;
  664. case Z_AXIS:
  665. {
  666. axis_pv(axis_z,dir,speed);
  667. }break;
  668. default:;
  669. }
  670. }
  671. //连续运动带加减速参数
  672. void AxisContinueMoveAcc(unsigned short axis,unsigned short speed,unsigned char dir,
  673. unsigned short start_speed,unsigned short stop_speed,
  674. unsigned short acc,unsigned short dec)
  675. {
  676. switch(axis)
  677. {
  678. case X_AXIS:
  679. {
  680. axis_x->start_speed = start_speed * axis_x->speed_unit;
  681. axis_x->stop_speed = stop_speed * axis_x->speed_unit;
  682. axis_x->acc_time = acc;
  683. axis_x->dec_time = dec;
  684. axis_pv(axis_x,dir,speed);
  685. }break;
  686. case Y_AXIS:
  687. {
  688. axis_y->start_speed = start_speed * axis_y->speed_unit;
  689. axis_y->stop_speed = stop_speed * axis_y->speed_unit;
  690. axis_y->acc_time = acc;
  691. axis_y->dec_time = dec;
  692. axis_pv(axis_y,dir,speed);
  693. }break;
  694. case Z_AXIS:
  695. {
  696. axis_z->start_speed = start_speed * axis_z->speed_unit;
  697. axis_z->stop_speed = stop_speed * axis_z->speed_unit;
  698. axis_z->acc_time = acc;
  699. axis_z->dec_time = dec;
  700. axis_pv(axis_z,dir,speed);
  701. }break;
  702. default:;
  703. }
  704. }
  705. //连续运动带加减速参数--中途改变目标速度
  706. void AxisContinueMoveChangeSpeed(unsigned short axis,unsigned short speed,unsigned short stop_speed,
  707. unsigned short acc,unsigned short dec)
  708. {
  709. GetCurSpeed(axis);
  710. switch(axis)
  711. {
  712. case X_AXIS:
  713. {
  714. if(axis_x->outputs.on)
  715. {
  716. axis_x->start_speed = GetCurSpeed(axis);;
  717. axis_x->stop_speed = stop_speed * axis_x->speed_unit;
  718. axis_x->acc_time = acc;
  719. axis_x->dec_time = dec;
  720. axis_pv_change_speed_table(axis_x,speed);
  721. }
  722. }break;
  723. case Y_AXIS:
  724. {
  725. if(axis_y->outputs.on)
  726. {
  727. axis_y->start_speed = GetCurSpeed(axis);;
  728. axis_y->stop_speed = stop_speed * axis_y->speed_unit;
  729. axis_y->acc_time = acc;
  730. axis_y->dec_time = dec;
  731. axis_pv_change_speed_table(axis_y,speed);
  732. }
  733. }break;
  734. case Z_AXIS:
  735. {
  736. if(axis_z->outputs.on)
  737. {
  738. axis_z->start_speed = GetCurSpeed(axis);;
  739. axis_z->stop_speed = stop_speed * axis_z->speed_unit;
  740. axis_z->acc_time = acc;
  741. axis_z->dec_time = dec;
  742. axis_pv_change_speed_table(axis_z,speed);
  743. }
  744. }break;
  745. default:;
  746. }
  747. }
  748. //直接变速不经过加减速过程,支持PP、PV模式调用,调用后切换到连续运动PV模式
  749. void AxisChangeSpeedDirect(unsigned short axis,unsigned short speed)
  750. {
  751. switch(axis)
  752. {
  753. case X_AXIS:
  754. {
  755. if(axis_x->outputs.on)
  756. {
  757. axis_change_speed_direct(axis_x,speed);
  758. }
  759. }break;
  760. case Y_AXIS:
  761. {
  762. if(axis_y->outputs.on)
  763. {
  764. axis_change_speed_direct(axis_y,speed);
  765. }
  766. }break;
  767. case Z_AXIS:
  768. {
  769. if(axis_z->outputs.on)
  770. {
  771. axis_change_speed_direct(axis_z,speed);
  772. }
  773. }break;
  774. default:;
  775. }
  776. }
  777. //两段速度移动距离
  778. void AxisMoveTwoPos(unsigned short axis,unsigned short speed1,long pos1,
  779. unsigned short speed2,long pos2,int dir,
  780. unsigned short start_speed,unsigned short stop_speed,
  781. unsigned short acc_pulse,unsigned short dec_pulse)
  782. {
  783. switch(axis)
  784. {
  785. case X_AXIS:
  786. {
  787. axis_init_task(axis_x,dir);
  788. SetStopSelect(X_AXIS,PP_Stop);
  789. axis_x->start_speed = start_speed * axis_x->speed_unit;
  790. axis_x->stop_speed = stop_speed * axis_x->speed_unit;
  791. axis_x->acc_time = acc_pulse;
  792. axis_x->dec_time = dec_pulse;
  793. axis_add_pp_task(axis_x, PosToPulse(X_AXIS,pos1), speed1);
  794. axis_add_pp_task(axis_x, PosToPulse(X_AXIS,pos2), speed2);
  795. axis_start_pp_task(axis_x);
  796. }
  797. break;
  798. case Y_AXIS:
  799. {
  800. SetStopSelect(Y_AXIS,PP_Stop);
  801. axis_init_task(axis_y,dir);
  802. axis_y->start_speed = start_speed * axis_y->speed_unit;
  803. axis_y->stop_speed = stop_speed * axis_y->speed_unit;
  804. axis_y->acc_time = acc_pulse;
  805. axis_y->dec_time = dec_pulse;
  806. axis_add_pp_task(axis_y, PosToPulse(Y_AXIS,pos1), speed1);
  807. axis_add_pp_task(axis_y, PosToPulse(Y_AXIS,pos2), speed2);
  808. axis_start_pp_task(axis_y);
  809. }
  810. break;
  811. case Z_AXIS:
  812. {
  813. SetStopSelect(Z_AXIS,PP_Stop);
  814. axis_init_task(axis_z,dir);
  815. axis_z->start_speed = start_speed * axis_z->speed_unit;
  816. axis_z->stop_speed = stop_speed * axis_z->speed_unit;
  817. axis_z->acc_time = acc_pulse;
  818. axis_z->dec_time = dec_pulse;
  819. axis_add_pp_task(axis_z, PosToPulse(Z_AXIS,pos1), speed1);
  820. axis_add_pp_task(axis_z, PosToPulse(Z_AXIS,pos2), speed2);
  821. axis_start_pp_task(axis_z);
  822. }
  823. break;
  824. default:
  825. break;
  826. }
  827. }
  828. //两段速度移动距离 (到位不停)
  829. void AxisMoveTwoPosNoStop(unsigned short axis,unsigned short speed1,long pos1,
  830. unsigned short speed2,long pos2,int dir,
  831. unsigned short start_speed,unsigned short stop_speed,
  832. unsigned short acc_pulse,unsigned short dec_pulse)
  833. {
  834. switch(axis)
  835. {
  836. case X_AXIS:
  837. {
  838. axis_init_task(axis_x,dir);
  839. SetStopSelect(X_AXIS,PP_NoStop);
  840. axis_x->start_speed = start_speed * axis_x->speed_unit;
  841. axis_x->stop_speed = stop_speed * axis_x->speed_unit;
  842. axis_x->acc_time = acc_pulse;
  843. axis_x->dec_time = dec_pulse;
  844. axis_add_pp_task(axis_x, PosToPulse(X_AXIS,pos1), speed1);
  845. axis_add_pp_task(axis_x, PosToPulse(X_AXIS,pos2), speed2);
  846. axis_start_pp_task(axis_x);
  847. }
  848. break;
  849. case Y_AXIS:
  850. {
  851. SetStopSelect(Y_AXIS,PP_NoStop);
  852. axis_init_task(axis_y,dir);
  853. axis_y->start_speed = start_speed * axis_y->speed_unit;
  854. axis_y->stop_speed = stop_speed * axis_y->speed_unit;
  855. axis_y->acc_time = acc_pulse;
  856. axis_y->dec_time = dec_pulse;
  857. axis_add_pp_task(axis_y, PosToPulse(Y_AXIS,pos1), speed1);
  858. axis_add_pp_task(axis_y, PosToPulse(Y_AXIS,pos2), speed2);
  859. axis_start_pp_task(axis_y);
  860. }
  861. break;
  862. case Z_AXIS:
  863. {
  864. SetStopSelect(Z_AXIS,PP_NoStop);
  865. axis_init_task(axis_z,dir);
  866. axis_z->start_speed = start_speed * axis_z->speed_unit;
  867. axis_z->stop_speed = stop_speed * axis_z->speed_unit;
  868. axis_z->acc_time = acc_pulse;
  869. axis_z->dec_time = dec_pulse;
  870. axis_add_pp_task(axis_z, PosToPulse(Z_AXIS,pos1), speed1);
  871. axis_add_pp_task(axis_z, PosToPulse(Z_AXIS,pos2), speed2);
  872. axis_start_pp_task(axis_z);
  873. }
  874. break;
  875. default:
  876. break;
  877. }
  878. }
  879. //三段速度移动距离
  880. void AxisMoveThreePos(unsigned short axis,unsigned short speed1,long pos1,unsigned short speed2,long pos2,unsigned short speed3,long pos3,int dir)
  881. {
  882. switch(axis)
  883. {
  884. case X_AXIS:
  885. {
  886. axis_init_task(axis_x,dir);
  887. SetStopSelect(X_AXIS,PP_Stop);
  888. axis_add_pp_task(axis_x, PosToPulse(X_AXIS,pos1), speed1);
  889. axis_add_pp_task(axis_x, PosToPulse(X_AXIS,pos2), speed2);
  890. axis_add_pp_task(axis_x, PosToPulse(X_AXIS,pos3), speed3);
  891. axis_start_pp_task(axis_x);
  892. }break;
  893. case Y_AXIS:
  894. {
  895. axis_init_task(axis_y,dir);
  896. SetStopSelect(Y_AXIS,PP_Stop);
  897. axis_add_pp_task(axis_y, PosToPulse(Y_AXIS,pos1), speed1);
  898. axis_add_pp_task(axis_y, PosToPulse(Y_AXIS,pos2), speed2);
  899. axis_add_pp_task(axis_y, PosToPulse(Y_AXIS,pos3), speed3);
  900. axis_start_pp_task(axis_y);
  901. }
  902. break;
  903. case Z_AXIS:
  904. {
  905. axis_init_task(axis_z,dir);
  906. SetStopSelect(Z_AXIS,PP_Stop);
  907. axis_add_pp_task(axis_z, PosToPulse(Z_AXIS,pos1), speed1);
  908. axis_add_pp_task(axis_z, PosToPulse(Z_AXIS,pos2), speed2);
  909. axis_add_pp_task(axis_z, PosToPulse(Z_AXIS,pos3), speed3);
  910. axis_start_pp_task(axis_z);
  911. }
  912. break;
  913. default:;
  914. }
  915. }
  916. //三段速度移动距离不停止
  917. void AxisMoveThreePosNoStop(unsigned short axis,unsigned short speed1,long pos1,unsigned short speed2,long pos2,unsigned short speed3,long pos3,int dir)
  918. {
  919. switch(axis)
  920. {
  921. case X_AXIS:
  922. {
  923. axis_init_task(axis_x,dir);
  924. SetStopSelect(X_AXIS,PP_NoStop);
  925. axis_add_pp_task(axis_x, PosToPulse(X_AXIS,pos1), speed1);
  926. axis_add_pp_task(axis_x, PosToPulse(X_AXIS,pos2), speed2);
  927. axis_add_pp_task(axis_x, PosToPulse(X_AXIS,pos3), speed3);
  928. axis_start_pp_task(axis_x);
  929. }break;
  930. case Y_AXIS:
  931. {
  932. axis_init_task(axis_y,dir);
  933. SetStopSelect(Y_AXIS,PP_NoStop);
  934. axis_add_pp_task(axis_y, PosToPulse(Y_AXIS,pos1), speed1);
  935. axis_add_pp_task(axis_y, PosToPulse(Y_AXIS,pos2), speed2);
  936. axis_add_pp_task(axis_y, PosToPulse(Y_AXIS,pos3), speed3);
  937. axis_start_pp_task(axis_y);
  938. }break;
  939. case Z_AXIS:
  940. {
  941. axis_init_task(axis_z,dir);
  942. SetStopSelect(Z_AXIS,PP_NoStop);
  943. axis_add_pp_task(axis_z, PosToPulse(Z_AXIS,pos1), speed1);
  944. axis_add_pp_task(axis_z, PosToPulse(Z_AXIS,pos2), speed2);
  945. axis_add_pp_task(axis_z, PosToPulse(Z_AXIS,pos3), speed3);
  946. axis_start_pp_task(axis_z);
  947. }break;
  948. default:;
  949. }
  950. }