-
Notifications
You must be signed in to change notification settings - Fork 3
/
scribbler_test.spin
2040 lines (1749 loc) · 160 KB
/
scribbler_test.spin
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
''*********************************************
''* Scribbler Test Utility *
''* Author: Ben Wirz, Element Products, Inc. *
''* Copyright (c) 2010 Parallax, Inc. *
''* See end of file for terms of use. *
''*********************************************
''
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
VERSION = 3 'Release Version Number
SUBVERSION = 2574 'Internal Version Number
OBJ
sio : "FullDuplexSerial"
scribbler : "scribbler"
music : "scribbler_music"
pwm : "PWMx8"
VAR
long last_call
byte line_threshold,obs_threshold
PUB start(default_version,default_subversion,line_tst,obs_tst) | index
''Initialize the test utility
''Print the firmware version numbers.
''default_version - default program version number
''default_subversion - default program subversion number
''line_test - the trip value for the line sensor
''obs_test - the obstacle sensor threshold
'Save the line following and obstacle sensitivity
line_threshold := (line_tst #> 0) <# $FF
obs_threshold := (obs_tst #> 0) <# 100
'Start hardware driver cogs and low level routlines
scribbler.start
scribbler.start_motors
scribbler.start_tones
'Start the Serial Communication Object
sio.start(scribbler#RX, scribbler#TX, 0, 19200)
sio.tx(CLS)
sio.rxflush
scribbler.set_leds(scribbler#OFF,scribbler#OFF,scribbler#OFF,scribbler#BLUE)
scribbler.beep
sio.tx(cls)
if scribbler.get_model_s2
print_title(TEST_COL_START,TEST_COL_END,-1,string("Scribbler S2 Robot"))
else
print_title(TEST_COL_START,TEST_COL_END,-1,string("Scribbler S3 Robot"))
print_str(TEST_COL_START,TEST_ROW_0,string("Press the Button for the Production Test"))
print_str(TEST_COL_START,TEST_ROW_1,string("Press the Space Bar for the Test Utility Menu"))
print_str(TEST_COL_START,TEST_ROW_3,string("File Versions:"))
print_str(constant(TEST_COL_START+1),TEST_ROW_4,string("scribbler"))
cursor_col(TEST_COL_VER)
sio.dec(scribbler#VERSION)
sio.tx("(")
sio.dec(scribbler#SUBVERSION)
sio.tx(")")
print_str(constant(TEST_COL_START+1),TEST_ROW_5,string("scribbler_default"))
cursor_col(TEST_COL_VER)
if default_version <> 0
sio.dec(default_version)
else
sio.tx("?")
sio.tx("(")
if default_subversion <> 0
sio.dec(default_subversion)
else
sio.tx("?")
sio.tx(")")
print_str(constant(TEST_COL_START+1),TEST_ROW_6,string("scribbler_test"))
cursor_col(TEST_COL_VER)
sio.dec(VERSION)
sio.tx("(")
sio.dec(SUBVERSION)
sio.tx(")")
print_str(constant(TEST_COL_START+1),TEST_ROW_7,string("scribbler_music"))
cursor_col(TEST_COL_VER)
sio.dec(music#VERSION)
sio.tx("(")
sio.dec(music#SUBVERSION)
sio.tx(")")
repeat until button_wait(1) == 1
production_test
CON
'Production Screen Layout
TOP_MARGIN = 4
LEFT_MARGIN = 3
TEST_COL_START = 1
TEST_COL_END = 52
TEST_COL_MID = (TEST_COL_END-TEST_COL_START)/2
TEST_COL_VER = TEST_COL_START + 20
TEST_COL_STEP_NUM = TEST_COL_START + 4
TEST_COL_STEP_NAME = TEST_COL_STEP_NUM + 5
TEST_COL_PASS = TEST_COL_STEP_NAME + 28
TEST_ROW_0 = TOP_MARGIN
TEST_ROW_1 = TOP_MARGIN + 1
TEST_ROW_2 = TOP_MARGIN + 2
TEST_ROW_3 = TOP_MARGIN + 3
TEST_ROW_4 = TOP_MARGIN + 4
TEST_ROW_5 = TOP_MARGIN + 5
TEST_ROW_6 = TOP_MARGIN + 6
TEST_ROW_7 = TOP_MARGIN + 7
TEST_ROW_8 = TOP_MARGIN + 8
TEST_ROW_RESULTS = TEST_ROW_2
TEST_ROW_BUTTON = TEST_ROW_RESULTS + TEST_LED + 2
TEST_ROW_NUMBER = TOP_MARGIN - 1
TEST_COL_NUMBER = TEST_COL_END - 8
TEST_PASS_PAUSE = 20 'Message display pause (10th secs)
UNTESTED = 1
'Production Test Steps
#0,TEST_ELECTRICAL,TEST_LIGHT,TEST_IDLER,TEST_MIC,TEST_LINE,TEST_TRACK,TEST_SPEED,TEST_IR,TEST_SPEAKER,TEST_LED
MOTOR_SAMPLE_LEN = 1
#0,MOT_LEFT,MOT_RIGHT
PUB production_test | current_test,step_pass[TEST_LED+1],index
''Perform a series of tests to verify the scribbler's operation
current_test := TEST_ELECTRICAL
longfill (@step_pass,UNTESTED,TEST_LED+1)
repeat
sio.tx(cls)
print_str(TEST_COL_NUMBER,TEST_ROW_NUMBER,string("Step: "))
sio.dec(current_test + 1)
case current_test
TEST_ELECTRICAL:
step_pass[TEST_ELECTRICAL] := electrical_test
TEST_LIGHT:
step_pass[TEST_LIGHT] := light_test
TEST_IDLER:
step_pass[TEST_IDLER] := idler_test(8)
TEST_MIC:
step_pass[TEST_MIC] := mic_test
TEST_LINE:
step_pass[TEST_LINE] := line_test
TEST_TRACK:
step_pass[TEST_TRACK] := track_test
TEST_SPEED:
step_pass[TEST_SPEED] := speed_test
TEST_IR:
step_pass[TEST_IR] := ir_test
TEST_SPEAKER:
step_pass[TEST_SPEAKER] := speaker_test
TEST_LED:
step_pass[TEST_LED] := led_test
print_str(TEST_COL_NUMBER,TEST_ROW_NUMBER,string("Step: "))
sio.dec(current_test + 1)
if step_pass[current_test]
scribbler.set_leds(scribbler#GREEN,scribbler#GREEN,scribbler#GREEN,scribbler#OFF)
else
scribbler.set_leds(scribbler#RED,scribbler#RED,scribbler#RED,scribbler#OFF)
repeat index from TEST_ELECTRICAL to TEST_LED
'Mark the current test step with an arrow
cursor(constant(TEST_COL_START+1),TEST_ROW_RESULTS + index)
if index == current_test
sio.tx("-")
sio.tx(">")
'Print the test step number & name
cursor_col(TEST_COL_STEP_NUM)
sio.tx("(")
sio.dec(index+1)
sio.tx(")")
cursor_col(TEST_COL_STEP_NAME)
case index
TEST_ELECTRICAL: sio.str(string("Electrical Test"))
TEST_LIGHT: sio.str(string("Light Sensor Test"))
TEST_IDLER: sio.str(string("Idler Wheel Test"))
TEST_MIC: sio.str(string("Microphone Test"))
TEST_LINE: sio.str(string("Line Sensor Test"))
TEST_TRACK: sio.str(string("Track Test"))
TEST_SPEED: sio.str(string("Motor Speed Test"))
TEST_IR: sio.str(string("IR Obstacle Sensor Test"))
TEST_SPEAKER: sio.str(string("Speaker Test"))
TEST_LED: sio.str(string("Visible LED Test"))
'Print the status of each step
cursor_col(TEST_COL_PASS)
sio.str(string(" - "))
if step_pass[index] == UNTESTED
sio.str(string("Untested"))
elseif step_pass[index] == FALSE
sio.str(string("FAIL"))
else
sio.str(string("Pass"))
print_str(TEST_COL_START,TEST_ROW_BUTTON,string("Button Press:"))
if current_test < TEST_LED
print_str(constant(TEST_COL_START+1),constant(TEST_ROW_BUTTON+1),string("Press Once - Next Step"))
print_str(constant(TEST_COL_START+1),constant(TEST_ROW_BUTTON+2),string("Press Twice - Repeat Current Step"))
if current_test > TEST_ELECTRICAL
print_str(constant(TEST_COL_START+1),constant(TEST_ROW_BUTTON+3),string("Press Three Times - Previous Step"))
case index := button_wait(3)
1: 'Move to the next test
current_test := (current_test + 1) <# TEST_LED
scribbler.set_leds(scribbler#OFF,scribbler#OFF,scribbler#GREEN,scribbler#OFF)
2: 'Repeat the current test
scribbler.set_leds(scribbler#OFF,scribbler#GREEN,scribbler#OFF,scribbler#OFF)
3: 'Go back to the previous test
current_test := (current_test - 1) #> TEST_ELECTRICAL
scribbler.set_leds(scribbler#GREEN,scribbler#OFF,scribbler#OFF,scribbler#OFF)
"1".."9": 'Number key press
current_test := index - "1"
"0":
current_test := 9
CON
'Power Screen Layout
PWR_COL_VLT = LEFT_MARGIN + 9
PWR_COL_FAIL = PWR_COL_VLT + 12
PWR_ROW = TOP_MARGIN
PWR_ROW_END = PWR_ROW + 8
' Test Voltage Limits
PWR_BATT_MIN_S2 = (600*255)/330/4 '1.5V V (S2)
PWR_BATT_MIN_S3 = (300*255)/330/2 '1.5V V (S3)
PWR_3V3_MIN = (310*255)/330 '3.10 V
PWR_3V3_MAX = (345*255)/330 '3.45 V
PWR_5V0_MIN_DIV = (475*255)/330 '4.75 V - divided 5V bus with 3.3V reference
PWR_5V0_MAX_DIV = (525*255)/330 '5.25 V
PWR_5V0_MIN = (475*255)/500 '4.75 V - non divided 5V bus with 5.0V reference
PWR_5V0_MAX = (525*255)/500 '5.25 V
PWR_VMOT_MIN = (850*255)/330 '8.50 V (S3)
PWR_VMOT_MAX = (950*255)/330 '9.50 V (S3)
PWR_TRIP_MIN = (18*255)/330 ' 18 mV (S2)
PWR_TRIP_MAX = (26*255)/330 ' 26 mV (S2)
PWR_I_MAX = 150 '150 mA (S2)
PUB electrical_test | calc, cog_index, cog_list[8], pass
''Check Bus Voltages
scribbler.set_leds(scribbler#OFF,scribbler#OFF,scribbler#OFF,scribbler#OFF)
pass := TRUE
print_title(TEST_COL_START,TEST_COL_END,-1,string("Electrical Test"))
'Start all unused cogs to load the 3V3 Bus
repeat cog_index from 0 to 7
cog_list[cog_index] := cognew(@busy, 0)
if cog_list[cog_index] == -1
quit
print_str(LEFT_MARGIN,constant(PWR_ROW+1),string("Battery"))
if scribbler.get_model_s2
calc := scribbler.get_adc_results(scribbler#ADC_VBAT)
print_volts_3v3(PWR_COL_VLT,constant(PWR_ROW+1), calc * 4)
if calc < PWR_BATT_MIN_S2
clear_row(constant(PWR_ROW+1))
print_str(LEFT_MARGIN,constant(PWR_ROW+1),string("FAIL - Replace Batteries"))
repeat
else
calc := scribbler.get_adc_results(scribbler#ADC_VBAT)
print_volts_3v3(PWR_COL_VLT,constant(PWR_ROW+1), calc * 2)
if calc < PWR_BATT_MIN_S3
clear_row(constant(PWR_ROW+1))
print_str(LEFT_MARGIN,constant(PWR_ROW+1),string("FAIL - Recharge Battery"))
calc := scribbler.get_adc_results(scribbler#ADC_VDD)
print_str(LEFT_MARGIN,constant(PWR_ROW+2),string("3V3 Bus"))
print_volts_3v3(PWR_COL_VLT,constant(PWR_ROW+2),calc)
ifnot limit_test(PWR_COL_FAIL,constant(PWR_ROW+2),calc,PWR_3V3_MIN,PWR_3V3_MAX)
pass := FALSE
if (scribbler.get_model_s2) ' only the S2 has the 5V bus current monitor
calc := ((scribbler.get_adc_results(scribbler#ADC_5V) - scribbler.get_adc_results(scribbler#ADC_IDD)) * 50000) / 11985
print_str(constant(PWR_COL_VLT+6),constant(PWR_ROW+3),string("mA"))
print_dec_word(constant(PWR_COL_VLT-1),constant(PWR_ROW+3),calc)
ifnot limit_test(PWR_COL_FAIL,constant(PWR_ROW+3),calc,20,PWR_I_MAX)
pass := FALSE
if calc > PWR_I_MAX
print_str(PWR_COL_FAIL,constant(PWR_ROW+3),string("FAIL - Over Current"))
pass := FALSE
' Resistor divided 5V bus, 3.3V reference
calc := scribbler.get_adc_results(scribbler#ADC_5V_DIV) * 2
print_str(LEFT_MARGIN,constant(PWR_ROW+4),string("5V0 Div"))
print_volts_3v3(PWR_COL_VLT,constant(PWR_ROW+4),calc)
ifnot limit_test(PWR_COL_FAIL,constant(PWR_ROW+4),calc,PWR_5V0_MIN_DIV,PWR_5V0_MAX_DIV)
pass := FALSE
'5V bus with no resistor divider, 5.0V reference
calc := scribbler.get_adc_results(scribbler#ADC_5V)
print_str(LEFT_MARGIN,constant(PWR_ROW+5),string("5V0 Bus"))
print_volts_5v0(PWR_COL_VLT,constant(PWR_ROW+5),calc)
ifnot limit_test(PWR_COL_FAIL,constant(PWR_ROW+5),calc,PWR_5V0_MIN,PWR_5V0_MAX)
pass := FALSE
if (scribbler.get_model_s2) 'S2 - Over Current Reference Voltage
calc := scribbler.get_adc_results(scribbler#ADC_VTRIP)
print_str(LEFT_MARGIN,constant(PWR_ROW+6),string("Mot Trip"))
print_volts_3v3(PWR_COL_VLT,constant(PWR_ROW+6),calc)
ifnot limit_test(PWR_COL_FAIL,constant(PWR_ROW+6),calc,PWR_TRIP_MIN,PWR_TRIP_MAX)
pass := FALSE
else 'S3 - Motor Power Supply Voltage
calc := (scribbler.get_adc_results(scribbler#ADC_VMOT) * (100+33)) / 33
print_str(LEFT_MARGIN,constant(PWR_ROW+6),string("Motor"))
print_volts_3v3(PWR_COL_VLT,constant(PWR_ROW+6),calc)
ifnot limit_test(PWR_COL_FAIL,constant(PWR_ROW+6),calc,PWR_VMOT_MIN,PWR_VMOT_MAX)
pass := FALSE
'Stop extra cogs
repeat while cog_index > 0
cog_index -= 1
cogstop(cog_list[cog_index])
if (scribbler.get_model_s2)
scribbler.stop_all
'Read the undriven hacker port to check the pull-up resistors
dira[scribbler#P5..scribbler#P0]~
scribbler.delay_tenths(2)
if INA[scribbler#P5..scribbler#P0] <> %111111
print_str(LEFT_MARGIN,constant(PWR_ROW+7),string("Fail - Hacker Port Pull-Up: "))
sio.bin(INA[scribbler#P5..scribbler#P0],6) '
pass := FALSE
else 'Drive the hacker port low and check the port
dira[scribbler#P5..scribbler#P0]~~
outa[scribbler#P5..scribbler#P0]~
scribbler.delay_tenths(1)
if INA[scribbler#P5..scribbler#P0] <> %000000
print_str(LEFT_MARGIN,constant(PWR_ROW+7),string("Fail - Hacker Port Stuck High: "))
sio.bin(INA[scribbler#P5..scribbler#P0],6) '
pass := FALSE
else
print_str(LEFT_MARGIN,constant(PWR_ROW+7),string("Hacker Port Pass"))
scribbler.start
scribbler.start_motors
scribbler.start_tones
'Print the test results
scribbler.delay_tenths(TEST_PASS_PAUSE)
sio.tx(cls)
print_title(TEST_COL_START,TEST_COL_END,-1,string("Electrical Test"))
print_str(TEST_COL_START,TEST_ROW_0,string("Electrical Test "))
if pass
sio.str(string("Pass"))
else
sio.str(string("Fail"))
return pass
PUB limit_test(col,row,vlt,vlt_min,vlt_max)
''Check a voltage and print Pass or Fail
if vlt < vlt_min
print_str(col,row,string("FAIL - Under"))
return FALSE
elseif vlt > vlt_max
print_str(col,row,string("FAIL - Over"))
return FALSE
else
print_str(col,row,string("Pass"))
return TRUE
CON
LIGHT_LOOP_FREQ = 10 'Loop frequency (Hz)
LIGHT_TEST_TIME = 20 * LIGHT_LOOP_FREQ 'Test Time for each step
LIGHT_ROW_TIME = 7
LIGHT_ROW_END = LIGHT_ROW_TIME
LIGHT_SHINE_TRIP = 200 'Min Flaslight Trip Level
#0,COVER_LEFT,COVER_CENTER,COVER_RIGHT,SHINE_LEFT,SHINE_CENTER,SHINE_RIGHT
PUB light_test | sample_left,sample_center,sample_right,cover_trip_left,cover_trip_center,cover_trip_right,state,time
''Test the light sensor
''
''Display light sensor levels on the corresponding left, center and right LED's
''If a light sensors hole is covered - set the LED to off. If the hole is uncovered,
''the LED will be green or yellow.
time := LIGHT_TEST_TIME
'Sample and scale light sensor levels with the fingers off
cover_trip_left := (scribbler.light_sensor(scribbler#LEFT) * 8) / 10
cover_trip_center := (scribbler.light_sensor(scribbler#CENTER) * 8) / 10
cover_trip_right := (scribbler.light_sensor(scribbler#RIGHT) * 8) / 10
print_title(TEST_COL_START,TEST_COL_END,-1,string("Light Sensor Test"))
music.play_song(music#LIGHT,2000)
print_str(TEST_COL_START,TEST_ROW_0,string("Cover the Left Light Sensor"))
print_str(TEST_COL_START,LIGHT_ROW_TIME,string("Time: "))
state := COVER_LEFT
periodic_start
repeat
print_dec(constant(TEST_COL_START + 7),LIGHT_ROW_TIME,time / LIGHT_LOOP_FREQ)
sio.str(string(" secs "))
sample_left := scribbler.light_sensor(scribbler#LEFT)
sample_center := scribbler.light_sensor(scribbler#CENTER)
sample_right := scribbler.light_sensor(scribbler#RIGHT)
scribbler.set_led(scribbler#LEFT,lookupz(scribbler.light_sensor(scribbler#LEFT) >> 6 :scribbler#OFF,scribbler#YELLOW,scribbler#DIM_GREEN,scribbler#GREEN))
scribbler.set_led(scribbler#CENTER,lookupz(scribbler.light_sensor(scribbler#CENTER) >> 6 :scribbler#OFF,scribbler#YELLOW,scribbler#DIM_GREEN,scribbler#GREEN))
scribbler.set_led(scribbler#RIGHT,lookupz(scribbler.light_sensor(scribbler#RIGHT) >> 6 :scribbler#OFF,scribbler#YELLOW,scribbler#DIM_GREEN,scribbler#GREEN))
case state
COVER_LEFT:
if (sample_left =< cover_trip_left) and (sample_center > cover_trip_center) and (sample_right > cover_trip_right)
music.play_note(music#HALF,music#A4,0)
clear_row(TEST_ROW_0)
print_str(TEST_COL_START,TEST_ROW_0,string("Cover the Center Light Sensor"))
state := COVER_CENTER
time := LIGHT_TEST_TIME
COVER_CENTER:
if (sample_left > cover_trip_left) and (sample_center =< cover_trip_center) and (sample_right > cover_trip_right)
music.play_note(music#HALF,music#B4,0)
clear_row(TEST_ROW_0)
print_str(TEST_COL_START,TEST_ROW_0,string("Cover the Right Light Sensor"))
state := COVER_RIGHT
time := LIGHT_TEST_TIME
COVER_RIGHT:
if (sample_left > cover_trip_left) and (sample_center > cover_trip_center) and (sample_right =< cover_trip_right)
music.play_note(music#HALF,music#C4,0)
clear_row(TEST_ROW_0)
print_str(TEST_COL_START,TEST_ROW_0,string("Shine a Light into the Left Light Sensor"))
state := SHINE_LEFT
time := LIGHT_TEST_TIME
SHINE_LEFT:
if sample_left > LIGHT_SHINE_TRIP
music.play_note(music#HALF,music#D4,0)
clear_row(TEST_ROW_0)
print_str(TEST_COL_START,TEST_ROW_0,string("Shine a Light into the Center Light Sensor"))
state := SHINE_CENTER
time := LIGHT_TEST_TIME
SHINE_CENTER:
if sample_center > LIGHT_SHINE_TRIP
music.play_note(music#HALF,music#E4,0)
clear_row(TEST_ROW_0)
print_str(TEST_COL_START,TEST_ROW_0,string("Shine a Light into the Right Light Sensor"))
state := SHINE_RIGHT
time := LIGHT_TEST_TIME
SHINE_RIGHT:
if sample_right > LIGHT_SHINE_TRIP
music.play_note(music#HALF,music#F4,0)
clear_row(TEST_ROW_0)
clear_row(LIGHT_ROW_TIME)
print_str(TEST_COL_START,TEST_ROW_0,string("Light Test Pass"))
return TRUE
time -= 1
if (time == 0)
scribbler.delay_tenths(TEST_PASS_PAUSE)
clear_row(TEST_ROW_0)
clear_row(LIGHT_ROW_TIME)
print_str(TEST_COL_START,TEST_ROW_0,string("** Fail - Light Timer Expired."))
return FALSE
periodic(LIGHT_LOOP_FREQ)
CON
'Idler Test Screen Layout
IDLER_COL_A = LEFT_MARGIN + 16
IDLER_COL_B = LEFT_MARGIN + 28
IDLER_ROW_PASS = 7
IDLER_ROW_TIME = 10
IDLER_LOOP_FREQ = 5 'Loop frequency (Hz)
IDLER_TEST_TIME = 15 'Max Test Time (Sec)
PUB idler_test(count_pass) | sample,cnt_last,cnt_init,time
''Print the Idler Wheel ADC return
''Print the Idler Wheel counter
''Beep on each Idler Wheel hole detect
''count_pass = number of counts to consider a test pass if positive
''repeat until key press if count_pass is negative
scribbler.set_leds(scribbler#OFF,scribbler#OFF,scribbler#OFF,scribbler#OFF)
scribbler.set_voices(scribbler#SQU,scribbler#SQU)
scribbler.set_volume(100)
print_title(TEST_COL_START,TEST_COL_END,-1,string("Idler Wheel Encoder Test"))
if count_pass < 0
exit_print(TEST_COL_MID,10)
print_center(TOP_MARGIN,string("Spin the Idler Wheel"))
print_str(LEFT_MARGIN,6,string("ADC Value:"))
print_str(LEFT_MARGIN,8,string("Idler Counter:"))
cnt_init := cnt_last := scribbler.get_results(scribbler#CNT_IDLER)
if (count_pass => 0)
time := constant(IDLER_TEST_TIME * IDLER_LOOP_FREQ)
print_str(LEFT_MARGIN,IDLER_ROW_TIME,string("Test Time: "))
periodic_start
repeat
'Print Idler ADC Voltage
sample := scribbler.get_adc_results(scribbler#ADC_IDLER)
print_volts_3v3(IDLER_COL_A,6,sample)
print_bar(IDLER_COL_B,6,sample << 3)
'Print Idler Wheel Counter
sample := scribbler.get_results(scribbler#CNT_IDLER)
print_dec_word(IDLER_COL_A,8,sample)
'Beep if Idler Wheel Counter has Changed
if sample > cnt_last
scribbler.play_tone(100,622,0)
cnt_last := sample
if (count_pass => 0)
print_dec_word(IDLER_COL_A,IDLER_ROW_TIME,time/IDLER_LOOP_FREQ)
sio.str(string(" secs "))
if (sample => (cnt_init + count_pass))
sio.tx(cls)
print_title(TEST_COL_START,TEST_COL_END,-1,string("Idler Wheel Encoder Test"))
print_str(TEST_COL_START,TEST_ROW_0,string("Idler Wheel Test Pass"))
return TRUE
elseif (time =< 0)
sio.tx(cls)
print_title(TEST_COL_START,TEST_COL_END,-1,string("Idler Wheel Encoder Test"))
print_str(TEST_COL_START,TEST_ROW_0,string("** Fail - Idler Timer Expired"))
return FALSE
time -= 1
else
exit_check
periodic(IDLER_LOOP_FREQ)
CON
MIC_ROW_START = TOP_MARGIN
MIC_ROW_VALUE = MIC_ROW_START + 2
MIC_ROW_PASS = MIC_ROW_VALUE + 2
MIC_ROW_TIME = MIC_ROW_PASS + 3
MIC_ROW_END = 12
MIC_SAMPLES = 4 'Number of microphone samples
MIC_LOOP_FREQ = 10 'Loop frequency (Hz)
MIC_TEST_TIME = 15 'Max Test Time (Sec)
MIC_LOWER_PASS = 32 'Lower value required to pass
MIC_UPPER_PASS = 100 'Upper value required to pass
PUB mic_test | mic[MIC_SAMPLES+2],index,mic_max,pass_lower,pass_upper,time
''Microphone Check
''Display the microphone level on the LED's
scribbler.set_leds(scribbler#OFF,scribbler#OFF,scribbler#OFF,scribbler#OFF)
pass_lower := FALSE
pass_upper := FALSE
scribbler.start_mic_env
print_title(TEST_COL_START,TEST_COL_END,-1,string("Microphone Test"))
time := constant(MIC_TEST_TIME * MIC_LOOP_FREQ)
print_str(TEST_COL_START,MIC_ROW_TIME,string("Time: "))
print_center(MIC_ROW_START,string("Speak into the Microphone"))
periodic_start
longfill(@mic,scribbler.get_mic_env >> 14,MIC_SAMPLES+2)
repeat
print_dec(constant(TEST_COL_START + 7),MIC_ROW_TIME,time / MIC_LOOP_FREQ)
sio.str(string(" secs "))
mic[0] := scribbler.get_mic_env >> 14 'Sample microphone level
if mic[0] =< MIC_LOWER_PASS
pass_lower := TRUE
print_str(TEST_COL_START,MIC_ROW_PASS,string("Lower Limit Pass"))
if mic[0] => MIC_UPPER_PASS
pass_upper := TRUE
print_str(TEST_COL_START,constant(MIC_ROW_PASS+1),string("Upper Limit Pass"))
mic_max := 0
repeat index from constant(MIC_SAMPLES+1) to 1 'Search samples for max
mic[index] := mic[index-1]
if mic[index] > mic_max
mic_max := mic[index]
case mic_max >> 5 'Display mic level on LED's
0: scribbler.set_leds(scribbler#OFF,scribbler#OFF,scribbler#OFF,scribbler#NO_CHANGE)
1: scribbler.set_leds(scribbler#GREEN,scribbler#OFF,scribbler#OFF,scribbler#NO_CHANGE)
2: scribbler.set_leds(scribbler#GREEN,scribbler#GREEN,scribbler#OFF,scribbler#NO_CHANGE)
3: scribbler.set_leds(scribbler#GREEN,scribbler#GREEN,scribbler#RED,scribbler#NO_CHANGE)
print_dec_byte(TEST_COL_START,MIC_ROW_VALUE,mic_max)
print_bar(constant(TEST_COL_START + 8),MIC_ROW_VALUE,mic_max)
time -= 1
if (pass_lower and pass_upper)
scribbler.start
scribbler.start_motors
scribbler.start_tones
scribbler.delay_tenths(TEST_PASS_PAUSE)
sio.tx(cls)
print_title(TEST_COL_START,TEST_COL_END,-1,string("Microphone Test"))
print_str(TEST_COL_START,TEST_ROW_0,string("Microphone Test Pass"))
return TRUE
if (time == 0)
scribbler.start
scribbler.start_motors
scribbler.start_tones
scribbler.delay_tenths(TEST_PASS_PAUSE)
sio.tx(cls)
print_title(TEST_COL_START,TEST_COL_END,-1,string("Microphone Test"))
print_str(TEST_COL_START,TEST_ROW_0,string("** Fail - Microphone Timer Expired"))
return FALSE
periodic(MIC_LOOP_FREQ)
CON
'Line Sensor Test Screen Layout Constants
LINE_COL_LABEL = LEFT_MARGIN
LINE_COL_MIN = LINE_COL_LABEL + 8
LINE_COL_MAX = LINE_COL_MIN + 8
LINE_COL_VALUE = LINE_COL_MAX + 10
LINE_COL_FAIL = LINE_COL_VALUE + 10
LINE_ROW_MESSAGE_A = TOP_MARGIN
LINE_ROW_MESSAGE_B = LINE_ROW_MESSAGE_A + 1
LINE_ROW_LABEL = LINE_ROW_MESSAGE_B +2
LINE_ROW_BLACK = LINE_ROW_LABEL + 1
LINE_ROW_GRAY = LINE_ROW_BLACK + 4
LINE_ROW_WHITE = LINE_ROW_GRAY + 4
LINE_ROW_END = LINE_ROW_WHITE + 4
'Line Sensor Limits for each Color Reference Card
LINE_BLACK_MIN = (0*255)/330 '0.00 V
LINE_BLACK_MAX = (41*255)/330 '0.40 V
LINE_GRAY_MIN = (41*255)/330 '0.40 V
LINE_GRAY_MAX = (101*255)/330 '1.00 V
LINE_WHITE_MIN = (91*255)/330 '0.90 V
LINE_WHITE_MAX = (330*255)/330 '3.30 V
PUB line_test | pass,sample_right,sample_left,index,row,bounce_cnt
''The utility tests the line sensor using a photography color reference card set.
''Opteka DGC-LARGE-8X10 / 8" X 10" Digital Color & White Balance Card Set
''
''Black Card RGB: 16,16,15
''Gray Card RGB: 162,162,160
''White Card RGB: 220,224,223
''
''Place the scribbler on each of the black, gray & white reference cards
''one at a time as directed by the program.
''The sensors are checked to be within the correct operating limits.
scribbler.set_leds(scribbler#OFF,scribbler#OFF,scribbler#OFF,scribbler#OFF)
pass := TRUE
print_title(TEST_COL_START,TEST_COL_END,-1,string("Line Sensor Test"))
print_str(constant(LINE_COL_MIN+3),LINE_ROW_LABEL,string("Min"))
print_str(constant(LINE_COL_MAX+3),LINE_ROW_LABEL,string("Max"))
print_str(constant(LINE_COL_VALUE+1),LINE_ROW_LABEL,string("Sensor"))
repeat index from 0 to 2
print_str(constant(TEST_COL_MID - 30/2),LINE_ROW_MESSAGE_A,string("Place the scribbler on the "))
case index
0:
sio.str(string("Black Card"))
row := LINE_ROW_BLACK
print_str(LINE_COL_LABEL,row,string("Black"))
1:
sio.str(string("Gray Card"))
row := LINE_ROW_GRAY
print_str(LINE_COL_LABEL,row,string("Gray"))
2:
sio.str(string("White Card"))
row := LINE_ROW_WHITE
print_str(LINE_COL_LABEL,row,string("White"))
print_center(LINE_ROW_MESSAGE_B,string("and then Press the Button."))
print_str(constant(TEST_COL_MID - 27/2),LINE_ROW_MESSAGE_B,string("and then Press the Button."))
print_str(LINE_COL_LABEL,row + 1,string("Left"))
print_str(LINE_COL_LABEL,row + 2,string("Right"))
print_volts_3v3(LINE_COL_MIN,row + 1,lookupz(index : LINE_BLACK_MIN,LINE_GRAY_MIN,LINE_WHITE_MIN))
print_volts_3v3(LINE_COL_MAX,row + 1,lookupz(index : LINE_BLACK_MAX,LINE_GRAY_MAX,LINE_WHITE_MAX))
'Debounce unpushed button state
bounce_cnt := 0
repeat until bounce_cnt == 3
if scribbler.button_press
bounce_cnt := 0
else
bounce_cnt += 1
print_volts_3v3(LINE_COL_VALUE,row + 1,sample_left := scribbler.line_sensor(scribbler#LEFT,TRUE))
print_volts_3v3(LINE_COL_VALUE,row + 2,sample_right := scribbler.line_sensor(scribbler#RIGHT,TRUE))
scribbler.delay_tenths(1)
repeat until scribbler.button_press
print_volts_3v3(LINE_COL_VALUE,row + 1,sample_left := scribbler.line_sensor(scribbler#LEFT,TRUE))
print_volts_3v3(LINE_COL_VALUE,row + 2,sample_right := scribbler.line_sensor(scribbler#RIGHT,TRUE))
scribbler.delay_tenths(1)
ifnot limit_test(LINE_COL_FAIL,row + 1,sample_left,{
}lookupz(index:LINE_BLACK_MIN,LINE_GRAY_MIN,LINE_WHITE_MIN),{
}lookupz(index:LINE_BLACK_MAX,LINE_GRAY_MAX,LINE_WHITE_MAX))
pass := FALSE
scribbler.set_led(scribbler#LEFT,scribbler#BLINK_RED)
ifnot limit_test(LINE_COL_FAIL,row + 2,sample_right,{
}lookupz(index:LINE_BLACK_MIN,LINE_GRAY_MIN,LINE_WHITE_MIN),{
}lookupz(index:LINE_BLACK_MAX,LINE_GRAY_MAX,LINE_WHITE_MAX))
pass := FALSE
scribbler.set_led(scribbler#RIGHT,scribbler#BLINK_RED)
clear_rows(TEST_ROW_0,TEST_ROW_1)
scribbler.delay_tenths(5)
'Print the test results
scribbler.delay_tenths(TEST_PASS_PAUSE)
sio.tx(cls)
print_title(TEST_COL_START,TEST_COL_END,-1,string("Line Sensor Test"))
if pass
print_str(TEST_COL_START,TEST_ROW_0,string("Line Sensor Test Pass"))
else
print_str(TEST_COL_START,TEST_ROW_0,string("** Fail - Line Readings out of range."))
return pass
PUB track_test | distance
''Test the scribbler's Motor and Encoders
''Print out the drive_track.pdf file
''Tape the print out on top of a blank piece of paper to
''a desk top or other hard surfaces.
''Place the scribbler on the track and start the utility.
''The utility measure distance between the start and finish
''line as a check of the encoder.
''The line sensors must be operational for the
''test to work correctly.
print_title(TEST_COL_START,TEST_COL_END,-1,string("Motor & Wheel Encoder Track Test"))
print_center(TEST_ROW_0,string("Place the scribbler on the Printed Test Track"))
print_center(TEST_ROW_1,string("Press the Button to Start"))
scribbler.set_leds(scribbler#OFF,scribbler#ORANGE,scribbler#OFF,scribbler#OFF)
button_wait(1)
clear_rows(TEST_ROW_0,TEST_ROW_1)
if not scribbler.line_sensor(scribbler#LEFT,line_threshold) or not scribbler.line_sensor(scribbler#RIGHT,line_threshold)
clear_rows(TEST_ROW_0,TEST_ROW_1)
print_str(TEST_COL_START,TEST_ROW_0,string("** Fail - Black Line Detect at Start"))
return FALSE
'Move to front edge of start line
clear_rows(TEST_ROW_0,TEST_ROW_1)
print_center(TEST_ROW_0,string("Moving to Start Line"))
scribbler.set_speed(3)
scribbler.go_forward (200)
repeat while scribbler.moving
if not scribbler.line_sensor(scribbler#LEFT,line_threshold) and not scribbler.line_sensor(scribbler#RIGHT,line_threshold)
scribbler.stop_now
scribbler.set_leds(scribbler#YELLOW,scribbler#OFF,scribbler#YELLOW,scribbler#NO_CHANGE)
scribbler.beep
quit
clear_row(TEST_ROW_0)
print_center(TEST_ROW_0,string("Moving to Finish Line"))
scribbler.set_speed(4)
repeat 4 'Move Forward 100mm - The Start to Finish Line Spacing
scribbler.go_forward (50)
scribbler.wait_stop
if not scribbler.line_sensor(scribbler#LEFT,line_threshold) or not scribbler.line_sensor(scribbler#RIGHT,line_threshold)
clear_rows(TEST_ROW_0,TEST_ROW_1)
print_str(TEST_COL_START,TEST_ROW_0,string("** Fail - Black Detect between Start & Finish"))
return FALSE
repeat distance from 200 to 210
if not scribbler.line_sensor(scribbler#LEFT,line_threshold) and not scribbler.line_sensor(scribbler#RIGHT,line_threshold)
scribbler.stop_now
quit
scribbler.go_forward (1) ' Move forward 0.5mm
scribbler.wait_stop
clear_rows(TEST_ROW_0,TEST_ROW_1)
if distance =< 210
print_str(TEST_COL_START,TEST_ROW_0,string("Pass - Finish Line at: "))
sio.dec(distance/2)
sio.str(string("mm"))
return TRUE
else
scribbler.beep
scribbler.beep
scribbler.beep
print_str(TEST_COL_START,TEST_ROW_0,string("** Fail - Finish Line Not Found in the 100-105mm Range"))
return FALSE
CON
'Speed Test Screen Layout
SPD_COL_LABEL = LEFT_MARGIN
SPD_COL_LIMIT = SPD_COL_LABEL + 10
SPD_COL_VALUE = SPD_COL_LIMIT + 12
SPD_COL_FAIL = SPD_COL_VALUE + 10
SPD_RPM_TOL = 25 'Maximum Motor Speed Variation (+/- %)
SPD_3V0_RPM_MIN = 2000 * (100 - SPD_RPM_TOL)/100
SPD_3V0_RPM_MAX = 2000 * (100 + SPD_RPM_TOL)/100
SPD_6V0_RPM_MIN = 5000 * (100 - SPD_RPM_TOL)/100
SPD_6V0_RPM_MAX = 5000 * (100 + SPD_RPM_TOL)/100
SPD_3V0_I_MIN = 0
SPD_3V0_I_MAX = 90
SPD_6V0_I_MIN = 0
SPD_6V0_I_MAX = 135
SPD_VLT_STEP = 3000
PUB speed_test | vmot,volt,duty,countl,countr,side,dir,rpm,cur,min_rpm,max_rpm,min_cur,max_cur,pass
''Test the Motor Speed
pass := TRUE
scribbler.set_leds(scribbler#OFF,scribbler#OFF,scribbler#OFF,scribbler#OFF)
print_title(TEST_COL_START,TEST_COL_END,-1,string("Motor Speed Test"))
'Stops all scribbler Object Cogs so native PWM routines can be ran
'Restart ADC cog for measuring the battery voltage
scribbler.start
scribbler.button_mode(FALSE,FALSE)
start_encoder_count 'Start encoder counter
pwm.start(constant(scribbler#MOT_LEFT_PWM & $1c), constant(1 << (scribbler#MOT_LEFT_PWM & 7) | 1 << (scribbler#MOT_RIGHT_PWM & 7)), 20000)
dira := constant(1 << scribbler#MOT_LEFT_DIR | 1 << scribbler#MOT_RIGHT_DIR)
if scribbler.get_model_s2
vmot := (scribbler.get_adc_results(scribbler#ADC_VBAT) * constant(100 * 33 * 4)) / 255 'Convert Battery Voltage Units
else
vmot := (scribbler.get_adc_results(scribbler#ADC_VMOT) * constant(100*33*(100+33))) / constant(255*33) 'Convert Boost Power Supply Voltage Unit
' calc := (scribbler.get_adc_results(scribbler#ADC_VMOT) * (100+33)) / 33
print_str(SPD_COL_LABEL,constant(TOP_MARGIN-1),string("Motor Supply: "))
print_10ths(vmot)
sio.tx("V")
'Motors forward
OUTA[scribbler#MOT_LEFT_DIR]~~
OUTA[scribbler#MOT_RIGHT_DIR]~~
repeat side from MOT_LEFT to MOT_RIGHT
repeat volt from 3000 to 6000 step SPD_VLT_STEP
min_rpm := lookup(volt/SPD_VLT_STEP:SPD_3V0_RPM_MIN,SPD_6V0_RPM_MIN)
max_rpm := lookup(volt/SPD_VLT_STEP:SPD_3V0_RPM_MAX,SPD_6V0_RPM_MAX)
min_cur := lookup(volt/SPD_VLT_STEP:SPD_3V0_I_MIN,SPD_6V0_I_MIN)
max_cur := lookup(volt/SPD_VLT_STEP:SPD_3V0_I_MAX,SPD_6V0_I_MAX)
cursor(SPD_COL_LABEL,TEST_ROW_2)
sio.str(string("Test Voltage:"))
cursor(SPD_COL_LIMIT+6,TEST_ROW_2)
print_100ths(volt)
sio.str(string(" V"))
'Print limits
print_str(SPD_COL_LIMIT+3,TEST_ROW_5,string("min"))
print_str(SPD_COL_LIMIT+9,TEST_ROW_5,string("max"))
print_str(SPD_COL_LABEL,TEST_ROW_6,string("Speed"))
print_dec_word(SPD_COL_LIMIT,TEST_ROW_6,min_rpm)
sio.str(string(" - "))
print_dec_word(SPD_COL_LIMIT+6,TEST_ROW_6,max_rpm)
print_str(SPD_COL_LABEL,TEST_ROW_7,string("Current"))
print_dec_word(SPD_COL_LIMIT,TEST_ROW_7,min_cur)
sio.str(string(" - "))
print_dec_word(SPD_COL_LIMIT+6,TEST_ROW_7,max_cur)
'Calculate and print the PWM duty cycle
duty := (volt * 100)/vmot
print_str(SPD_COL_LABEL,TEST_ROW_3,string("Duty Cycle:"))
print_dec_word(SPD_COL_LIMIT+6,TEST_ROW_3,duty)
sio.str(string("%"))
'Print motor side
if (side == MOT_LEFT)
print_str(SPD_COL_LABEL,TEST_ROW_1,string("Left Motor"))
pwm.duty(scribbler#MOT_LEFT_PWM, duty * 255 / 100)
else
print_str(SPD_COL_LABEL,TEST_ROW_1,string("Right Motor"))
pwm.duty(scribbler#MOT_RIGHT_PWM, duty * 255 / 100)
waitcnt(cnt + clkfreq*2) 'Pause two seconds for motors to accelerate
countl := phsa 'Read initial encoder counts.
countr := phsb
waitcnt(cnt + clkfreq * MOTOR_SAMPLE_LEN)
countl := phsa - countl 'Read encoder counts after sample length
countr := phsb - countr
if side == MOT_LEFT
rpm := countl*constant(60/MOTOR_SAMPLE_LEN)/4
else
rpm := countr*constant(60/MOTOR_SAMPLE_LEN)/4
cur := (scribbler.get_adc_results(scribbler#ADC_IMOT) * 33000) / 5865
print_dec_word(SPD_COL_VALUE,TEST_ROW_6,rpm)
ifnot limit_test(SPD_COL_FAIL,TEST_ROW_6,rpm,min_rpm,max_rpm)
pass := FALSE
print_dec_word(SPD_COL_VALUE,TEST_ROW_7,cur)
ifnot limit_test(SPD_COL_FAIL,TEST_ROW_7,cur,min_cur,max_cur)
pass := FALSE
scribbler.delay_tenths(TEST_PASS_PAUSE)
clear_rows(TEST_ROW_0,TEST_ROW_7)
'Turn Motors Off
pwm.duty(scribbler#MOT_LEFT_PWM, 0)
pwm.duty(scribbler#MOT_RIGHT_PWM, 0)
clear_row(constant(TOP_MARGIN-1))
clear_row(TEST_ROW_0)
if pass
print_str(TEST_COL_START,TEST_ROW_0,string("Speed Test Pass."))
else
print_str(TEST_COL_START,TEST_ROW_0,string("** Fail - Speed Test."))
scribbler.start
scribbler.button_mode(FALSE,FALSE)
scribbler.start_motors
scribbler.start_tones
scribbler.delay_tenths(5)
return pass
CON
IR_DETECT_NUM = 4 'Number of repeated IR detects to pass
PUB ir_test | detect_cnt,side,time,position
''Test the IR Obstacle Sensors
scribbler.set_leds(scribbler#OFF,scribbler#OFF,scribbler#OFF,scribbler#OFF)
print_title(TEST_COL_START,TEST_COL_END,-1,string("IR Obstacle Sensor Test"))
print_str(TEST_COL_START,TEST_ROW_0,string("Place the scribbler on Carpet."))
print_str(TEST_COL_START,TEST_ROW_2,string("Press the Button to Continue."))
button_wait(1)
clear_row(TEST_ROW_0)
clear_row(TEST_ROW_2)
print_str(TEST_COL_START,TEST_ROW_0,string("Checking for False Obstacle Detects."))
print_str(TEST_COL_START,TEST_ROW_1,string("Time: "))
repeat time from 50 to 0 'Check for false obstacle detects
if scribbler.obstacle(scribbler#RIGHT,obs_threshold) or scribbler.obstacle(scribbler#LEFT,obs_threshold)
clear_row(TEST_ROW_0)
clear_row(TEST_ROW_1)
print_str(TEST_COL_START,TEST_ROW_0,string("** Fail - False Detect on Carpet"))
return FALSE
print_dec(constant(TEST_COL_START + 7),TEST_ROW_1, time/10)
sio.tx(" ")
scribbler.delay_tenths(1)
clear_row(TEST_ROW_0)
clear_row(TEST_ROW_1)
print_str(TEST_COL_START,TEST_ROW_0,string("Place the scribbler on Obstacle Range Printout"))
repeat position from "A" to "E"
scribbler.set_leds(scribbler#OFF,scribbler#OFF,scribbler#OFF,scribbler#OFF)
detect_cnt := IR_DETECT_NUM
clear_row(TEST_ROW_1)
print_str(TEST_COL_START,TEST_ROW_1,string("Place Pipe at Postion: "))
sio.tx(position)
print_str(TEST_COL_START,TEST_ROW_3,string("Press the Button to Continue."))
button_wait(1)
clear_row(TEST_ROW_3)
repeat until detect_cnt == 0
if position == "A" or position == "B"
if scribbler.obstacle(scribbler#LEFT,obs_threshold)
detect_cnt -= 1
scribbler.set_led(scribbler#LEFT,scribbler#GREEN)
music.play_note(music#EGTH,music#C4,0)
scribbler.delay_tenths(3)
else
detect_cnt := IR_DETECT_NUM
scribbler.set_led(scribbler#LEFT,scribbler#RED)
elseif position == "C"
if scribbler.obstacle(scribbler#LEFT,obs_threshold)
music.play_note(music#EGTH,music#C4,0)
scribbler.set_led(scribbler#LEFT,scribbler#GREEN)
scribbler.delay_tenths(3)
if scribbler.obstacle(scribbler#RIGHT,obs_threshold)
music.play_note(music#EGTH,music#E4,0)
scribbler.set_led(scribbler#RIGHT,scribbler#GREEN)
detect_cnt -= 1
scribbler.delay_tenths(3)
else
detect_cnt := IR_DETECT_NUM/2
scribbler.set_led(scribbler#RIGHT,scribbler#RED)
else
detect_cnt := IR_DETECT_NUM/2
scribbler.set_led(scribbler#LEFT,scribbler#RED)
if scribbler.obstacle(scribbler#RIGHT,obs_threshold)
music.play_note(music#EGTH,music#E4,0)
scribbler.set_led(scribbler#RIGHT,scribbler#GREEN)
scribbler.delay_tenths(3)
else
scribbler.set_led(scribbler#RIGHT,scribbler#RED)
else
if scribbler.obstacle(scribbler#RIGHT,obs_threshold)
scribbler.set_led(scribbler#RIGHT,scribbler#GREEN)
detect_cnt -= 1