AxisController.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.Concurrent;
  4. using System.IO.Ports;
  5. using System.Linq;
  6. using System.Linq.Expressions;
  7. using System.Text;
  8. using System.Threading;
  9. using PaintDotNet.Base.SettingModel;
  10. using StageController.M3H;
  11. using System.Threading.Tasks;
  12. namespace StageController
  13. {
  14. public delegate void DataReceiveEvent(CommandBase command, Result result, string msg);
  15. public class AxisController
  16. {
  17. //定义接收数据事件
  18. public event DataReceiveEvent DataReceived;
  19. #region Com Connection
  20. private SerialPort m_serialPort;
  21. private string m_portName;
  22. private int m_baudRate;
  23. #endregion
  24. private ConcurrentQueue<CommandBase> m_cmdQueueM;
  25. private Thread m_waitingThread;
  26. private bool IsSimulation = false;
  27. /// <summary>
  28. /// 发送试错次数
  29. /// </summary>
  30. private int m_retryCount = 3;
  31. #region AxisList
  32. private Dictionary<M3HAxisType, M3HAxis> AxisList;
  33. private M3HAxis m_AxisX => AxisList[M3HAxisType.X];
  34. private M3HAxis m_AxisY => AxisList[M3HAxisType.Y];
  35. private M3HAxis m_AxisZ => AxisList[M3HAxisType.Z];
  36. private void InitAxisList()
  37. {
  38. AxisList = new Dictionary<M3HAxisType, M3HAxis>();
  39. AxisList.Add(M3HAxisType.X, new M3HAxis(M3HAxisType.X, this));
  40. AxisList.Add(M3HAxisType.Y, new M3HAxis(M3HAxisType.Y, this));
  41. AxisList.Add(M3HAxisType.Z, new M3HAxis(M3HAxisType.Z, this));
  42. }
  43. #endregion
  44. #region AxisShell List 虚拟轴控制
  45. private Dictionary<AxisType, AxisShell> AxisShellList;
  46. /// <summary>
  47. /// M3H--> 0:停机自由,1:停机锁死,2:正向连续,3:反向连续,4:正向步进,5:反向步进
  48. /// </summary>
  49. public int StateX => AxisShellList[AxisType.X].State;
  50. /// <summary>
  51. /// M3H--> 0:停机自由,1:停机锁死,2:正向连续,3:反向连续,4:正向步进,5:反向步进
  52. /// </summary>
  53. public int StateY => AxisShellList[AxisType.Y].State;
  54. /// <summary>
  55. /// M3H--> 0:停机自由,1:停机锁死,2:正向连续,3:反向连续,4:正向步进,5:反向步进
  56. /// </summary>
  57. public int StateZ => AxisShellList[AxisType.Z].State;
  58. //public bool StageRelox { get => StateX + StateY + StateZ == 0; }
  59. public double X => AxisShellList[AxisType.X].Actual;
  60. public double Y => AxisShellList[AxisType.Y].Actual;
  61. public double Z => AxisShellList[AxisType.Z].Actual;
  62. private void InitAxisShellList()
  63. {
  64. AxisShellList = new Dictionary<AxisType, AxisShell>();
  65. AxisShellList.Add(AxisType.X, new AxisShell(AxisType.X, this));
  66. AxisShellList.Add(AxisType.Y, new AxisShell(AxisType.Y, this));
  67. AxisShellList.Add(AxisType.Z, new AxisShell(AxisType.Z, this));
  68. AxisShellList[AxisType.X].SpeedConvert = SpeedConvert;
  69. AxisShellList[AxisType.Y].SpeedConvert = SpeedConvert;
  70. AxisShellList[AxisType.Z].SpeedConvert = SpeedConvert;
  71. }
  72. private int SpeedConvert(int seed)
  73. {
  74. switch (seed)
  75. {
  76. case 2:
  77. return 30000;
  78. case 4:
  79. return 30000;
  80. case 8:
  81. return 25000;
  82. case 10:
  83. return 22500;
  84. case 20:
  85. return 15200;
  86. case 40:
  87. return 9650;
  88. case 60:
  89. return 6950;
  90. case 80:
  91. return 5450;
  92. case 100:
  93. return 500;
  94. }
  95. return 5000;
  96. }
  97. #endregion
  98. #region Instance
  99. private static AxisController m_instance = null;
  100. private AxisController()
  101. {
  102. InitAxisList();
  103. InitAxisShellList();
  104. //IsSimulation = true;
  105. m_cmdQueueM = new ConcurrentQueue<CommandBase>();
  106. CommandBase.AddReceivedHandle(typeof(CommandAllPosition), new Action<CommandBase>(PositionUpdate));
  107. CommandBase.AddReceivedHandle(typeof(CommandVersion), new Action<CommandBase>(VersionUpdate));
  108. }
  109. public static AxisController GetInstance()
  110. {
  111. if (m_instance == null)
  112. {
  113. m_instance = new AxisController();
  114. }
  115. return m_instance;
  116. }
  117. #endregion
  118. public LoadingStageModel LoadingStageModel
  119. {
  120. set
  121. {
  122. var m_loadingStageModel = value;
  123. m_portName = m_loadingStageModel.BaseSetPort;
  124. m_baudRate = m_loadingStageModel.BaseSetBps;
  125. AxisShellList[AxisType.X].Stepping = double.Parse(m_loadingStageModel.SteppingX);
  126. AxisShellList[AxisType.Y].Stepping = double.Parse(m_loadingStageModel.SteppingY);
  127. AxisShellList[AxisType.Z].Stepping = double.Parse(m_loadingStageModel.SteppingZ);
  128. m_AxisX.Stepping = double.Parse(m_loadingStageModel.SteppingX);
  129. m_AxisX.Reversed = true;
  130. m_AxisY.Stepping = double.Parse(m_loadingStageModel.SteppingY);
  131. m_AxisZ.Stepping = double.Parse(m_loadingStageModel.SteppingZ);
  132. }
  133. }
  134. #region Open Close
  135. private bool m_running = false;
  136. /// <summary>
  137. /// 平台是否正常开启
  138. /// </summary>
  139. public bool IsOpen
  140. {
  141. get => m_running;
  142. }
  143. public string Version { get; private set; }
  144. // TODO: 此函数测试期间使用
  145. public string Open()
  146. {
  147. try
  148. {
  149. if (!m_running)
  150. Open(m_portName, m_baudRate, Parity.None, 8, StopBits.One);
  151. return "";
  152. }
  153. catch (Exception ex)
  154. {
  155. return ex.Message;
  156. }
  157. }
  158. public void Open(string portName, int baudRate, Parity parity, int dataBits, StopBits stopBits)
  159. {
  160. if (m_serialPort == null || !m_serialPort.IsOpen)
  161. {
  162. m_serialPort = new SerialPort(portName, baudRate, parity, dataBits, stopBits);
  163. m_serialPort.Encoding = Encoding.ASCII;
  164. m_serialPort.ReadTimeout = 500;
  165. m_serialPort.DataReceived += new SerialDataReceivedEventHandler(SerialPort_DataReceived);
  166. m_serialPort.Open();
  167. CommandBase.SerialPort = m_serialPort;
  168. }
  169. if (!m_running)
  170. {
  171. m_cmdQueueM = new ConcurrentQueue<CommandBase>();
  172. m_curCommand = null;
  173. m_waitingThread = new Thread(new ThreadStart(Runtime));
  174. m_waitingThread.Start();
  175. m_running = true;
  176. ResetParameter();
  177. }
  178. }
  179. public void Close()
  180. {
  181. FreeStage();
  182. FreeZ();
  183. _closing = true;
  184. }
  185. #endregion
  186. // 接收串口返回数据
  187. private void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
  188. {
  189. if (!m_running) return;
  190. string recvData = ((SerialPort)sender).ReadExisting();
  191. m_curCommand.Receive(recvData);
  192. }
  193. #region Application Event
  194. private List<IStageEvent> m_listApp = new List<IStageEvent>();
  195. public void AddApp(IStageEvent app)
  196. {
  197. var wk = new WeakReference(app);//弱引用
  198. m_listApp.Add((wk.Target as IStageEvent));
  199. }
  200. public void RemoveApp(IStageEvent app)
  201. {
  202. m_listApp.Remove(app);
  203. }
  204. #endregion
  205. #region Command Runtime
  206. private CommandBase m_curCommand = null;
  207. public void AddCommand(CommandBase command)
  208. {
  209. m_cmdQueueM.Enqueue(command);
  210. }
  211. private void Runtime()
  212. {
  213. while (m_running)
  214. {
  215. Thread.Sleep(0);
  216. Process();
  217. }
  218. }
  219. enum ConnectErrorType
  220. {
  221. SendFailed,
  222. Timeout
  223. }
  224. private void Process()
  225. {
  226. if (m_currentMoveflow != null && m_currentMoveflow.Done)
  227. StopMoveflow();
  228. #region 虚拟轴控制
  229. foreach (var axis in AxisShellList.Values)
  230. {
  231. //axis.Execute();
  232. // new Task(axis.Execute).Start();
  233. }
  234. if (IsSimulation)
  235. {
  236. if (_closing)
  237. {
  238. m_running = false;
  239. _closing = false;
  240. }
  241. return;
  242. }
  243. #endregion
  244. #region 执行当前指令
  245. if (m_curCommand != null)
  246. {
  247. switch (m_curCommand.State)
  248. {
  249. case -1: //error:停止当前运动控制服务.
  250. if (m_curCommand.SendCount > m_retryCount) CommandError();
  251. m_curCommand.Send();
  252. return;
  253. case 1: //等待平台应答
  254. if (m_curCommand.IsTimeout)
  255. {
  256. m_curCommand = null;
  257. // CommandTimeout();
  258. }
  259. break;
  260. case 2: //完成应答处理
  261. m_curCommand = null;
  262. break;
  263. case 0: //初始值, 此处不应该出现0的情况
  264. //m_curCommand.Send()
  265. default:
  266. break;
  267. }
  268. }
  269. #endregion
  270. #region 开始一个新指令,
  271. if (m_curCommand == null)
  272. {
  273. if (m_cmdQueueM.IsEmpty && _closing)
  274. {
  275. m_running = false;
  276. _closing = false;
  277. return;
  278. }
  279. if (m_cmdQueueM.IsEmpty || !m_cmdQueueM.TryDequeue(out m_curCommand))
  280. { // 空闲时间刷新位置
  281. // m_curCommand = new CommandAllPosition();
  282. }
  283. if (m_curCommand != null && !m_curCommand.Send())
  284. { //指令发送失败
  285. CommandError();
  286. }
  287. }
  288. #endregion
  289. }
  290. private void CommandError()
  291. {
  292. Logs.Write("CommandError");
  293. foreach (var app in m_listApp) app.OnErrorSend();
  294. m_curCommand = null;
  295. }
  296. private void CommandTimeout()
  297. {
  298. Logs.Write("CommandTimeout");
  299. foreach (var app in m_listApp) app.OnTimeoutConnect();
  300. // m_running = false;
  301. // IsSimulation = true;
  302. m_serialPort.Close();
  303. }
  304. public void RefreshPosition()
  305. {
  306. if (m_cmdQueueM.Any(e => e is CommandAllPosition))
  307. return;
  308. AddCommand(new CommandAllPosition());
  309. }
  310. private void PositionUpdate(CommandBase cmd)
  311. {
  312. var posInfo = (CommandAllPosition)cmd;
  313. m_AxisX.Step = posInfo.XStep;
  314. m_AxisY.Step = posInfo.YStep;
  315. m_AxisZ.Step = posInfo.ZStep;
  316. m_AxisX.Limit = (int)posInfo.XBorder;
  317. m_AxisY.Limit = (int)posInfo.YBorder;
  318. m_AxisZ.Limit = (int)posInfo.ZBorder;
  319. m_AxisX.State = posInfo.XState;
  320. m_AxisY.State = posInfo.YState;
  321. m_AxisZ.State = posInfo.ZState;
  322. AxisShellList[AxisType.X].Step = m_AxisX.Reversed ? -posInfo.XStep : posInfo.XStep;
  323. AxisShellList[AxisType.Y].Step = posInfo.YStep;
  324. AxisShellList[AxisType.Z].Step = posInfo.ZStep;
  325. AxisShellList[AxisType.X].Limit = (int)posInfo.XBorder;
  326. AxisShellList[AxisType.Y].Limit = (int)posInfo.YBorder;
  327. AxisShellList[AxisType.Z].Limit = (int)posInfo.ZBorder;
  328. AxisShellList[AxisType.X].State = posInfo.XState;
  329. AxisShellList[AxisType.Y].State = posInfo.YState;
  330. AxisShellList[AxisType.Z].State = posInfo.ZState;
  331. for (int i = 0; i < m_listApp.Count; i++)
  332. {
  333. var app = m_listApp[i];
  334. if (app == null)
  335. m_listApp.RemoveAt(i--);
  336. else
  337. app.OnUpdatePosition();
  338. }
  339. }
  340. private void VersionUpdate(CommandBase cmd)
  341. {
  342. Version = (cmd as CommandVersion).Version;
  343. }
  344. #endregion
  345. #region Motion
  346. /// <summary>
  347. /// 平台平移
  348. /// </summary>
  349. /// <param name="x">X轴移动距离(μm)</param>
  350. /// <param name="y">Y轴移动距离(μm)</param>
  351. public void Move(double x, double y)
  352. {
  353. if (m_currentMoveflow != null) StopMoveflow();
  354. //throw new Exception("MoveflowBusy");
  355. AxisShellList[AxisType.X].Move(x);
  356. AxisShellList[AxisType.Y].Move(y);
  357. m_AxisY.Move(y);
  358. m_AxisX.Move(x);
  359. }
  360. public void To(double x, double y)
  361. {
  362. if (m_currentMoveflow != null) StopMoveflow();
  363. //throw new Exception("MoveflowBusy");
  364. AxisShellList[AxisType.X].To(x);
  365. AxisShellList[AxisType.Y].To(y);
  366. m_AxisY.To(y);
  367. m_AxisX.To(x);
  368. }
  369. public void Up(double z)
  370. {
  371. if (m_currentMoveflow != null) StopMoveflow();
  372. // throw new Exception("MoveflowBusy");
  373. AxisShellList[AxisType.Z].Move(z);
  374. m_AxisZ.Move(z);
  375. }
  376. public void UpTo(double z)
  377. {
  378. if (m_currentMoveflow != null) StopMoveflow();
  379. // throw new Exception("MoveflowBusy");
  380. AxisShellList[AxisType.Z].To(z);
  381. m_AxisZ.To(z);
  382. }
  383. public void Up(int z)
  384. {
  385. if (m_currentMoveflow != null) StopMoveflow();
  386. //throw new Exception("MoveflowBusy");
  387. AxisShellList[AxisType.Z].Move(z);
  388. m_AxisZ.Move(z);
  389. }
  390. /// <summary>
  391. /// Z连续
  392. /// </summary>
  393. /// <param name="isToTop">true:正向.false:反向</param>
  394. public void GoTop(bool isToTop)
  395. {
  396. if (m_currentMoveflow != null) StopMoveflow();
  397. //throw new Exception("MoveflowBusy");
  398. AxisShellList[AxisType.Z].Slide(isToTop);
  399. m_AxisZ.Slide(isToTop);
  400. }
  401. /// <summary>
  402. /// 平台朝一个水平方向连续运动
  403. /// </summary>
  404. /// <param name="direction">0-7 从X周负向逆时针</param>
  405. public void Split(int direction)
  406. {
  407. if (m_currentMoveflow != null) StopMoveflow();
  408. // throw new Exception("MoveflowBusy");
  409. switch (direction)
  410. {
  411. case 0:
  412. m_AxisX.Slide(false);
  413. AxisShellList[AxisType.X].Slide(false);
  414. break;
  415. case 1:
  416. AxisShellList[AxisType.X].Slide(false);
  417. AxisShellList[AxisType.Y].Slide(false);
  418. m_AxisX.Slide(false);
  419. m_AxisY.Slide(false);
  420. break;
  421. case 2:
  422. AxisShellList[AxisType.Y].Slide(false);
  423. m_AxisY.Slide(false);
  424. break;
  425. case 3:
  426. AxisShellList[AxisType.X].Slide(true);
  427. AxisShellList[AxisType.Y].Slide(false);
  428. m_AxisX.Slide(true);
  429. m_AxisY.Slide(false);
  430. break;
  431. case 4:
  432. AxisShellList[AxisType.X].Slide(true);
  433. m_AxisX.Slide(true);
  434. break;
  435. case 5:
  436. AxisShellList[AxisType.X].Slide(true);
  437. AxisShellList[AxisType.Y].Slide(true);
  438. m_AxisX.Slide(true);
  439. m_AxisY.Slide(true);
  440. break;
  441. case 6:
  442. AxisShellList[AxisType.Y].Slide(true);
  443. m_AxisY.Slide(true);
  444. break;
  445. case 7:
  446. AxisShellList[AxisType.X].Slide(false);
  447. AxisShellList[AxisType.Y].Slide(true);
  448. m_AxisX.Slide(false);
  449. m_AxisY.Slide(true);
  450. break;
  451. }
  452. }
  453. #endregion
  454. #region Stop
  455. public void FreeStage()
  456. {
  457. StopMoveflow();
  458. AxisShellList[AxisType.X].Stop();
  459. AxisShellList[AxisType.Y].Stop();
  460. Stop(M3HAxisType.X, HandLock.F);
  461. Stop(M3HAxisType.Y, HandLock.F);
  462. }
  463. public void LockStage()
  464. {
  465. StopMoveflow();
  466. AxisShellList[AxisType.X].Stop();
  467. AxisShellList[AxisType.Y].Stop();
  468. Stop(M3HAxisType.X, HandLock.S);
  469. Stop(M3HAxisType.Y, HandLock.S);
  470. }
  471. public void ClearPosXY()
  472. {
  473. m_AxisX.ResetPosition();
  474. m_AxisY.ResetPosition();
  475. RefreshPosition();
  476. AxisShellList[AxisType.X].ResetPosition();
  477. AxisShellList[AxisType.Y].ResetPosition();
  478. }
  479. public void FreeZ()
  480. {
  481. StopMoveflow();
  482. Stop(M3HAxisType.Z, HandLock.F);
  483. AxisShellList[AxisType.Z].Stop();
  484. }
  485. public void LockZ()
  486. {
  487. Stop(M3HAxisType.Z, HandLock.S);
  488. AxisShellList[AxisType.Z].Stop();
  489. }
  490. public void ClearPosZ()
  491. {
  492. m_AxisZ.ResetPosition();
  493. AxisShellList[AxisType.Z].ResetPosition();
  494. }
  495. private void Stop(M3HAxisType axis, HandLock hlock)
  496. {
  497. AxisList[axis].Stop(hlock);
  498. }
  499. #endregion
  500. #region Moveflow
  501. /// <summary>
  502. /// 平台中心位置
  503. /// </summary>
  504. private int _centerX = 106500;
  505. /// <summary>
  506. /// 平台中心位置
  507. /// </summary>
  508. private int _centerY = 73500;
  509. /// <summary>
  510. /// 轴锁定状态常量
  511. /// </summary>
  512. const int STATE_LOCK = 1;
  513. /// <summary>
  514. /// 正边界
  515. /// </summary>
  516. const int LIMIT_P = (int)Border.F;
  517. /// <summary>
  518. /// 负边界
  519. /// </summary>
  520. const int LIMIT_N = (int)Border.R;
  521. /// <summary>
  522. /// 边界内
  523. /// </summary>
  524. const int LIMIT_I = (int)Border.I;
  525. /// <summary>
  526. /// 运行中流程
  527. /// </summary>
  528. Moveflow m_currentMoveflow;
  529. private bool _closing;
  530. Moveflow StartMoveflow()
  531. {
  532. m_cmdQueueM = new ConcurrentQueue<CommandBase>();
  533. return new Moveflow();
  534. }
  535. void StopMoveflow()
  536. {
  537. if (m_currentMoveflow == null) return;
  538. m_currentMoveflow.Stop();
  539. m_currentMoveflow = null;
  540. }
  541. /// <summary>
  542. /// 开始中心移动流程
  543. /// </summary>
  544. public void ToCenter()
  545. {
  546. if (IsSimulation) return;
  547. var mf = StartMoveflow();
  548. mf.Add(() =>
  549. {
  550. m_AxisY.Stop(HandLock.S);
  551. m_AxisX.Stop(HandLock.S);
  552. },
  553. () => { return m_AxisX.State == STATE_LOCK && m_AxisY.State == STATE_LOCK; });
  554. mf.Add(() =>
  555. {
  556. m_AxisX.Slide(false);
  557. m_AxisY.Slide(false);
  558. },
  559. () => { return m_AxisX.Limit == LIMIT_N && m_AxisY.Limit == LIMIT_N; });
  560. mf.Add(
  561. () =>
  562. {
  563. m_AxisY.Move(_centerY);
  564. m_AxisX.Move(_centerX);
  565. },
  566. () => { return m_AxisX.Limit == LIMIT_I || m_AxisY.Limit == LIMIT_I; });
  567. mf.Add(() => { }, () => { return m_AxisX.State == STATE_LOCK && m_AxisY.State == STATE_LOCK; });
  568. mf.Start();
  569. m_currentMoveflow = mf;
  570. }
  571. /// <summary>
  572. /// 开始复位流程
  573. /// </summary>
  574. public void ResetStage(Action actDone)
  575. {
  576. if (IsSimulation)//模拟模式
  577. {
  578. ClearPosXY();
  579. actDone();
  580. return;
  581. }
  582. var mf = StartMoveflow();
  583. mf.Add(() =>
  584. {
  585. m_AxisY.Stop(HandLock.S);
  586. m_AxisX.Stop(HandLock.S);
  587. },
  588. null// () => { return m_AxisX.State == STATE_LOCK && m_AxisY.State == STATE_LOCK; }
  589. );
  590. mf.Add(() =>
  591. {
  592. m_AxisX.Slide(false);
  593. m_AxisY.Slide(false);
  594. },
  595. () =>
  596. {
  597. RefreshPosition();
  598. return m_AxisX.Limit == LIMIT_N && m_AxisY.Limit == LIMIT_N;
  599. });
  600. mf.Add(() =>
  601. {
  602. ClearPosXY();
  603. },
  604. () => { return X == 0 && Y == 0; });
  605. mf.Start();
  606. mf.OnMoveflowDone += actDone;
  607. m_currentMoveflow = mf;
  608. }
  609. public void ZScan(double start, double steplen, int times, Action shoot, Action actDone)
  610. {
  611. if (IsSimulation)//模拟模式
  612. return;
  613. var mf = StartMoveflow();
  614. mf.Add(
  615. () => m_AxisZ.Stop(HandLock.S),
  616. null);
  617. mf.Add(() =>
  618. {
  619. m_AxisZ.To(start);
  620. },
  621. () => {
  622. RefreshPosition();
  623. return Math.Abs(m_AxisZ.Actual - start) < m_AxisZ.Stepping; });
  624. mf.Add(shoot, null);
  625. for (int i = 0; i < times - 1; i++)
  626. {
  627. mf.Add(() =>
  628. {
  629. m_AxisZ.Move(steplen);
  630. start += steplen;
  631. },
  632. () => {
  633. RefreshPosition();
  634. return Math.Abs(m_AxisZ.Actual - start) < m_AxisZ.Stepping; });
  635. mf.Add(shoot, null);
  636. }
  637. mf.Start();
  638. mf.OnMoveflowDone += actDone;
  639. m_currentMoveflow = mf;
  640. }
  641. #endregion
  642. #region Speed
  643. public void SetSpeedXY(int speed)
  644. {
  645. m_AxisX.Speed = speed;
  646. m_AxisY.Speed = speed;
  647. AxisShellList[AxisType.X].Speed = speed;
  648. AxisShellList[AxisType.Y].Speed = speed;
  649. }
  650. public void SetSpeedZ(int speed)
  651. {
  652. m_AxisZ.Speed = speed;
  653. }
  654. #endregion
  655. public void ResetParameter()
  656. {
  657. AddCommand(new CommandAllPosition());
  658. AddCommand(new CommandParameter() { AxisSelect = 'x' });
  659. AddCommand(new CommandParameter() { AxisSelect = 'y' });
  660. // AddCommand(new CommandParameter() { AxisSelect = 'z', LockOrFree = 'F' }); // z轴参数下发不识别
  661. AddCommand(new CommandVersion());
  662. }
  663. /// <summary>
  664. /// 拼图模式
  665. /// </summary>
  666. public void SetMergeMode(bool isMerge)
  667. {
  668. if (isMerge)
  669. AddCommand(new CommandGlobal(ControlType.P));
  670. else
  671. AddCommand(new CommandGlobal(ControlType.Q));
  672. }
  673. /// <summary>
  674. /// 启用/禁用摇杆
  675. /// </summary>
  676. /// <param name="isAvailable">摇杆可用</param>
  677. public void SetRockerEnabel(bool isAvailable)
  678. {
  679. }
  680. }
  681. }