ATMDualArmRobot.xaml.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. using MECF.Framework.Common.CommonData;
  2. using VirgoUI.Controls.Common;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Linq;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Animation;
  12. using OpenSEMI.ClientBase;
  13. using MECF.Framework.Common.Equipment;
  14. using Aitex.Core.UI.MVVM;
  15. namespace VirgoUI.Client.Models.Controls
  16. {
  17. /// <summary>
  18. /// ATMDualArmRobot.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class ATMDualArmRobot : UserControl, INotifyPropertyChanged
  21. {
  22. protected readonly int MoveTime = 300;
  23. private const int AnimationTimeout = 3000; // seconds
  24. public int TranslateX
  25. {
  26. get { return (int)GetValue(TranslateXProperty); }
  27. set { SetValue(TranslateXProperty, value); }
  28. }
  29. // Using a DependencyProperty as the backing store for RotateAngel. This enables animation, styling, binding, etc...
  30. public static readonly DependencyProperty TranslateXProperty =
  31. DependencyProperty.Register("TranslateX", typeof(int), typeof(ATMDualArmRobot), new PropertyMetadata(0));
  32. public ModuleName Station
  33. {
  34. get { return (ModuleName)GetValue(StationProperty); }
  35. set { SetValue(StationProperty, value); }
  36. }
  37. // Using a DependencyProperty as the backing store for Station. This enables animation, styling, binding, etc...
  38. public static readonly DependencyProperty StationProperty =
  39. DependencyProperty.Register("Station", typeof(ModuleName), typeof(ATMDualArmRobot), new PropertyMetadata(ModuleName.Robot));
  40. public ICommand Command
  41. {
  42. get { return (ICommand)GetValue(CommandProperty); }
  43. set { SetValue(CommandProperty, value); }
  44. }
  45. // Using a DependencyProperty as the backing store for Command. This enables animation, styling, binding, etc...
  46. public static readonly DependencyProperty CommandProperty =
  47. DependencyProperty.Register("Command", typeof(ICommand), typeof(ATMDualArmRobot), new PropertyMetadata(null));
  48. public RobotMoveInfo RobotMoveInfo
  49. {
  50. get { return (RobotMoveInfo)GetValue(RobotMoveInfoProperty); }
  51. set { SetValue(RobotMoveInfoProperty, value); }
  52. }
  53. public static readonly DependencyProperty RobotMoveInfoProperty =
  54. DependencyProperty.Register("RobotMoveInfo", typeof(RobotMoveInfo), typeof(ATMDualArmRobot), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  55. public VTMRobotPosition StationPosition
  56. {
  57. get { return (VTMRobotPosition)GetValue(StationPositionProperty); }
  58. set { SetValue(StationPositionProperty, value); }
  59. }
  60. // Using a DependencyProperty as the backing store for StationPosition. This enables animation, styling, binding, etc...
  61. public static readonly DependencyProperty StationPositionProperty =
  62. DependencyProperty.Register("StationPosition", typeof(VTMRobotPosition), typeof(ATMDualArmRobot), new PropertyMetadata(null, PropertyChangedCallback));
  63. public WaferInfo[] RobotWafers
  64. {
  65. get { return (WaferInfo[])GetValue(RobotWafersProperty); }
  66. set { SetValue(RobotWafersProperty, value); }
  67. }
  68. // Using a DependencyProperty as the backing store for RobotWafers. This enables animation, styling, binding, etc...
  69. public static readonly DependencyProperty RobotWafersProperty =
  70. DependencyProperty.Register("RobotWafers", typeof(WaferInfo[]), typeof(ATMDualArmRobot), new PropertyMetadata(null, PropertyChangedCallback));
  71. public WaferInfo Wafer1
  72. {
  73. get { return (WaferInfo)GetValue(Wafer1Property); }
  74. set { SetValue(Wafer1Property, value); }
  75. }
  76. // Using a DependencyProperty as the backing store for Wafer1. This enables animation, styling, binding, etc...
  77. public static readonly DependencyProperty Wafer1Property =
  78. DependencyProperty.Register("Wafer1", typeof(WaferInfo), typeof(ATMDualArmRobot), new PropertyMetadata(null));
  79. public WaferInfo Wafer2
  80. {
  81. get { return (WaferInfo)GetValue(Wafer2Property); }
  82. set { SetValue(Wafer2Property, value); }
  83. }
  84. // Using a DependencyProperty as the backing store for Wafer2. This enables animation, styling, binding, etc...
  85. public static readonly DependencyProperty Wafer2Property =
  86. DependencyProperty.Register("Wafer2", typeof(WaferInfo), typeof(ATMDualArmRobot), new PropertyMetadata(null));
  87. private string CurrentPosition;
  88. //private string CurrentArmA;
  89. //private string CurrentArmB;
  90. private RobotAction CurrentAction
  91. {
  92. get; set;
  93. }
  94. private List<MenuItem> menu;
  95. public List<MenuItem> Menu
  96. {
  97. get
  98. {
  99. return menu;
  100. }
  101. set
  102. {
  103. menu = value;
  104. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Menu"));
  105. }
  106. }
  107. public ICommand MoveCommand
  108. {
  109. get
  110. {
  111. return new DelegateCommand<object>(MoveTo);
  112. }
  113. }
  114. // private AnimationQueue queue;
  115. public event PropertyChangedEventHandler PropertyChanged;
  116. static void PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  117. {
  118. var self = (ATMDualArmRobot)d;
  119. switch (e.Property.Name)
  120. {
  121. case "StationPosition":
  122. if (e.NewValue != null)
  123. {
  124. var positions = ((VTMRobotPosition)e.NewValue).Rotations;
  125. var menus = new List<MenuItem>();
  126. foreach (var position in positions)
  127. {
  128. var m = new MenuItem() { Header = position.Key };
  129. Enum.TryParse(position.Key.Split('.')[0], out RobotArm arm);
  130. m.Items.Add(new MenuItem() { Header = "Pick", Command = self.MoveCommand, CommandParameter = new RobotMoveInfo() { BladeTarget = position.Key, Action = RobotAction.Picking, ArmTarget = arm } });
  131. m.Items.Add(new MenuItem() { Header = "Place", Command = self.MoveCommand, CommandParameter = new RobotMoveInfo() { BladeTarget = position.Key, Action = RobotAction.Placing, ArmTarget = arm } });
  132. m.Items.Add(new MenuItem() { Header = "Move", Command = self.MoveCommand, CommandParameter = new RobotMoveInfo() { BladeTarget = position.Key, Action = RobotAction.Moving, ArmTarget = arm } });
  133. menus.Add(m);
  134. }
  135. self.Menu = menus;
  136. self.MoveTo(new RobotMoveInfo() { BladeTarget = positions.First().Key, Action = RobotAction.None });
  137. }
  138. break;
  139. case "RobotWafers":
  140. //if (e.NewValue == null)
  141. //{
  142. // self.Wafer1 = null;
  143. // self.Wafer2 = null;
  144. //}
  145. //else
  146. //{
  147. // if (self.RobotWafers.Length > 1)
  148. // {
  149. // self.Wafer1 = self.RobotWafers[0];
  150. // self.Wafer2 = self.RobotWafers[1];
  151. // }
  152. //}
  153. break;
  154. default:
  155. break;
  156. }
  157. }
  158. Dictionary<string, int> CanvasRotates = new Dictionary<string, int>
  159. {
  160. {"System",90},{"EfemRobot",90 },{"LP",90 }
  161. ,{"PM",270},
  162. {"Aligner",0 },
  163. };
  164. public ATMDualArmRobot()
  165. {
  166. #if DEBUG
  167. System.Diagnostics.PresentationTraceSources.DataBindingSource.Switch.Level = System.Diagnostics.SourceLevels.Critical;
  168. #endif
  169. InitializeComponent();
  170. root.DataContext = this;
  171. canvasRoot.Rotate(90);
  172. canvas1.Rotate(200);
  173. canvas2.Rotate(260);
  174. canvas3.Rotate(-100);
  175. canvas21.Rotate(140);
  176. canvas22.Rotate(100);
  177. canvas23.Rotate(120);
  178. StationPosition = new VTMRobotPosition()
  179. {
  180. Rotations = new Dictionary<string, int>()
  181. {
  182. { "Both.System", -0 },
  183. { "ArmA.System", -0 }
  184. , { "ArmA.LP", -0 }
  185. , { "ArmA.Aligner1", 0 }
  186. , { "ArmA.PM", -0 }
  187. , { "ArmB.System", -0 }
  188. , { "ArmB.LP", -0 }
  189. , { "ArmB.Aligner1", 0 }
  190. , { "ArmB.PM", -0 }
  191. },
  192. Home = new int[8] { 0, 180, 180, 0, 0, 180, 180, 0 },
  193. //Arm1Extend = new int[8] { 140, 180, -50, 40, 100, 260, 50, -180 },
  194. //Arm2Extend = new int[8] { 220, 100, -50, -50, 180, 180, 50, -85 },
  195. //Flipper
  196. Arm1Extend = new int[8] { 4, 180, 180, 0, 4, 360, 0, 0 },
  197. Arm2Extend = new int[8] { -4, 360, 0, 0, -4, 180, 180, 0, },
  198. //Buffer
  199. Arm3Extend = new int[8] { -30, 210, 180, 0, -30, 390, 0, 0 },
  200. Arm31Extend = new int[8] { -60, 60, 0, 0, 0, 180, 180, 0 },
  201. //Aligner
  202. //Arm4Extend = new int[8] { 0, 180, 180, 0, 90, 270, 0, 0, },
  203. Arm4Extend = new int[8] { 44, 136, 180, 0, 90, 270, 0, 0, },
  204. Arm41Extend = new int[8] { 36, 324, 0, 0, 37, 143, 180, 0, },
  205. //LP,PM
  206. Arm5Extend = new int[8] { 0, 180, 180, 0, 0, 360, 0, 0 },
  207. Arm6Extend = new int[8] { 0, 360, 0, 0, 0, 180, 180, 0, },
  208. // Cooling1
  209. Arm7Extend = new int[8] { -35, 35, 180, 0, -30, 30, 0, 0 },
  210. Arm71Extend = new int[8] { -50, 50, 0, 0, -40, 220, 180, 0 },
  211. // Cooling2
  212. Arm8Extend = new int[8] { 80, 100, 180, 0, 80, -80, 0, 0 },
  213. Arm81Extend = new int[8] { 44, 316, 0, 0, 44, 140, 180, 0 },
  214. };
  215. CurrentPosition = ModuleName.System.ToString();
  216. //CurrentArmA = CurrentArmB = RobotConstant.RobotRetract;
  217. }
  218. protected override void OnRender(DrawingContext drawingContext)
  219. {
  220. base.OnRender(drawingContext);
  221. if (DesignerProperties.GetIsInDesignMode(this))
  222. {
  223. return;
  224. }
  225. if (RobotMoveInfo != null)
  226. {
  227. var needMove = CurrentPosition != RobotMoveInfo.BladeTarget || CurrentAction != RobotMoveInfo.Action;
  228. if (needMove)
  229. {
  230. //LogMsg($" RobotMoveInfo, action:{RobotMoveInfo.Action} armTarget:{RobotMoveInfo.ArmTarget} bladeTarget:{RobotMoveInfo.BladeTarget}");
  231. Invoke(() => MoveRobot(RobotMoveInfo));
  232. CurrentAction = RobotMoveInfo.Action;
  233. CurrentPosition = RobotMoveInfo.BladeTarget;
  234. }
  235. }
  236. }
  237. private void UpdateWafer(RobotMoveInfo moveInfo)
  238. {
  239. /*
  240. bool waferPresent = false;
  241. switch (moveInfo.Action)
  242. {
  243. case RobotAction.None:
  244. case RobotAction.Moving:
  245. return;
  246. case RobotAction.Picking:
  247. waferPresent = true;
  248. break;
  249. case RobotAction.Placing:
  250. waferPresent = false;
  251. break;
  252. default:
  253. break;
  254. }*/
  255. switch (moveInfo.ArmTarget)
  256. {
  257. case RobotArm.ArmA:
  258. // WaferPresentA = waferPresent;
  259. break;
  260. case RobotArm.ArmB:
  261. // WaferPresentB = waferPresent;
  262. break;
  263. case RobotArm.Both:
  264. // WaferPresentA = waferPresent;
  265. // WaferPresentB = waferPresent;
  266. break;
  267. default:
  268. break;
  269. }
  270. }
  271. private void Action(int[] angles, Action onComplete = null)
  272. {
  273. var storyboard = new Storyboard();
  274. storyboard.Completed += (s, e) => onComplete?.Invoke();
  275. var needRotate = new List<bool>
  276. {
  277. canvas1.Rotate(storyboard, angles[0], true, MoveTime),
  278. canvas2.Rotate(storyboard,angles[1], true, MoveTime),
  279. canvas3.Rotate(storyboard, angles[2], true, MoveTime),
  280. canvas21.Rotate(storyboard, angles[4], true, MoveTime),
  281. canvas22.Rotate(storyboard, angles[5], true, MoveTime),
  282. canvas23.Rotate(storyboard, angles[6], true, MoveTime),
  283. };
  284. if (needRotate.Any(x => x))
  285. {
  286. storyboard.Begin();
  287. }
  288. else
  289. {
  290. onComplete?.Invoke();
  291. }
  292. }
  293. private void Translate(string station, Action onComplete = null)
  294. {
  295. if (station == null)
  296. return;
  297. if (CanvasRotates.Keys.Any(s => s.Contains(station.Split('.')[1])))
  298. {
  299. canvasRoot.Rotate(CanvasRotates[station.Split('.')[1]]);
  300. }
  301. var translateX = StationPosition.Rotations[station];
  302. TranslateX = translateX;
  303. TranslateTo(onComplete);
  304. }
  305. private void TranslateTo(Action onComplete)
  306. {
  307. if (translate.X != TranslateX)
  308. {
  309. var animation = new DoubleAnimation(translate.X, TranslateX, new Duration(TimeSpan.FromMilliseconds(MoveTime)));
  310. animation.Completed += (s, e) => onComplete?.Invoke();
  311. translate.BeginAnimation(TranslateTransform.XProperty, animation);
  312. }
  313. else
  314. {
  315. onComplete?.Invoke();
  316. }
  317. }
  318. private void MoveRobot(RobotMoveInfo moveInfo)
  319. {
  320. var updateWafer = new Action(() => UpdateWafer(moveInfo));
  321. canvas1.Stop();
  322. canvas2.Stop();
  323. canvas3.Stop();
  324. canvas2.Stop();
  325. canvas21.Stop();
  326. canvas22.Stop();
  327. canvas23.Stop();
  328. var target = moveInfo.BladeTarget;
  329. var arm = moveInfo.ArmTarget;
  330. Action(StationPosition.Home, () => Translate(moveInfo.BladeTarget, () =>
  331. {
  332. var moved = false;
  333. string modulename = moveInfo.BladeTarget.Split('.')[1];
  334. if (moveInfo.ArmTarget == RobotArm.ArmA)
  335. {
  336. switch (moveInfo.Action)
  337. {
  338. case RobotAction.None:
  339. break;
  340. case RobotAction.Picking:
  341. case RobotAction.Placing:
  342. if (modulename == "Flipper")
  343. {
  344. Action(StationPosition.Arm1Extend, updateWafer);
  345. }
  346. else if (modulename == "Buffer" || modulename == "Aligner2")
  347. {
  348. Action(StationPosition.Arm3Extend, updateWafer);
  349. }
  350. else if ( modulename == "Aligner1")
  351. {
  352. Action(StationPosition.Arm4Extend, updateWafer);
  353. }
  354. else if(modulename == "Cooling1")
  355. {
  356. Action(StationPosition.Arm7Extend, updateWafer);
  357. }
  358. else if(modulename == "Cooling2")
  359. {
  360. Action(StationPosition.Arm8Extend, updateWafer);
  361. }
  362. else
  363. {
  364. Action(StationPosition.Arm5Extend, updateWafer);
  365. }
  366. moved = true;
  367. break;
  368. case RobotAction.Moving:
  369. break;
  370. default:
  371. break;
  372. }
  373. }
  374. else if (moveInfo.ArmTarget == RobotArm.ArmB)
  375. {
  376. switch (moveInfo.Action)
  377. {
  378. case RobotAction.None:
  379. break;
  380. case RobotAction.Picking:
  381. case RobotAction.Placing:
  382. if (modulename == "Flipper")
  383. {
  384. Action(StationPosition.Arm2Extend, updateWafer);
  385. }
  386. else if (modulename == "Buffer" || modulename == "Aligner2")
  387. {
  388. Action(StationPosition.Arm31Extend, updateWafer);
  389. }
  390. else if (modulename == "Aligner1" )
  391. {
  392. Action(StationPosition.Arm41Extend, updateWafer);
  393. }
  394. else if (modulename == "Cooling1")
  395. {
  396. Action(StationPosition.Arm71Extend, updateWafer);
  397. }
  398. else if (modulename == "Cooling2")
  399. {
  400. Action(StationPosition.Arm81Extend, updateWafer);
  401. }
  402. else
  403. {
  404. Action(StationPosition.Arm6Extend, updateWafer);
  405. }
  406. moved = true;
  407. break;
  408. case RobotAction.Moving:
  409. break;
  410. default:
  411. break;
  412. }
  413. }
  414. if (!moved && updateWafer != null)
  415. {
  416. updateWafer();
  417. }
  418. }));
  419. }
  420. private void MoveTo(object obj)
  421. {
  422. MoveRobot((RobotMoveInfo)obj);
  423. }
  424. private void Invoke(Action action)
  425. {
  426. Dispatcher.Invoke(action);
  427. }
  428. private void LogMsg(string msg)
  429. {
  430. var source = "ATMRobot";
  431. Console.WriteLine("{0} {1}", source, msg);
  432. }
  433. }
  434. //public class RobotPosition
  435. //{
  436. // public int? X;
  437. // public int Root;
  438. // public int Arm;
  439. // public int Hand;
  440. //}
  441. //public class StationPosition
  442. //{
  443. // public RobotPosition StartPosition;
  444. // public RobotPosition EndPosition;
  445. //}
  446. public class VTMRobotPosition
  447. {
  448. public Dictionary<string, int> Rotations;
  449. public int[] Arm1Extend;
  450. public int[] Arm2Extend;
  451. public int[] Home;
  452. public int[] Arm3Extend;
  453. public int[] Arm4Extend;
  454. public int[] Arm5Extend;
  455. public int[] Arm6Extend;
  456. internal int[] Arm31Extend;
  457. internal int[] Arm41Extend;
  458. public int[] Arm7Extend;
  459. public int[] Arm71Extend;
  460. public int[] Arm8Extend;
  461. public int[] Arm81Extend;
  462. }
  463. public class RobotPosition
  464. {
  465. public int X;
  466. public int Z;
  467. public int Root;
  468. public int Arm;
  469. public int Hand;
  470. }
  471. public class StationPosition
  472. {
  473. public RobotPosition StartPosition;
  474. public RobotPosition EndPosition;
  475. }
  476. public class RobotConstant
  477. {
  478. public const string RobotRetract = "0";
  479. public const string RobotExtend = "1";
  480. public const string UnknownTarget = "Unknown";
  481. }
  482. }