-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPLCLogic.cs
842 lines (777 loc) · 31.6 KB
/
PLCLogic.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
using System;
using System.Collections.Generic;
using System.Threading;
namespace mujinplccs
{
public static class Extensions
{
public static TValue Get<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue)
{
TValue value;
return dictionary.TryGetValue(key, out value) ? value : defaultValue;
}
}
public sealed class PLCLogic
{
/// <summary>
/// MUJIN PLC ErrorCode
/// </summary>
public enum PLCErrorCode
{
ErrorCodeNotAvailable = 0x0000,
EStopError = 0x1000,
PLCError = 0x2000,
PLCSupplyInterlockError = 0x2001,
PLCDestInterlockError = 0x2002,
PLCOtherInterlockError = 0x2003,
PLCCommandError = 0x2010,
PlanningError = 0x3000,
DetectionError = 0x4000,
SensorError = 0x5000,
RobotError = 0x6000,
SystemError = 0x7000,
OtherCycleError = 0xf000,
InCycleError = 0xf001,
InvalidOrderNumberError = 0xf003,
NotRunningError = 0xf004,
FailedToMoveToError = 0xf009,
GenericError = 0xffff,
}
/// <summary>
/// PLCError is raised when an error code is set by MUJIN controller.
/// </summary>
public sealed class PLCError : Exception
{
private PLCErrorCode _errorcode = PLCErrorCode.ErrorCodeNotAvailable;
private string _detailedErrorCode;
public PLCError(PLCErrorCode errorcode, string detailedErrorCode="") : base(String.Format("Error 0x{0:X} has occurred: {1}", errorcode, detailedErrorCode))
{
this._errorcode = errorcode;
this._detailedErrorCode = detailedErrorCode;
}
/// <summary>
/// MUJIN PLC Error Code
/// </summary>
public PLCErrorCode errorcode
{
get { return this._errorcode; }
}
/// <summary>
/// When ErrorCode is RobotError, DetailedErrorCode contains the error code returned by robot controller.
/// </summary>
public string detailedErrorCode
{
get { return this._detailedErrorCode; }
}
}
/// <summary>
/// MUJIN PLC Preparation FinishCode
/// </summary>
public enum PLCPreparationFinishCode
{
PreparationNotAvailable = 0x0000,
PreparationFinishedSuccess = 0x0001,
PreparationFinishedImmediatelyStopped = 0x0102,
PreparationFinishedBadPartType = 0xfffd,
PreparationFinishedBadOrderCyclePrecondition = 0xfffe,
PreparationFinishedGenericError = 0xffff,
}
/// <summary>
/// MUJIN PLC OrderCycleFinishCode
/// </summary>
public enum PLCOrderCycleFinishCode
{
FinishedNotAvailable = 0x0000,
FinishedOrderComplete = 0x0001,
FinishedNoMoreTargets = 0x0002,
FinishedNoMoreTargetsNotEmpty = 0x0003,
FinishedNoMoreDest = 0x0004,
FinishedNoEnvironmentUpdate = 0x0005,
FinishedDropTargetFailure = 0x0006,
FinishedTooManyPickFailures = 0x0007,
FinishedRobotExecutionError = 0x0008,
FinishedNoDestObstacles = 0x0009,
FinishedStopped = 0x0101,
FinishedStoppedImmediately = 0x0102,
FinishedPlanningFailure = 0x1000,
FinishedNoValidGrasp = 0x1001,
FinishedNoValidDest = 0x1002,
FinishedNoValidGraspDestPair = 0x1003,
FinishedNoValidPath = 0x1004,
FinishedNoValidTargets = 0x1005,
FinishedNoValidBarcodeScan = 0x1006,
FinishedComputePlanFailure = 0x1007,
FinishedCannotGenerateGraspingModel = 0x1008,
FinishedContainerNotDetected = 0x2001,
FinishedPlaceContainerNotDetected = 0x2002,
FinishedBadExpectedDetectionHeight = 0x2003,
FinishedCannotComputeFinishPlan = 0xfff7,
FinishedUnknownReasonNoError = 0xfff8,
FinishedCannotGetState = 0xfff9,
FinishedCycleStopCanceled = 0xfffa,
FinishedDropOffIsOn = 0xfffb,
FinishedBadPartType = 0xfffd,
FinishedBadOrderCyclePrecondition = 0xfffe,
FinishedGenericFailure = 0xffff,
}
/// <summary>
/// Mujin Pack Composition Finish Codes
/// </summary>
public enum PackCompositionFinishCodes
{
FinishedPackingUnknown = 0x0000,
FinishedPackingSuccess = 0x0001,
FinishedPackingInvalid = 0x0002,
FinishedPackingStopped = 0x0102,
FinishedCannotGetState = 0xfff9,
FinishedBadOrderCyclePrecondition = 0xfffe,
FinishedPackingError = 0xffff,
}
/// <summary>
/// MUJIN order cycle status information.
/// </summary>
public sealed class PLCOrderCycleStatus
{
/// <summary>
/// Whether the order cycle is currently running.
/// </summary>
public bool isRunningOrderCycle { get; set; }
/// <summary>
/// Whether the robot is currently moving.
/// </summary>
public bool isRobotMoving { get; set; }
/// <summary>
/// Whether detection is currently running.
/// </summary>
public bool location1DetectionRunning { get; set; }
/// <summary>
/// Number of items left in order to be picked.
/// </summary>
public int numLeftInOrder { get; set; }
/// <summary>
/// Number of items placed.
/// </summary>
public int numPutInDestination { get; set; }
/// <summary>
/// MUJIN PLC OrderCycleFinishCode.
/// </summary>
public PLCOrderCycleFinishCode orderCycleFinishCode { get; set; }
/// <summary>
/// Whether container at location can be safely moved at the moment.
/// </summary>
public bool location1Released { get; set; }
/// <summary>
/// Whether container at location can be safely moved at the moment.
/// </summary>
public bool location2Released { get; set; }
/// <summary>
/// Whether container at location can be safely moved at the moment.
/// </summary>
public bool location3Released { get; set; }
/// <summary>
/// Whether container at location can be safely moved at the moment.
/// </summary>
public bool location4Released { get; set; }
/// <summary>
/// Whether container at location is currently empty.
/// </summary>
public bool location1NotEmpty { get; set; }
/// <summary>
/// Whether container at location is currently empty.
/// </summary>
public bool location2NotEmpty { get; set; }
/// <summary>
/// Whether container at location is currently empty.
/// </summary>
public bool location3NotEmpty { get; set; }
/// <summary>
/// Whether container at location is currently empty.
/// </summary>
public bool location4NotEmpty { get; set; }
/// <summary>
/// Number of detected work parts detected and left in location.
/// </summary>
public int numLeftInLocation1 { get; set; }
/// <summary>
/// Number of detected work parts detected and left in location.
/// </summary>
public int numLeftInLocation2 { get; set; }
/// <summary>
/// Number of detected work parts detected and left in location.
/// </summary>
public int numLeftInLocation3 { get; set; }
/// <summary>
/// Number of detected work parts detected and left in location.
/// </summary>
public int numLeftInLocation4 { get; set; }
}
/// <summary>
/// Mujin Preparation Cycle status
/// </summary>
public sealed class PLCPreparationCycleStatus
{
/// <summary>
/// Whether the preparation cycle is currently running
/// </summary>
public bool isRunningPreparation { get; set; }
}
private PLCController controller = null;
/// <summary>
/// MUJIN specific PLC logic implementation.
/// </summary>
/// <param name="controller">An instance of PLCController.</param>
public PLCLogic(PLCController controller)
{
this.controller = controller;
}
/// <summary>
/// Clear all signals to the MUJIN controller. Set them all to false.
/// </summary>
public void ClearAllSignals()
{
this.controller.Set(new Dictionary<string, object>() {
{ "startOrderCycle", false },
{ "stopOrderCycle", false },
{ "stopImmediately", false },
{ "startPreparation", false },
{ "stopPreparation", false },
{ "startMoveToHome", false },
{ "startDetection", false },
{ "stopDetection", false },
{ "stopGripper", false },
{ "resetError", false },
});
}
/// <summary>
/// Block until connection from MUJIN controller is detected.
/// </summary>
/// <param name="timeout"></param>
public void WaitUntilConnected(TimeSpan? timeout = null)
{
this.controller.WaitUntilConnected(timeout);
}
/// <summary>
/// Check if there is an error set by MUJIN controller in the current state. If so, raise a PLCError exception.
/// </summary>
public void CheckError()
{
if (this.controller.Get<bool>("isError", false))
{
var errorcode = (PLCErrorCode)this.controller.Get<int>("errorcode", 0);
var detailedErrorCode = this.controller.Get<string>("detailedErrorCode", "");
throw new PLCError(errorcode, detailedErrorCode);
}
}
public bool IsError()
{
return this.controller.SyncAndGet<bool>("isError", false);
}
/// <summary>
/// Reset error on MUJIN controller. Block until error is reset.
/// </summary>
/// <param name="timeout"></param>
public void ResetError(TimeSpan? timeout = null)
{
this.controller.Set("resetError", true);
try
{
this.controller.WaitUntil("isError", false, timeout);
}
finally
{
this.controller.Set("resetError", false);
}
}
public bool IsSystemReady()
{
return this.controller.SyncAndGet<bool>("isSystemReady", false);
}
public bool IsModeAuto()
{
return this.controller.SyncAndGet<bool>("isModeAuto", false);
}
public void WaitUntilAutoMode(TimeSpan? timeout = null)
{
this.controller.WaitUntil(new Dictionary<string, object>()
{
{ "isModeAuto", true },
{ "isSystemReady", true },
}, new Dictionary<string, object>()
{
{ "isError", true },
}, timeout);
this.CheckError();
}
/// <summary>
/// Block until MUJIN controller is ready to start order cycle.
/// </summary>
/// <param name="timeout"></param>
public void WaitUntilOrderCycleReady(TimeSpan? timeout = null)
{
this.controller.WaitUntil(new Dictionary<string, object>()
{
{ "isRunningOrderCycle", false },
{ "isRobotMoving", false },
{ "isModeAuto", true },
{ "isSystemReady", true },
{ "isCycleReady", true },
}, new Dictionary<string, object>()
{
{ "isError", true },
}, timeout);
this.CheckError();
}
/// <summary>
/// Start order cycle. Block until MUJIN controller acknowledge the start command.
/// </summary>
/// <param name="orderPartType"></param>
/// <param name="orderNumber"></param>
/// <param name="orderPickLocationIndex"></param>
/// <param name="orderPickContainerId"></param>
/// <param name="orderPlaceLocationIndex"></param>
/// <param name="orderPlaceContainerId"></param>
/// <param name="timeout"></param>
/// <returns></returns>
// public PLCOrderCycleStatus StartOrderCycle(string orderPartType, int orderNumber, int orderPickLocation, string orderPickContainerId, int orderPlaceLocation, string orderPlaceContainerId, TimeSpan? timeout = null)
public PLCOrderCycleStatus StartOrderCycle(string orderPartType, int orderNumber, int orderPickLocationIndex, string orderPickContainerId, int orderPlaceLocationIndex, string orderPlaceContainerId, TimeSpan? timeout = null)
{
this.controller.Set(new Dictionary<string, object>() {
{ "orderPartType", orderPartType },
{ "orderNumber", orderNumber },
{ "orderPickLocation", orderPickLocationIndex },
{ "orderPlaceLocation", orderPlaceLocationIndex },
{ "orderPickContainerId", orderPickContainerId },
{ "orderPlaceContainerId", orderPlaceContainerId },
{ "startOrderCycle", true }
});
try
{
this.controller.WaitUntil(new Dictionary<string, object>() {
{ "isRunningOrderCycle", true },
}, new Dictionary<string, object>() {
{ "isError", true },
}, timeout);
}
finally
{
this.controller.Set(new Dictionary<string, object>() {
{ "startOrderCycle", false },
});
}
this.CheckError();
return this.GetOrderCycleStatus();
}
/// <summary>
/// Gather order cycle status information in the current state.
/// </summary>
/// <param name="timeout"></param>
/// <returns></returns>
public PLCOrderCycleStatus GetOrderCycleStatus(TimeSpan? timeout = null)
{
var values = this.controller.SyncAndGet(new string[]
{
"isRunningOrderCycle",
"isRobotMoving",
"location1DetectionRunning",
"numLeftInOrder",
"numPutInDestination",
"orderCycleFinishCode",
"location1Released",
"location2Released",
"location3Released",
"location4Released",
"location1NotEmpty",
"location2NotEmpty",
"location3NotEmpty",
"location4NotEmpty",
"numLeftInLocation1",
"numLeftInLocation2",
"numLeftInLocation3",
"numLeftInLocation4",
});
return new PLCOrderCycleStatus
{
isRunningOrderCycle = Convert.ToBoolean(values.Get("isRunningOrderCycle", false)),
isRobotMoving = Convert.ToBoolean(values.Get("isRobotMoving", false)),
location1DetectionRunning = Convert.ToBoolean(values.Get("location1DetectionRunning", false)),
numLeftInOrder = Convert.ToInt32(values.Get("numLeftInOrder", 0)),
numPutInDestination = Convert.ToInt32(values.Get("numPutInDestination", 0)),
orderCycleFinishCode = (PLCOrderCycleFinishCode)Convert.ToInt32(values.Get("orderCycleFinishCode", 0)),
location1Released = Convert.ToBoolean(values.Get("location1Released", false)),
location2Released = Convert.ToBoolean(values.Get("location2Released", false)),
location3Released = Convert.ToBoolean(values.Get("location3Released", false)),
location4Released = Convert.ToBoolean(values.Get("location4Released", false)),
location1NotEmpty = Convert.ToBoolean(values.Get("location1NotEmpty", false)),
location2NotEmpty = Convert.ToBoolean(values.Get("location2NotEmpty", false)),
location3NotEmpty = Convert.ToBoolean(values.Get("location3NotEmpty", false)),
location4NotEmpty = Convert.ToBoolean(values.Get("location4NotEmpty", false)),
numLeftInLocation1 = Convert.ToInt32(values.Get("numLeftInLocation1", 0)),
numLeftInLocation2 = Convert.ToInt32(values.Get("numLeftInLocation2", 0)),
numLeftInLocation3 = Convert.ToInt32(values.Get("numLeftInLocation3", 0)),
numLeftInLocation4 = Convert.ToInt32(values.Get("numLeftInLocation4", 0)),
};
}
/// <summary>
/// Block until values in order cycle status changes.
/// </summary>
/// <param name="timeout"></param>
/// <returns>Order cycle status information in the current state.</returns>
public PLCOrderCycleStatus WaitForOrderCycleStatusChange(TimeSpan? timeout = null)
{
if (this.controller.Get<bool>("isRunningOrderCycle", false))
{
this.controller.WaitFor(new Dictionary<string, object>()
{
{ "isError", true },
// listen to any changes in the following addresses
{ "isRunningOrderCycle", null },
{ "isRobotMoving", null },
{ "location1DetectionRunning", null },
{ "numLeftInOrder", null },
{ "orderCycleFinishCode", null },
{ "location1Released", null },
{ "location2Released", null },
{ "location3Released", null },
{ "location4Released", null },
{ "location1NotEmpty", null },
{ "location2NotEmpty", null },
{ "location3NotEmpty", null },
{ "location4NotEmpty", null },
{ "numLeftInLocation1", null },
{ "numLeftInLocation2", null },
{ "numLeftInLocation3", null },
{ "numLeftInLocation4", null },
}, timeout);
}
this.CheckError();
return this.GetOrderCycleStatus();
}
/// <summary>
/// Block until MUJIN controller finishes the order cycle.
/// </summary>
/// <param name="timeout"></param>
/// <returns>Order cycle status information in the finish state.</returns>
public PLCOrderCycleStatus WaitUntilOrderCycleFinish(TimeSpan? timeout = null)
{
this.controller.WaitUntil(new Dictionary<string, object>() {
{ "isRunningOrderCycle", false },
}, new Dictionary<string, object>() {
{ "isError", true },
}, timeout);
this.CheckError();
return this.GetOrderCycleStatus();
}
/// <summary>
/// Signal MUJIN controller to stop order cycle and block until it is stopped.
/// </summary>
/// <param name="timeout"></param>
/// <returns>Order cycle status information in the current state.</returns>
public PLCOrderCycleStatus StopOrderCycle(TimeSpan? timeout = null)
{
this.controller.Set(new Dictionary<string, object>() {
{ "stopOrderCycle", true },
});
try
{
this.controller.WaitUntil(new Dictionary<string, object>() {
{ "isRunningOrderCycle", false },
}, new Dictionary<string, object>() {
{ "isError", true },
}, timeout);
}
finally
{
this.controller.Set(new Dictionary<string, object>() {
{ "stopOrderCycle", false },
});
}
this.CheckError();
return this.GetOrderCycleStatus();
}
/// <summary>
/// Stop the current operation on MUJIN controller immediately.
/// </summary>
/// <param name="timeout"></param>
public void StopImmediately(TimeSpan? timeout = null)
{
this.controller.Set(new Dictionary<string, object>() {
{ "stopImmediately", true },
});
try
{
this.controller.WaitUntil(new Dictionary<string, object>() {
{ "isRunningOrderCycle", false },
{ "isRobotMoving", false },
}, new Dictionary<string, object>() {
{ "isError", true },
}, timeout);
}
finally
{
this.controller.Set(new Dictionary<string, object>() {
{ "stopImmediately", false },
});
}
this.CheckError();
}
/// <summary>
/// Block until MUJIN controller is ready to start preparation cycle.
/// </summary>
/// <param name="timeout"></param>
public void WaitUntilPreparationCycleReady(TimeSpan? timeout = null)
{
this.controller.WaitUntil(new Dictionary<string, object>()
{
{ "isRunningPreparation", false },
{ "isModeAuto", true },
{ "isSystemReady", true },
{ "isCycleReady", true },
}, new Dictionary<string, object>()
{
{ "isError", true },
}, timeout);
this.CheckError();
}
/// <summary>
/// Signal to start the preparation cycle on MUJIN controller.
/// </summary>
/// <param name="preparationPartType"></param>
/// <param name="preparationOrderNumber"></param>
/// <param name="preparationPickLocationIndex"></param>
/// <param name="preparationPickContainerId"></param>
/// <param name="preparationPlaceLocationIndex"></param>
/// <param name="preparationPlaceContainerId"></param>
/// <param name="timeout"></param>
public PLCPreparationCycleStatus StartPreparationCycle(string preparationPartType, int preparationOrderNumber, int preparationPickLocationIndex, string preparationPickContainerId, int preparationPlaceLocationIndex, string preparationPlaceContainerId, TimeSpan? timeout = null)
{
this.controller.Set(new Dictionary<string, object>() {
{ "preparationPartType", preparationPartType },
{ "preparationOrderNumber", preparationOrderNumber },
{ "preparationPickLocation", preparationPickLocationIndex },
{ "preparationPlaceLocation", preparationPlaceLocationIndex },
{ "preparationPickContainerId", preparationPickContainerId },
{ "preparationPlaceContainerId", preparationPlaceContainerId },
{ "startPreparation", true },
});
try
{
this.controller.WaitUntil(new Dictionary<string, object>(){
{ "isRunningPreparation", true },
}, new Dictionary<string, object>(){
{ "isError", true },
}, timeout);
}
finally
{
this.controller.Set(new Dictionary<string, object>(){
{ "startPreparation", false },
});
}
this.CheckError();
return this.GetPreparationCycleStatus();
}
/// <summary>
/// Gather preparation cycle status information in the current state
/// </summary>
public PLCPreparationCycleStatus GetPreparationCycleStatus(TimeSpan? timeout = null)
{
var values = this.controller.SyncAndGet(new string[]
{
"isRunningPreparation",
});
return new PLCPreparationCycleStatus
{
isRunningPreparation = Convert.ToBoolean(values.Get("isRunningPreparation", false))
};
}
/// <summary>
/// Block until MUJIN controller finishes the preparation cycle
/// </summary>
public PLCPreparationCycleStatus WaitUntilPreparationCycleFinish(TimeSpan? timeout = null)
{
this.controller.WaitUntil(new Dictionary<string, object>() {
{ "isRunningPreparation", false },
}, new Dictionary<string, object>() {
{ "isError", true },
}, timeout);
this.CheckError();
return this.GetPreparationCycleStatus();
}
/// <summary>
/// Signal to stop the preparation cycle on MUJIN controller.
/// </summary>
/// <param name="timeout"></param>
public PLCPreparationCycleStatus StopPreparationCycle(TimeSpan? timeout = null)
{
this.controller.Set(new Dictionary<string, object>() {
{ "stopPreparation", true },
});
try
{
this.controller.WaitUntil(new Dictionary<string, object>() {
{ "isRunningPreparation", false },
}, new Dictionary<string, object>() {
{ "isError", true },
}, timeout);
}
finally
{
this.controller.Set(new Dictionary<string, object>() {
{ "stopPreparation", false },
});
}
this.CheckError();
return this.GetPreparationCycleStatus();
}
/// <summary>
/// Block until MUJIN controller is ready to move robot to home position.
/// </summary>
/// <param name="timeout"></param>
public void WaitUntilMoveToHomeReady(TimeSpan? timeout = null)
{
this.controller.WaitUntil(new Dictionary<string, object>()
{
{ "isRunningOrderCycle", false },
{ "isRobotMoving", false },
{ "isModeAuto", true },
{ "isSystemReady", true },
{ "isCycleReady", true },
}, new Dictionary<string, object>()
{
{ "isError", true },
}, timeout);
this.CheckError();
}
public bool IsAtHome()
{
return this.controller.SyncAndGet<bool>("isAtHome", false);
}
/// <summary>
/// Signal MUJIN controller to move the robot to its home position. Block until the robot starts moving.
/// </summary>
/// <param name="timeout"></param>
public void StartMoveToHome(TimeSpan? timeout = null)
{
this.controller.Set(new Dictionary<string, object>() {
{ "startMoveToHome", true },
});
try
{
this.controller.WaitUntil(new Dictionary<string, object>() {
{ "isRobotMoving", true },
}, new Dictionary<string, object>() {
{ "isError", true },
}, timeout);
}
finally
{
this.controller.Set(new Dictionary<string, object>() {
{ "startMoveToHome", false },
});
}
this.CheckError();
}
/// <summary>
/// Block until the robot moving state is expected.
/// </summary>
/// <param name="isRobotMoving">true if expecting robot to move, false if expecting robot to stop</param>
/// <param name="timeout"></param>
public void WaitUntilRobotMoving(bool isRobotMoving, TimeSpan? timeout = null)
{
this.controller.WaitUntil(new Dictionary<string, object>() {
{ "isRobotMoving", isRobotMoving },
}, new Dictionary<string, object>() {
{ "isError", true },
}, timeout);
this.CheckError();
}
/// <summary>
/// Signal MUJIN controller to start detection. Block until detection is running.
/// </summary>
/// <param name="timeout"></param>
public void StartDetection(TimeSpan? timeout = null)
{
this.controller.Set(new Dictionary<string, object>() {
{ "startDetection", true },
});
try
{
this.controller.WaitUntil(new Dictionary<string, object>() {
{ "location1DetectionRunning", true },
}, new Dictionary<string, object>() {
{ "isError", true },
}, timeout);
}
finally
{
this.controller.Set(new Dictionary<string, object>() {
{ "startDetection", false },
});
}
this.CheckError();
}
/// <summary>
/// Signal MUJIN controller to stop detection. Block until detection stopped running.
/// </summary>
/// <param name="timeout"></param>
public void StopDetection(TimeSpan? timeout = null)
{
this.controller.Set(new Dictionary<string, object>() {
{ "stopDetection", true },
});
try
{
this.controller.WaitUntil(new Dictionary<string, object>() {
{ "location1DetectionRunning", false },
}, new Dictionary<string, object>() {
{ "isError", true },
}, timeout);
}
finally {
this.controller.Set(new Dictionary<string, object>() {
{ "stopDetection", false },
});
}
this.CheckError();
}
public bool IsGrabbingTarget()
{
return this.controller.SyncAndGet<bool>("isGrabbingTarget", false);
}
/// <summary>
/// Signal MUJIN controller to power off gripper.
/// </summary>
/// <param name="timeout"></param>
public void StopGripper(TimeSpan? timeout = null)
{
this.controller.Set("stopGripper", true);
try
{
this.controller.WaitUntil("isGrabbingTarget", false, timeout);
}
finally
{
this.controller.Set("stopGripper", false);
}
this.CheckError();
}
public void ChuckGripper(TimeSpan? timeout = null)
{
this.controller.Set("chuckGripper", true);
// TODO: currently there is no signal to indicate chuck gripper command has been received.
Thread.Sleep(500);
this.controller.Set("chuckGripper", false);
this.controller.Sync();
this.CheckError();
}
public void UnchuckGripper(TimeSpan? timeout = null)
{
this.controller.Set("unchuckGripper", true);
// TODO: currently there is no signal to indicate unchuck gripper command has been received.
Thread.Sleep(500);
this.controller.Set("unchuckGripper", false);
this.controller.Sync();
this.CheckError();
}
}
}