forked from nstylo/dbl-embedded-systems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCountingRobot.dzn
1129 lines (1021 loc) · 35.9 KB
/
CountingRobot.dzn
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
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//interface Communication //used to be time, communication interface now. Because these will be functions of communication with mqtt
//{
// in void error();
// in void tick();
// in void errorProcedure();
// behaviour
// {
// enum State {heartbeat, error};
// State state = State.heartbeat;
// on error: state = State.error;
// [state.heartbeat]
// {
// on tick:{}
// on errorProcedure: illegal;
// }
/// [state.error]
/// {
// on errorProcedure:{state = State.heartbeat;}
// on tick: illegal;
// }
//
// }
//}
interface ITimer {
extern Long $long$;
in void start(Long milliseconds);
in void cancel();
out void timeout();
behaviour {
enum State { Idle, Running };
State state = State.Idle;
[state.Idle] {
on start: state = State.Running;
on cancel: illegal;
}
[state.Running] {
on start: {}
on cancel: state = State.Idle;
on inevitable: {
state = State.Idle;
timeout;
}
}
}
}
interface IRobotCommunication {
in void start();
in void stop();
in void emergencyStop();
out void emergency();
out void requestDiskCounters();
in void respondDiskCounters();
out void heartbeat();
in void heartbeat1();
in void heartbeat2();
in void heartbeat3();
in void heartbeat4();
out void tookDisk_out();
in void tookDisk_in();
in void controller_took_disk();
in void controller_error();
in void controller_error_solved();
in void controller_emergency();
out void error_out();
in void error_in();
out void requestDisksTaken();
in void respondDisksTaken();
behaviour {
enum State { Idle, Running, Error };
State state = State.Idle;
on respondDiskCounters,
respondDisksTaken,
controller_took_disk,
controller_error,
controller_error_solved,
controller_emergency,
error_in,
heartbeat1,
heartbeat2,
heartbeat3,
heartbeat4,
tookDisk_in: {}
[state.Idle] {
on start: state = State.Running;
on stop: {}
on emergencyStop: {}
//all below required against verification error
on controller_emergency:{emergency;}
on controller_took_disk:illegal;
on controller_error_solved: {requestDisksTaken; state= State.Running;}
on respondDisksTaken:illegal;
on error_in:illegal;
on controller_error:{illegal;}
on tookDisk_in:illegal;
on heartbeat1:illegal;
on heartbeat2:illegal;
on heartbeat3:illegal;
on heartbeat4:illegal;
on respondDiskCounters:illegal;
on controller_took_disk:illegal;
}
[state.Running] {
on stop: state = State.Idle;
on emergencyStop: state = State.Idle;
on controller_emergency: {
state = State.Error;
emergency;
}
on optional: {
requestDiskCounters;
}
on controller_error_solved: {
requestDisksTaken;
}
on controller_error: {
error_out;
state= State.Error;
}
on controller_took_disk: {
tookDisk_out;
}
on optional: {
heartbeat;
}
on start: illegal;
}
//ADDED THIS BECAUSE ITS NEEDED.
[state.Error]
{
on emergencyStop: {}
on respondDisksTaken:illegal;
on error_in:illegal;
on controller_error:{illegal;}
on optional: {
heartbeat;
}
on tookDisk_in:illegal;
on respondDiskCounters:illegal;
on controller_took_disk:illegal;
on start:illegal;
on stop: illegal;
on controller_emergency:{emergency;}
on controller_error_solved: {
requestDisksTaken;
state = State.Running;
}
}
}
}
component RobotCommunication
{
provides IRobotCommunication iCommunication;
requires ITimer iTimer;
//requires IController icontroller;
behaviour
{
enum State {idle, running, error};
State state = State.idle;
enum R1 {dead, running, error, unconnected, awaiting_h}; R1 r1 = R1.unconnected;
enum R2 {dead, running, error, unconnected, awaiting_h}; R2 r2 = R2.unconnected;
enum R3 {dead, running, error, unconnected, awaiting_h}; R3 r3 = R3.unconnected;
enum R4 {dead, running, error, unconnected, awaiting_h}; R4 r4 = R4.unconnected;
[state.idle]
{
on iCommunication.controller_took_disk(),
iCommunication.controller_error(),
iCommunication.controller_error_solved(),
iCommunication.controller_emergency(),
iCommunication.error_in(),
iCommunication.respondDiskCounters(),
iTimer.timeout(),
iCommunication.tookDisk_in(),
iCommunication.respondDisksTaken(),
iCommunication.emergencyStop(),
iCommunication.heartbeat1(),
iCommunication.heartbeat2(),
iCommunication.heartbeat3(),
iCommunication.heartbeat4(),
iCommunication.stop():{}
on iCommunication.start():
{
state = State.running;
iTimer.start($30$);
r1 = R1.unconnected; // initialized all robots as unconnected on startup
r2 = R2.unconnected;
r3 = R3.unconnected;
r4 = R4.unconnected;
}
}
[state.running]
{
on iCommunication.stop(): state = State.idle;
on iCommunication.emergencyStop(): state = State.idle;
on iTimer.timeout():
{
iCommunication.heartbeat(); //sends heartbeat every 30 seconds
if(r1 == R1.running){r1 = R1.awaiting_h;} else {r1 = R1.dead;} //checks if robots are still on
if(r2 == R2.running){r2 = R2.awaiting_h;} else {r2 = R2.dead;} // in on we will set to wait for next heartbeat
if(r3 == R3.running){r3 = R3.awaiting_h;} else {r3 = R3.dead;} // if robots have not updated, we will assume dead
if(r4 == R4.running){r4 = R4.awaiting_h;} else {r4 = R4.dead;}
iTimer.start($30$);
}
on iCommunication.heartbeat1(): r1 = R1.running; // updates state of robots when receiving heartbeat
on iCommunication.heartbeat2(): r2 = R2.running;
on iCommunication.heartbeat3(): r3 = R3.running;
on iCommunication.heartbeat4(): r4 = R4.running;
on iCommunication.tookDisk_in():{}
on iCommunication.controller_error(): { state = State.error; iCommunication.error_out();}
on iCommunication.controller_emergency(): {iCommunication.emergency(); state = State.error; }
on iCommunication.respondDisksTaken():{}
on iCommunication.error_in():{}
on iCommunication.respondDiskCounters():{}
on iCommunication.controller_error_solved():{}
on iCommunication.controller_took_disk(): {state = State.running; iCommunication.tookDisk_out();}
}
[state.error]
{
on iTimer.timeout():
{
iCommunication.heartbeat(); //sends heartbeat every 30 seconds
if(r1 == R1.running){r1 = R1.awaiting_h;} else {r1 = R1.dead;} //checks if robots are still on
if(r2 == R2.running){r2 = R2.awaiting_h;} else {r2 = R2.dead;} // in on we will set to wait for next heartbeat
if(r3 == R3.running){r3 = R3.awaiting_h;} else {r3 = R3.dead;} // if robots have not updated, we will assume dead
if(r4 == R4.running){r4 = R4.awaiting_h;} else {r4 = R4.dead;}
iTimer.start($30$);
}
on iCommunication.controller_error_solved(): {state = State.running; iCommunication.requestDisksTaken();}
on iCommunication.controller_emergency(): {state = State.error; iCommunication.emergency();}
on iCommunication.emergencyStop(): {}
on iCommunication.heartbeat1(): r1 = R1.running; // updates state of robots when receiving heartbeat
on iCommunication.heartbeat2(): r2 = R2.running;
on iCommunication.heartbeat3(): r3 = R3.running;
on iCommunication.heartbeat4(): r4 = R4.running;
}
}
}
interface IHead // gets required bit colours from controller, manages the tape part of the robot
{
in void start_building();
in void next_bit();
in void start_clearing();
out void tape_is_clear();
out void take_fromfloor();
out void tape_takefromfloor();
out void ready_to_update();
behaviour
{
enum State {building, waiting, clearing};
State state = State.waiting;
[state.waiting]
{
on start_building: {state = State.building;}
on start_clearing: {state = State.clearing;}
on next_bit: {}
}
[state.building]
{
on start_clearing: {state = State.clearing;}
on start_building: {illegal;}
on next_bit: {}
}
[state.clearing]
{
on start_building: {state = State.building;}
on next_bit: {}
on start_clearing: {state = State.clearing;}
}
}
}
interface IFloorPusher // pushed the current disk off the factory if it receives the push order
{
in void push();
out void completedPushProcedure();
behaviour
{
enum State {letPass, pushProcedure};
State state = State.letPass;
on push: {state = State.pushProcedure; completedPushProcedure;}
[state.pushProcedure]
{
on inevitable: state = State.letPass;
}
}
}
interface IFloorSensor // replacement for the floorsensor, outputs which colour disk it detects
{
in void black_comes();
in void white_comes();
out void black_sensed();
out void white_sensed();
behaviour
{
enum State {black_next, white_next, noDisk};
State state = State.noDisk;
on black_comes: {state = State.black_next; black_sensed;} //outputs diskcolour when found,
on white_comes: {state = State.white_next; white_sensed;}
[state.black_next]
{
on inevitable: state = State.noDisk; //after x time goes back to sensing
}
[state.white_next]
{
on inevitable: state = State.noDisk; //after x time goes back to sensing
}
}
}
interface IFloorPicker
{
in void pause();
in void resume();
in void take_from_floor();
out void taken_from_floor();
out void black_on_floor();
out void white_on_floor();
behaviour
{
enum State {busy, paused};
State state = State.busy;
on take_from_floor:{}
[state.busy]
{
on pause: state = State.paused;
on resume: illegal;
on take_from_floor :illegal;
}
[state.paused]
{
on pause: {}
on resume: state = State.busy;
on take_from_floor :illegal;
}
}
}
interface IController // interface of the controller, keeps track of what we're doing,
//can handle errors (eventually)
{
in void init();
in void update();
in void error();
in void continue();
out void pause();
out void resume();
out void increment();
//out void error_detected();
//out void error_solved();
out void took_disk();
out void emergency();
behaviour
{
enum State {error, building, off};
State state = State.off;
[state.off]
{
on init: state = State.building;
on error: {illegal;}
on continue: illegal;
on update: illegal;
}
[state.building]
{
on error: state = State.error;
on update:{state = State.building;}
on continue:{state = State.building;}
on init: {illegal;}//dezyne wanted this here
}
[state.error]
{
on inevitable: state = State.building;
on continue: illegal;
on error: state = State.error;
on update: illegal;
on init: illegal;
}
}
}
interface ITapeColorSensor //color Sensor on Tape
{
in void sense();
out void colorSensed();
behaviour
{
enum State {single_state};
State state = State.single_state;
on sense: {state = State.single_state; colorSensed;}
}
}
interface IDiskSensor //disk sensor on tape
{
in void diskSensed();
out void diskColor();
behaviour
{
enum State {noDisk, diskPresent};
State state = State.noDisk;
on diskSensed: {state = State.diskPresent; diskColor;}
[state.diskPresent]
{
on inevitable: state = State.noDisk;
}
}
}
interface ITapePusher
{
in void push();
in void backToWaiting();
out void pushComplete();
behaviour
{
enum State {waiting, pushing};
State state = State.waiting;
on push: {state = State.pushing; }
on backToWaiting: state = State.waiting;
[state.pushing]
{
on backToWaiting: {state = State.waiting; pushComplete;}
}
}
}
interface ILCD //LCD screen
{
in void getValue();
in void showValue();
behaviour
{
enum State {single_state};
State state = State.single_state;
on getValue: state = State.single_state;
on showValue: state = State.single_state;
}
}
interface ITape //our tape of the Turing machine with 3 slots
{
in void moveto1(); //goes to bit1
in void moveto2(); //goes to bit2
in void moveto3(); //goes to bit3
in void movetoclear1(); // starts clearing procedure
in void movetoclear2();
in void movetoclear3();
in void dontmove(); //stops tape
out void positionIn(); //The tape is in position to intake bit;
out void positionOut(); //The tape is in position to output bit;
behaviour
{
enum State {moving, stopping};
State state = State.stopping;
on moveto1: {positionIn; state = State.moving;}
on moveto2: {positionIn; state = State.moving;}
on moveto3: {positionIn; state = State.moving;}
on movetoclear1: {positionOut; state = State.moving;}
on movetoclear2: {positionOut; state = State.moving;}
on movetoclear3: {positionOut; state = State.moving;}
on dontmove: state = State.stopping;
[state.moving]
{
on inevitable: state = State.stopping;
}
}
}
component Tape //keeps track of the position of the tape
{
provides ITape iTape;
behaviour
{
enum position {bit1, bit2, bit3, bit1_clear, bit2_clear, bit3_clear, neutral};
position state = position.neutral;
[state.neutral]
{
on iTape.moveto1(): {iTape.positionIn(); state = position.bit1;}
on iTape.moveto2(): {iTape.positionIn(); state = position.bit2;}
on iTape.moveto3(): {iTape.positionIn(); state = position.bit3;}
on iTape.movetoclear1(): {iTape.positionOut(); state = position.bit1_clear;}
on iTape.movetoclear2(): { iTape.positionOut(); state = position.bit2_clear;}
on iTape.movetoclear3(): { iTape.positionOut(); state = position.bit3_clear;}
}
[state.bit1]
{
on iTape.moveto1(): {iTape.positionIn(); state = position.bit1;}//dezyne wanted
on iTape.moveto2(): {state = position.bit2; iTape.positionIn();}
on iTape.moveto3(): {state = position.bit3; iTape.positionIn();}
on iTape.movetoclear1(): {state = position.bit1_clear; iTape.positionOut();}
on iTape.movetoclear2(): {state = position.bit2_clear; iTape.positionOut();}
on iTape.movetoclear3(): {state = position.bit3_clear; iTape.positionOut();}
}
[state.bit2]
{
on iTape.moveto1(): {state = position.bit1; iTape.positionIn();}
on iTape.moveto2(): {iTape.positionIn();state = position.bit2;} //dezyne wanted
on iTape.moveto3(): {state = position.bit3; iTape.positionIn();}
on iTape.movetoclear1(): {state = position.bit1_clear;iTape.positionOut();}
on iTape.movetoclear2(): {state = position.bit2_clear; iTape.positionOut();}
on iTape.movetoclear3(): {state = position.bit3_clear; iTape.positionOut();}
}
[state.bit3]
{
on iTape.moveto1(): {state = position.bit1; iTape.positionIn();}
on iTape.moveto2(): {state = position.bit2; iTape.positionIn();}
on iTape.moveto3(): {iTape.positionIn();state = position.bit3;} //Dezyne wanted
on iTape.movetoclear1(): {state = position.bit1_clear; iTape.positionOut();}
on iTape.movetoclear2(): {state = position.bit2_clear; iTape.positionOut();}
on iTape.movetoclear3(): {state = position.bit3_clear; iTape.positionOut();}
}
[state.bit1_clear]
{
on iTape.movetoclear1(): {state = position.bit1_clear; iTape.positionOut();} //Dezyne wanted
on iTape.movetoclear2(): {state = position.bit2_clear; iTape.positionOut();}
on iTape.movetoclear3(): {state = position.bit3_clear; iTape.positionOut();}
on iTape.moveto1(): {iTape.positionIn(); state = position.bit1;}
on iTape.moveto2(): {iTape.positionIn(); state = position.bit2;}
on iTape.moveto3(): {iTape.positionIn(); state = position.bit3;}
}
[state.bit2_clear]
{
on iTape.movetoclear1(): {state = position.bit1_clear; iTape.positionOut();}
on iTape.movetoclear2(): {state = position.bit2_clear; iTape.positionOut();} //Dezyne wanted
on iTape.movetoclear3(): {state = position.bit3_clear; iTape.positionOut();}
on iTape.moveto1(): {iTape.positionIn(); state = position.bit1;}
on iTape.moveto2(): {iTape.positionIn(); state = position.bit2;}
on iTape.moveto3(): {iTape.positionIn(); state = position.bit3;}
}
[state.bit3_clear]
{
on iTape.movetoclear1(): {state = position.bit1_clear; iTape.positionOut();}
on iTape.movetoclear2(): {state = position.bit2_clear; iTape.positionOut();}
on iTape.movetoclear3(): {state = position.bit3_clear; iTape.positionOut();} //Dezyne wanted
on iTape.moveto1(): {iTape.positionIn(); state = position.bit1;}
on iTape.moveto2(): {iTape.positionIn(); state = position.bit2;}
on iTape.moveto3(): {iTape.positionIn(); state = position.bit3;}
}
on iTape.dontmove():{}
}
}
component Head // Gives orders to position the tape for intake and output
{
provides IHead iHead;
requires ITapePusher iTapePusher;
requires ITapeColorSensor iTapeColorSensor;
requires IDiskSensor iDiskSensor;
requires ITape iTape;
behaviour
{
enum State {waiting, busy_1, busy_2, busy_3, clear_1, clear_2, clear_3};
State state = State.waiting;
bool bit1w = false;
bool bit2w = false;
bool bit3w = false;
bool white_sensed = false;
[state.waiting]
{
on iHead.start_building(): {state = State.busy_1; iTape.moveto1();} // moves tape to the bit1 intake slot
on iHead.start_clearing(): {state = State.clear_1; iTape.movetoclear1();}
on iHead.next_bit():{}
}
[state.busy_1]
{
on iTape.positionIn(): {} //iHead.tape_takefromfloor(); Dezyne doesn't allow
on iHead.next_bit(): {state = State.busy_2; iTape.moveto2();} // waits until one is pushed in and moves to slot 2
on iHead.start_clearing(): {state = State.clear_1; iTape.movetoclear1();}
}
[state.busy_2]
{
on iTape.positionIn(): {}//iHead.tape_takefromfloor(); Dezyne doesn't allow
on iHead.next_bit(): {state = State.busy_3; iTape.moveto3();}
on iHead.start_clearing(): {state = State.clear_1; iTape.movetoclear1();}
}
[state.busy_3]
{
on iTape.positionIn():{}//iHead.tape_takefromfloor(); Dezyne doesn't allow
on iHead.next_bit(): {}
on iHead.start_clearing(): {state = State.clear_1; iTape.movetoclear1();}
}
[state.clear_1]
{
on iTape.positionOut(): {iTapePusher.push(); iTape.movetoclear2(); state = State.clear_2;}
//on iTapePusher.pushComplete(): {state = State.clear_2; iTape.movetoclear2();} clearing procedure
}
[state.clear_2]
{
on iTape.positionOut(): {iTapePusher.push(); iTape.movetoclear3(); state = State.clear_3;}
//on iTapePusher.pushComplete(): {state = State.clear_3; iTape.movetoclear3();}
}
[state.clear_3]
{
on iTape.positionOut(): {iTapePusher.push(); state=State.waiting;}// iHead.tape_is_clear(); not allowed by Dezyne
//on iTapePusher.pushComplete(): {state = State.waiting; iTape.dontmove(); iHead.tape_is_clear();}
}
}
}
component Controller //keeps track of which number we're building, communicates required bitcolours
// gives the order to start building, clearing, incrementing (the checking of bits must still be implemented)
{
provides IController iController;
requires ILCD iLCD;
requires IFloorPicker iFloorPicker;
requires IHead iHead;
requires IRobotCommunication iRobotCommunication;
behaviour
{
enum making {off, empty, zero, one, two, three, four, five, six, seven, error, wait};
making state = making.off;
bool bit1w = false;
bool bit2w = false;
bool bit3w = false;
bool white_sensed = false;
bool full = false;
on iFloorPicker.black_on_floor(): white_sensed = false;
on iFloorPicker.white_on_floor(): white_sensed = true;
[state.off] //starts with off
{
on iController.init():{state = making.empty;}
on iController.error():{illegal;}
}
[state.wait]
{
on iController.continue(): {iController.resume(); state = making.empty; iFloorPicker.resume();} // pause to wait for other robots to catch up, dont know how to actually pause the current action yet
}
[state.empty]
{
on iController.error(): {state = making.error; iHead.start_clearing(); iRobotCommunication.controller_error();}
on iController.update():
{
state = making.zero;
bit1w = false; bit2w = false; bit3w = false;
iHead.start_building();
}
//on iController.init():{} Dezyne wanted this here
on iController.continue():{} //Dezyne wanted this here
}
[state.zero]
{
on iController.error(): {state = making.error; iHead.start_clearing();iRobotCommunication.controller_error();}
//first bit
on iHead.tape_takefromfloor():
{
if (bit1w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit1w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor():{ iHead.next_bit(); iRobotCommunication.controller_took_disk();}
//second bit
on iHead.tape_takefromfloor():
{
if (bit2w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit2w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): { iHead.next_bit(); iRobotCommunication.controller_took_disk();}
//third bit
on iHead.tape_takefromfloor():
{
if (bit3w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit3w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): {full = true; iRobotCommunication.controller_took_disk();} //checker to mark that the tape is full
on iController.update(): // need to manually update the number because Dezyne
{
iHead.start_clearing(); state = making.one; iHead.start_building();
bit1w = false; bit2w = false; bit3w = true; full = false;
}
on iController.continue():{}//dezyne wanted this here
}
[state.one]
{
on iController.error(): {state = making.error; iHead.start_clearing();iRobotCommunication.controller_error();}
//first bit
on iHead.tape_takefromfloor():
{
if (bit1w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit1w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): { iHead.next_bit(); iRobotCommunication.controller_took_disk();}
//second bit
on iHead.tape_takefromfloor():
{
if (bit2w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit2w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): { iHead.next_bit(); iRobotCommunication.controller_took_disk();}
//third bit
on iHead.tape_takefromfloor():
{
if (bit3w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit3w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): {full = true; iRobotCommunication.controller_took_disk();}//checker to mark that the tape is full
on iController.update():
{
iHead.start_clearing(); state = making.two; iHead.start_building();
bit1w = false; bit2w = true; bit3w = false; full = false;
}
on iController.continue():{}//dezyne wanted this here
}
[state.two]
{
on iController.error(): {state = making.error; iHead.start_clearing();iRobotCommunication.controller_error();}
//first bit
on iHead.tape_takefromfloor():
{
if (bit1w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit1w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): { iHead.next_bit(); iRobotCommunication.controller_took_disk();}
//second bit
on iHead.tape_takefromfloor():
{
if (bit2w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit2w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): { iHead.next_bit(); iRobotCommunication.controller_took_disk();}
//third bit
on iHead.tape_takefromfloor():
{
if (bit3w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit3w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): {full = true; iRobotCommunication.controller_took_disk();} //checker to mark that the tape is full
on iController.update():
{
iHead.start_clearing(); state = making.three; iHead.start_building();
bit1w = false; bit2w = true; bit3w = true; full = false;
}
on iController.continue():{}//dezyne wanted this here
}
[state.three]
{
on iController.error(): {state = making.error; iHead.start_clearing();iRobotCommunication.controller_error();}
//first bit
on iHead.tape_takefromfloor():
{
if (bit1w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit1w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): { iHead.next_bit(); iRobotCommunication.controller_took_disk();}
//second bit
on iHead.tape_takefromfloor():
{
if (bit2w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit2w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): { iHead.next_bit(); iRobotCommunication.controller_took_disk();}
//third bit
on iHead.tape_takefromfloor():
{
if (bit3w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit3w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): {full = true; iRobotCommunication.controller_took_disk();}//checker to mark that the tape is full
on iController.update():
{
iHead.start_clearing(); state = making.four; iHead.start_building();
bit1w = true; bit2w = false; bit3w = false; full = false;
}
on iController.continue():{}//dezyne wanted this here
}
[state.four]
{
on iController.error(): {state = making.error; iHead.start_clearing();iRobotCommunication.controller_error();}
//first bit
on iHead.tape_takefromfloor():
{
if (bit1w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit1w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): { iHead.next_bit(); iRobotCommunication.controller_took_disk();}
//second bit
on iHead.tape_takefromfloor():
{
if (bit2w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit2w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): { iHead.next_bit(); iRobotCommunication.controller_took_disk();}
//third bit
on iHead.tape_takefromfloor():
{
if (bit3w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit3w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): {full = true; iRobotCommunication.controller_took_disk();}//checker to mark that the tape is full
on iController.update():
{
iHead.start_clearing(); state = making.five; iHead.start_building();
bit1w = true; bit2w = false; bit3w = true; full = false;
}
on iController.continue():{}//dezyne wanted this here
}
[state.five]
{
on iController.error(): {state = making.error; iHead.start_clearing();iRobotCommunication.controller_error();}
//first bit
on iHead.tape_takefromfloor():
{
if (bit1w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit1w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): { iHead.next_bit(); iRobotCommunication.controller_took_disk();}
//second bit
on iHead.tape_takefromfloor():
{
if (bit2w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit2w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): { iHead.next_bit(); iRobotCommunication.controller_took_disk();}
//third bit
on iHead.tape_takefromfloor():
{
if (bit3w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit3w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): {full = true; iRobotCommunication.controller_took_disk();}//checker to mark that the tape is full
on iController.update():
{
iHead.start_clearing(); state = making.six; iHead.start_building();
bit1w = true; bit2w = true; bit3w = false; full = false;
}
on iController.continue():{}//dezyne wanted this here
}
[state.six]
{
on iController.error(): {state = making.error;iHead.start_clearing();iRobotCommunication.controller_error();}
//first bit
on iHead.tape_takefromfloor():
{
if (bit1w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit1w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): { iHead.next_bit(); iRobotCommunication.controller_took_disk();}
//second bit
on iHead.tape_takefromfloor():
{
if (bit2w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit2w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): { iHead.next_bit(); iRobotCommunication.controller_took_disk();}
//third bit
on iHead.tape_takefromfloor():
{
if (bit3w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit3w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): {full = true; iRobotCommunication.controller_took_disk();}//checker to mark that the tape is full
on iController.update():
{
iHead.start_clearing(); state = making.seven; iHead.start_building();
bit1w = true; bit2w = true; bit3w = true; full = false;
}
on iController.continue():{} //dezyne wanted this here
}
[state.seven]
{
on iController.error(): {state = making.error; iHead.start_clearing();iRobotCommunication.controller_error();}
//first bit
on iHead.tape_takefromfloor():
{
if (bit1w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit1w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): { iHead.next_bit(); iRobotCommunication.controller_took_disk();}
//second bit
on iHead.tape_takefromfloor():
{
if (bit2w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit2w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): { iHead.next_bit(); iRobotCommunication.controller_took_disk();}
//third bit
on iHead.tape_takefromfloor():
{
if (bit3w && white_sensed) {iFloorPicker.take_from_floor();} // checks if the correct bit is coming
if (!bit3w && !white_sensed) {iFloorPicker.take_from_floor();} // orders to take it if correct
}
on iFloorPicker.taken_from_floor(): {full = true; iRobotCommunication.controller_took_disk();}//checker to mark that the tape is full
on iController.update():
{
iHead.start_clearing(); state = making.zero; iHead.start_building();
bit1w = false; bit2w = false; bit3w = false; full = false;
}
on iController.continue():{} //dezyne wanted this here
}
[state.error]
{
//!!!Controller must give continue instruction in error state to trigger iHead.start_clearing because inevitable didn't work
on iController.continue(): {iHead.start_clearing();}
on iController.error(): {iHead.start_clearing();iRobotCommunication.controller_error();}
on iHead.tape_is_clear(): {iRobotCommunication.controller_error_solved(); state = making.zero;}
on iController.update():{}
}
}
}
component FloorPicker
{
requires IFloorSensor iFloorSensor; // used to be provide
requires IFloorPusher iFloorPusher; // used to be provide, but i cant order the floorpusher to push if it is a provide relation
provides IFloorPicker iFloorPicker;
//requires IController iController;
behaviour
{
enum State {sensing, disk_found, paused};
State state = State.sensing;
on iFloorPicker.pause(): state = State.paused;
[state.sensing]
{
on iFloorSensor.black_sensed(): {state = State.disk_found; iFloorPicker.black_on_floor();}
on iFloorSensor.white_sensed(): {state = State.disk_found; iFloorPicker.white_on_floor();} //have to give the command to push to the pusher, cant do that with a provide
on iFloorPicker.take_from_floor():{} //Dezyne wanted this here
}
[state.disk_found]
{
on iFloorPicker.take_from_floor():{iFloorPusher.push();}
on iFloorPusher.completedPushProcedure(): {iFloorPicker.taken_from_floor();}
}
[state.paused]
{
on iFloorPicker.resume(): state = State.sensing;