GalilSocketSimulator.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. using Aitex.Common.Util;
  2. using Aitex.Core.Util;
  3. using MECF.Framework.Common.Beckhoff.AxisProvider;
  4. using MECF.Framework.Common.Device.Galil;
  5. using MECF.Framework.Common.Net;
  6. using MECF.Framework.Common.Simulator;
  7. using MECF.Framework.Simulator.Core.Driver;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.IO;
  11. using System.Text;
  12. namespace CyberX8_Simulator.Devices
  13. {
  14. public class GalilSocketSimulator : SocketDeviceSimulator
  15. {
  16. #region 常量
  17. //最大运动轴数量(abcdefg)
  18. private const int MAX_AXIS_NUM = 8;
  19. //GalilControllerData最大数据长度
  20. private const int MAX_CONTROL_DATA_LENGTH_21 = 264;
  21. private const int MAX_CONTROL_DATA_LENGTH_40 = 366;
  22. //GalilAxisData最大数据长度
  23. private const int MAX_AXIS_DATA_LENGTH_21 = 28;
  24. private const int MAX_AXIS_DATA_LENGTH_40 = 36;
  25. private const string TARGET_VELOCITY = "TargetVelocity";
  26. private const string TARGET_ACCEL = "TargetAcceleration";
  27. private const string TARGET_DECEL = "TargetDeceleration";
  28. private const string TARGET_POSITION = "TargetPosition";
  29. private const string SWITCH_SIGNAL = "SwitchSignal";
  30. private const string ACTUAL_POSITION = "ActualPosition";
  31. private const string AUXILIARY_POSITION = "AuxiliaryPosition";
  32. private const string HOMING_SIGNAL = "HomingSignal";
  33. private const string MOTION_SIGNAL = "MotionSignal";
  34. private const string STOP_SIGNAL = "StopSignal";
  35. private const double MOTOR_POSITION_FACTOR = 31.25;
  36. private const string GALIL_21 = "Galil21";
  37. private const string GALIL_40 = "Galil40";
  38. #endregion
  39. #region 内部变量
  40. private IByteTransform byteTransform = new BigEndianByteTransformBase();
  41. /// <summary>
  42. /// Galil数据
  43. /// </summary>
  44. private GalilControllerData _galilControlData = new GalilControllerData();
  45. /// <summary>
  46. /// Axis名称字典(key:axisName, value:index)
  47. /// </summary>
  48. private Dictionary<string, int> _axisNameIndexDic = new Dictionary<string, int>();
  49. /// <summary>
  50. /// Axis名称列表(index - axisName)
  51. /// </summary>
  52. private string[] _nameAxisList = new string[MAX_AXIS_NUM];
  53. /// <summary>
  54. /// ModuleName
  55. /// </summary>
  56. /// <param name="port"></param>
  57. private string _moduleName;
  58. /// <summary>
  59. /// Galil Type
  60. /// </summary>
  61. private string _galilType;
  62. /// <summary>
  63. /// GalilControllerData数据长度
  64. /// </summary>
  65. private int _controlDataLength;
  66. /// <summary>
  67. /// GalilAxisDatas数据长度
  68. /// </summary>
  69. private int _axisDataLength;
  70. /// <summary>
  71. /// MotorPosition比例系数字典(index - motorPositionRate)
  72. /// </summary>
  73. private Dictionary<string, double> _motorPositionRateDic = new Dictionary<string, double>();
  74. #endregion
  75. /// <summary>
  76. /// 构造函数
  77. /// </summary>
  78. /// <param name="port"></param>
  79. public GalilSocketSimulator(int port) :base(port)
  80. {
  81. InitData(port);
  82. }
  83. /// <summary>
  84. /// 解析信息
  85. /// </summary>
  86. /// <param name="data"></param>
  87. protected override void ProcessUnsplitMessage(byte[] data)
  88. {
  89. string cmdStr = ASCIIEncoding.ASCII.GetString(data);
  90. if (CheckCmdValid(cmdStr))
  91. {
  92. var cmdOperation = AnalyseCommand(cmdStr);
  93. byte[] response;
  94. if(cmdOperation.Item1 == "QR")
  95. {
  96. //Read
  97. response = CreateReadResponse(_galilControlData);
  98. }
  99. else
  100. {
  101. //Write
  102. SetOperation(cmdOperation.Item1, cmdOperation.Item2, cmdOperation.Item3);
  103. response = CreateWriteResponse();
  104. }
  105. OnWriteMessage(response);
  106. }
  107. else
  108. {
  109. OnWriteMessage(CreateError());
  110. }
  111. }
  112. /// <summary>
  113. /// 读回复
  114. /// </summary>
  115. /// <param name="flag"></param>
  116. /// <param name="channel"></param>
  117. /// <param name="command"></param>
  118. /// <param name="registerCount"></param>
  119. /// <param name="values"></param>
  120. /// <returns></returns>
  121. private byte[] CreateReadResponse(GalilControllerData data)
  122. {
  123. //数据头(4 bytes)
  124. int headLength = 4;
  125. byte[] result = new byte[headLength + _controlDataLength];
  126. result[0] = 0x00;
  127. result[1] = 0x00;
  128. short dataLength = (short)(headLength + _controlDataLength);
  129. Array.Copy(byteTransform.GetBytes(dataLength), 0, result, 2, 2);
  130. //数据体(MAX_CONTROL_DATA_LENGTH bytes)
  131. switch (_galilType)
  132. {
  133. case GALIL_21:
  134. Array.Copy(CodeControlData21(data), 0, result, 4, MAX_CONTROL_DATA_LENGTH_21);
  135. break;
  136. case GALIL_40:
  137. Array.Copy(CodeControlData40(data), 0, result, 4, MAX_CONTROL_DATA_LENGTH_40);
  138. break;
  139. default:
  140. break;
  141. }
  142. return result;
  143. }
  144. /// <summary>
  145. /// 写回复
  146. /// </summary>
  147. /// <param name="flag"></param>
  148. /// <param name="channel"></param>
  149. /// <param name="command"></param>
  150. /// <param name="startAddress"></param>
  151. /// <param name="value"></param>
  152. /// <returns></returns>
  153. private byte[] CreateWriteResponse()
  154. {
  155. //数据头(1 bytes)
  156. int headLength = 1;
  157. byte[] result = new byte[headLength];
  158. result[0] = 0x3A;
  159. return result;
  160. }
  161. /// <summary>
  162. /// 错误回复
  163. /// </summary>
  164. /// <param name="flag"></param>
  165. /// <param name="channel"></param>
  166. /// <param name="command"></param>
  167. /// <param name="error"></param>
  168. /// <returns></returns>
  169. private byte[] CreateError()
  170. {
  171. int headLength = 1;
  172. byte[] result = new byte[headLength];
  173. //Command not valid in program
  174. result[0] = 0x03;
  175. return result;
  176. }
  177. /// <summary>
  178. /// 初始化
  179. /// </summary>
  180. private void InitData(int port)
  181. {
  182. //初始化AxisData(最大MAX_AXIS_NUM个axis)
  183. _galilControlData.GalilAxisDatas = new List<GalilAxisData>();
  184. for (int i = 0; i < MAX_AXIS_NUM; i++)
  185. {
  186. _galilControlData.GalilAxisDatas.Add(new GalilAxisData());
  187. _galilControlData.GalilAxisDatas[i].Status = 0x01;
  188. }
  189. _galilControlData.Inputs = new byte[10];
  190. _galilControlData.Outputs = new byte[10];
  191. //电机数据更新事件
  192. MotorSimulator.Instance.OnUpdateVariableValueChanged += UpdataRealTimeMotionData;
  193. //加载对应配置文件 GalilControllerCfg-Simulator.xml
  194. string oldXmlPath = PathManager.GetCfgDir();
  195. string newXmlPath = oldXmlPath.Replace("CyberX8_Simulator", "CyberX8_RT") + "Devices\\GalilControllerCfg-Simulator.xml";
  196. GalilControllerCfg cfg = CustomXmlSerializer.Deserialize<GalilControllerCfg>(new FileInfo(newXmlPath));
  197. foreach (GalilDeviceConfig config in cfg.GalilDeviceConfigs)
  198. {
  199. if (port == config.Port)
  200. {
  201. _moduleName = config.Module;
  202. _galilType = config.GalilType;
  203. foreach (GalilAxisConfig item in config.GalilAxises)
  204. {
  205. _axisNameIndexDic[$"{config.Module}.{item.Name}"] = item.Index;
  206. _nameAxisList[item.Index] = $"{config.Module}.{item.Name}";
  207. }
  208. }
  209. }
  210. //加载AxisProviderCfg.xml
  211. oldXmlPath = PathManager.GetCfgDir();
  212. newXmlPath = oldXmlPath.Replace("CyberX8_Simulator", "CyberX8_RT") + "Devices\\AxisProviderCfg.xml";
  213. BeckhoffAxisProviderCfg axisProviderCfg = CustomXmlSerializer.Deserialize<BeckhoffAxisProviderCfg>(new FileInfo(newXmlPath));
  214. foreach(BeckhoffProviderAxis item in axisProviderCfg.Axes)
  215. {
  216. for (int i = 0; i < MAX_AXIS_NUM; i++)
  217. {
  218. if (_nameAxisList[i] == item.Name)
  219. {
  220. _motorPositionRateDic[item.Name] = item.MotorPositionRate;
  221. }
  222. }
  223. }
  224. if (_galilType == GALIL_40)
  225. {
  226. _controlDataLength = MAX_CONTROL_DATA_LENGTH_40;
  227. _axisDataLength = MAX_AXIS_DATA_LENGTH_40;
  228. _galilControlData.SBlocks = new byte[10];
  229. _galilControlData.TBlocks = new byte[10];
  230. }
  231. else
  232. {
  233. _controlDataLength = MAX_CONTROL_DATA_LENGTH_21;
  234. _axisDataLength = MAX_AXIS_DATA_LENGTH_21;
  235. _galilControlData.SBlocks = new byte[8];
  236. _galilControlData.TBlocks = new byte[8];
  237. }
  238. }
  239. #region Galil编码
  240. /// <summary>
  241. /// GalilControllerData编码(Galil21)
  242. /// </summary>
  243. /// <returns></returns>
  244. private byte[] CodeControlData21(GalilControllerData ctrlData)
  245. {
  246. byte[] result = new byte[MAX_CONTROL_DATA_LENGTH_21];
  247. int index = 0;
  248. //Sample(2 bytes)
  249. Array.Copy(BitConverter.GetBytes(ctrlData.Sample), 0, result, index, 2);
  250. index += 2;
  251. //Inputs(1*10 bytes)
  252. Array.Copy(ctrlData.Inputs, 0, result, index, 10);
  253. index += 10;
  254. //Outputs(1*10 bytes)
  255. Array.Copy(ctrlData.Outputs, 0, result, index, 10);
  256. index += 10;
  257. //Error Code(1 bytes)
  258. result[13] = ctrlData.ErrorCode;
  259. index++;
  260. //General Status(1 bytes)
  261. result[14] = ctrlData.Status;
  262. index++;
  263. //S Block(2+2+4=8 bytes)
  264. Array.Copy(ctrlData.SBlocks, 0, result, 15, 8);
  265. index += 8;
  266. //T Block(2+2+4=8 bytes)
  267. Array.Copy(ctrlData.TBlocks, 0, result, 23, 8);
  268. index += 8;
  269. //Axis Datas(28 * 8 bytes)
  270. for (int i = 0; i < MAX_AXIS_NUM; i++)
  271. {
  272. Array.Copy(CodeAxisData21(ctrlData.GalilAxisDatas[i]), 0, result, index, MAX_AXIS_DATA_LENGTH_21);
  273. index += MAX_AXIS_DATA_LENGTH_21;
  274. }
  275. return result;
  276. }
  277. /// <summary>
  278. /// GalilAxisData编码(Galil21)
  279. /// </summary>
  280. /// <param name="axisData"></param>
  281. /// <returns></returns>
  282. private byte[] CodeAxisData21(GalilAxisData axisData)
  283. {
  284. byte[] result = new byte[MAX_AXIS_DATA_LENGTH_21];
  285. int index = 0;
  286. //Status(2 bytes)
  287. Array.Copy(byteTransform.GetBytes(axisData.Status), 0, result, index, 2);
  288. index += 2;
  289. //Switches(1 bytes)
  290. result[index] = axisData.Switches;
  291. index++;
  292. //Stop Code(1 bytes)
  293. result[index] = axisData.StopCode;
  294. index++;
  295. //Reference Position(4 bytes)
  296. Array.Copy(BitConverter.GetBytes(axisData.ReferencePosition), 0, result, index, 4);
  297. index += 4;
  298. //Motor Position(4 bytes)
  299. Array.Copy(BitConverter.GetBytes(axisData.MotorPosition), 0, result, index, 4);
  300. index += 4;
  301. //Position Error
  302. Array.Copy(BitConverter.GetBytes(axisData.PositionError), 0, result, index, 4);
  303. index += 4;
  304. //Auxiliary Position
  305. Array.Copy(BitConverter.GetBytes(axisData.AuxiliaryPosition), 0, result, index, 4);
  306. index += 4;
  307. //Velocity
  308. Array.Copy(BitConverter.GetBytes(axisData.Velocity), 0, result, index, 4);
  309. index += 4;
  310. //Torque
  311. Array.Copy(BitConverter.GetBytes(axisData.Torque), 0, result, index, 2);
  312. index += 2;
  313. //Analog
  314. Array.Copy(BitConverter.GetBytes(axisData.Res), 0, result, index, 2);
  315. return result;
  316. }
  317. /// <summary>
  318. /// GalilControllerData编码(Galil40)
  319. /// </summary>
  320. /// <returns></returns>
  321. private byte[] CodeControlData40(GalilControllerData ctrlData)
  322. {
  323. byte[] result = new byte[MAX_CONTROL_DATA_LENGTH_40];
  324. int index = 0;
  325. //Sample(2 bytes)
  326. Array.Copy(BitConverter.GetBytes(ctrlData.Sample), 0, result, index, 2);
  327. index += 2;
  328. //Inputs(1*10 bytes)
  329. Array.Copy(ctrlData.Inputs, 0, result, index, 10);
  330. index += 10;
  331. //Outputs(1*10 bytes)
  332. Array.Copy(ctrlData.Outputs, 0, result, index, 10);
  333. index += 10;
  334. //reservers
  335. byte[] reservers = new byte[16];
  336. Array.Copy(reservers, 0, result, index, 16);
  337. index += 16;
  338. //ethernet
  339. byte[] ethernet = new byte[8];
  340. Array.Copy(ethernet, 0, result, index, 8);
  341. index += 8;
  342. //ethernet
  343. //Error Code(1 bytes)
  344. result[13] = ctrlData.ErrorCode;
  345. index++;
  346. //General Status(1 bytes)
  347. result[14] = ctrlData.Status;
  348. index++;
  349. //ampliferStatus
  350. byte[] ampliferStatus = new byte[4];
  351. Array.Copy(ampliferStatus, 0, result, index, 4);
  352. index += 4;
  353. //counterModel
  354. byte[] counterModel = new byte[6];
  355. Array.Copy(counterModel, 0, result, index, 6);
  356. index += 6;
  357. //S Block(10 bytes)
  358. Array.Copy(ctrlData.SBlocks, 0, result, index, 10);
  359. index += 10;
  360. //T Block(10 bytes)
  361. Array.Copy(ctrlData.TBlocks, 0, result, index, 10);
  362. index += 10;
  363. //Axis Datas(36 * 8 bytes)
  364. for (int i = 0; i < MAX_AXIS_NUM; i++)
  365. {
  366. Array.Copy(CodeAxisData40(ctrlData.GalilAxisDatas[i]), 0, result, index, MAX_AXIS_DATA_LENGTH_40);
  367. index += MAX_AXIS_DATA_LENGTH_40;
  368. }
  369. return result;
  370. }
  371. /// <summary>
  372. /// GalilAxisData编码(Galil40)
  373. /// </summary>
  374. /// <param name="axisData"></param>
  375. /// <returns></returns>
  376. private byte[] CodeAxisData40(GalilAxisData axisData)
  377. {
  378. byte[] result = new byte[MAX_AXIS_DATA_LENGTH_40];
  379. int index = 0;
  380. //Status(2 bytes)
  381. Array.Copy(byteTransform.GetBytes(axisData.Status), 0, result, index, 2);
  382. index += 2;
  383. //Switches(1 bytes)
  384. result[index] = axisData.Switches;
  385. index++;
  386. //Stop Code(1 bytes)
  387. result[index] = axisData.StopCode;
  388. index++;
  389. //Reference Position(4 bytes)
  390. Array.Copy(BitConverter.GetBytes(axisData.ReferencePosition), 0, result, index, 4);
  391. index += 4;
  392. //Motor Position(4 bytes)
  393. Array.Copy(BitConverter.GetBytes(axisData.MotorPosition), 0, result, index, 4);
  394. index += 4;
  395. //Position Error
  396. Array.Copy(BitConverter.GetBytes(axisData.PositionError), 0, result, index, 4);
  397. index += 4;
  398. //Auxiliary Position
  399. Array.Copy(BitConverter.GetBytes(axisData.AuxiliaryPosition), 0, result, index, 4);
  400. index += 4;
  401. //Velocity
  402. Array.Copy(BitConverter.GetBytes(axisData.Velocity), 0, result, index, 4);
  403. index += 4;
  404. //Torque
  405. Array.Copy(BitConverter.GetBytes(axisData.Torque), 0, result, index, 4);
  406. index += 4;
  407. //Analog
  408. Array.Copy(BitConverter.GetBytes(axisData.Res), 0, result, index, 2);
  409. index += 2;
  410. byte hallInput = 0x00;
  411. result[index] = hallInput;
  412. index ++;
  413. byte reserved = 0x00;
  414. result[index] = reserved;
  415. index ++;
  416. byte[] userVariables = new byte[4];
  417. Array.Copy(userVariables, 0, result, index, 4);
  418. return result;
  419. }
  420. #endregion
  421. /// <summary>
  422. /// 解析指令(操作符, 运动轴, 操作数)
  423. /// </summary>
  424. /// <param name="cmd"></param>
  425. /// <returns></returns>
  426. private (string, char, int) AnalyseCommand(string cmdStr)
  427. {
  428. var result = ("", ' ', -1);
  429. //操作符
  430. result.Item1 = cmdStr.Substring(0, 2);
  431. //运动轴
  432. if (cmdStr.Length >= 4)
  433. {
  434. result.Item2 = Convert.ToChar(cmdStr.Substring(2, 1));
  435. }
  436. //操作数
  437. if (cmdStr.Length >= 5 && int.TryParse(cmdStr.Substring(4, cmdStr.Length - 5), out int tmp))
  438. {
  439. result.Item3 = tmp;
  440. }
  441. return result;
  442. }
  443. /// <summary>
  444. /// CMD校验
  445. /// </summary>
  446. /// <returns></returns>
  447. private bool CheckCmdValid(string cmdStr)
  448. {
  449. //长度
  450. if(cmdStr.Length < 3) return false;
  451. //;结尾
  452. if (!cmdStr.EndsWith(";")) return false;
  453. //第1位为A~Z
  454. if (cmdStr[0] < 'A' || cmdStr[0] > 'Z') return false;
  455. //第2位为A~Z
  456. if (cmdStr[1] < 'A' || cmdStr[1] > 'Z') return false;
  457. if (cmdStr.Length >= 4)
  458. {
  459. //axis名称为A~H
  460. if (cmdStr[2] < 'A' || cmdStr[2] > 'H') return false;
  461. //=
  462. if(cmdStr.Length > 4 && !cmdStr.Contains("=")) return false;
  463. }
  464. return true;
  465. }
  466. /// <summary>
  467. /// 设置操作
  468. /// </summary>
  469. /// <param name="cmd"></param>
  470. /// <param name="axis"></param>
  471. /// <param name="value"></param>
  472. /// <returns></returns>
  473. private bool SetOperation(string cmd, char axis, int value)
  474. {
  475. switch (cmd)
  476. {
  477. case "SH"://上电
  478. SwitchMotor(axis, true);
  479. break;
  480. case "MO"://下电
  481. SwitchMotor(axis, false);
  482. break;
  483. case "PR"://相对位置
  484. SetTargetRelativePosition(axis, value);
  485. break;
  486. case "PA"://绝对位置
  487. SetTargetAbsolutePosition(axis, value);
  488. break;
  489. case "SP"://速度
  490. SetSpeed(axis, value);
  491. break;
  492. case "AC"://加速度
  493. SetAcceleration(axis, value);
  494. break;
  495. case "DC"://减速度
  496. SetDeceleration(axis, value);
  497. break;
  498. case "ST"://停止
  499. ControlMotion(axis, false);
  500. break;
  501. case "BG"://启动
  502. ControlMotion(axis, true);
  503. break;
  504. case "HM"://回零
  505. Home(axis);
  506. break;
  507. case "DP"://设定motor position
  508. SetMotorPosition(axis, value);
  509. break;
  510. case "DE"://设定auxiliary position
  511. SetAuxiliaryPosition(axis, value);
  512. break;
  513. default:
  514. break;
  515. }
  516. return true;
  517. }
  518. /// <summary>
  519. /// 实时更新电机数据
  520. /// </summary>
  521. /// <param name="datasDic"></param>
  522. private void UpdataRealTimeMotionData(Dictionary<string, SimulatorMotionData> datasDic)
  523. {
  524. foreach(var dataItem in datasDic)
  525. {
  526. if (_axisNameIndexDic.ContainsKey(dataItem.Key))
  527. {
  528. UpdateAxisData(_axisNameIndexDic[dataItem.Key], dataItem.Value);
  529. }
  530. }
  531. }
  532. /// <summary>
  533. /// 更新对应Axis数据
  534. /// </summary>
  535. /// <param name="index"></param>
  536. private void UpdateAxisData(int index, SimulatorMotionData data)
  537. {
  538. _galilControlData.GalilAxisDatas[index].Velocity = data.ActualVelocity;
  539. _galilControlData.GalilAxisDatas[index].MotorPosition = (int)(data.ActualPosition / _motorPositionRateDic[_nameAxisList[index]]);
  540. _galilControlData.GalilAxisDatas[index].ReferencePosition = data.TargetPosition;
  541. _galilControlData.GalilAxisDatas[index].Torque = data.ActualTorque;
  542. _galilControlData.GalilAxisDatas[index].StopCode = data.StopCode;
  543. }
  544. #region AxisOperation
  545. /// <summary>
  546. /// 开/关电机
  547. /// </summary>
  548. /// <param name="axis"></param>
  549. /// <param name="flag"></param>
  550. private void SwitchMotor(char axis, bool flag)
  551. {
  552. byte[] data = byteTransform.GetBytes(_galilControlData.GalilAxisDatas[axis - 'A'].Status);
  553. data[0] &= 0xFE;
  554. data[0] |= (byte)(flag ? 0x00 : 0x01);
  555. _galilControlData.GalilAxisDatas[axis - 'A'].Status = byteTransform.TransUInt16(data, 0);
  556. MotorSimulator.Instance.SetMotionData(_nameAxisList[axis - 'A'], SWITCH_SIGNAL, flag);
  557. }
  558. /// <summary>
  559. /// 设置速度
  560. /// </summary>
  561. private void SetSpeed(char axis, int value)
  562. {
  563. MotorSimulator.Instance.SetMotionData(_nameAxisList[axis - 'A'], TARGET_VELOCITY, value);
  564. }
  565. /// <summary>
  566. /// 设置加速度
  567. /// </summary>
  568. private void SetAcceleration(char axis, int value)
  569. {
  570. MotorSimulator.Instance.SetMotionData(_nameAxisList[axis - 'A'], TARGET_ACCEL, value);
  571. }
  572. /// <summary>
  573. /// 设置减速度
  574. /// </summary>
  575. private void SetDeceleration(char axis, int value)
  576. {
  577. MotorSimulator.Instance.SetMotionData(_nameAxisList[axis - 'A'], TARGET_DECEL, value);
  578. }
  579. /// <summary>
  580. /// 设置目标绝对位置(设定位置)
  581. /// </summary>
  582. private void SetTargetAbsolutePosition(char axis, int value)
  583. {
  584. _galilControlData.GalilAxisDatas[axis - 'A'].ReferencePosition = value;
  585. MotorSimulator.Instance.SetMotionData(_nameAxisList[axis - 'A'], TARGET_POSITION, value);
  586. }
  587. /// <summary>
  588. /// 设置目标相对位置(设定位置)
  589. /// </summary>
  590. private void SetTargetRelativePosition(char axis, int value)
  591. {
  592. _galilControlData.GalilAxisDatas[axis - 'A'].ReferencePosition = _galilControlData.GalilAxisDatas[axis - 'A'].MotorPosition + value;
  593. MotorSimulator.Instance.SetMotionData(_nameAxisList[axis - 'A'], TARGET_POSITION, _galilControlData.GalilAxisDatas[axis - 'A'].ReferencePosition);
  594. }
  595. /// <summary>
  596. /// 设置 Motor Position(实际位置)
  597. /// </summary>
  598. /// <param name="axis"></param>
  599. /// <param name="value"></param>
  600. private void SetMotorPosition(char axis, int value)
  601. {
  602. MotorSimulator.Instance.SetMotionData(_nameAxisList[axis - 'A'], ACTUAL_POSITION, value);
  603. }
  604. /// <summary>
  605. /// 设置 Auxiliary Position
  606. /// </summary>
  607. /// <param name="axis"></param>
  608. /// <param name="value"></param>
  609. private void SetAuxiliaryPosition(char axis, int value)
  610. {
  611. MotorSimulator.Instance.SetMotionData(_nameAxisList[axis - 'A'], AUXILIARY_POSITION, value);
  612. }
  613. /// <summary>
  614. /// 控制运动
  615. /// </summary>
  616. private void ControlMotion(char axis, bool value)
  617. {
  618. MotorSimulator.Instance.SetMotionData(_nameAxisList[axis - 'A'], value ? MOTION_SIGNAL : STOP_SIGNAL, value);
  619. }
  620. /// <summary>
  621. /// 电机回零
  622. /// </summary>
  623. /// <param name="axis"></param>
  624. private void Home(char axis)
  625. {
  626. MotorSimulator.Instance.SetMotionData(_nameAxisList[axis - 'A'], HOMING_SIGNAL, true);
  627. }
  628. #endregion
  629. }
  630. }