@@ -85,9 +85,6 @@ static int32_t s3_readBarWidth();
8585s3 S3 ;
8686s3 * self ;
8787
88- // Serial : "FullDuplexSerial"
89- // ServoDriver : "Servo32v7"
90- // ---[Start of Program]---------------------------------------------------------
9188void s3_setup ()
9289{
9390 self = & S3 ;
@@ -103,17 +100,6 @@ void s3_setup()
103100 _waitcnt ((CNT + 10000000 ));
104101}
105102
106- /*
107- Pub SerialStart(BaudRate)
108-
109- Serial.Start(31, 30, 0, BaudRate)
110- waitcnt(80_000_000 + cnt)
111- */
112- /*
113- Pub ServoStart
114-
115- ServoDriver.Start
116- */
117103static void s3_obstacler ()
118104{
119105 int32_t side , ObstacleThld ;
@@ -376,37 +362,38 @@ int32_t s3_readObstacle(int32_t Side)
376362int32_t s3_simpleObstacle (int32_t Condition , int32_t Location )
377363{
378364 int32_t result = 0 ;
365+ char obsL , obsR ;
366+
379367 if ((Condition == S3_IS ) || (Condition == S3_IS_NOT )) {
380- self -> WasObs [S3_LEFT ] = self -> obs [S3_LEFT ];
381- self -> WasObs [S3_RIGHT ] = self -> obs [S3_RIGHT ];
382- }
383- if ((Condition == S3_IS ) || (Condition == S3_WAS )) {
384- result = -1 ;
385- }
368+ obsL = self -> obs [S3_LEFT ];
369+ obsR = self -> obs [S3_RIGHT ];
370+
371+ self -> WasObs [S3_LEFT ] = obsL ;
372+ self -> WasObs [S3_RIGHT ] = obsR ;
373+
374+ } else if ((Condition == S3_WAS ) || (Condition == S3_WAS_NOT )) {
375+ obsL = self -> WasObs [S3_LEFT ];
376+ obsR = self -> WasObs [S3_RIGHT ];
377+ }
378+
386379 switch (Location ) {
387- case S3_CENTER :
388- if ((self -> WasObs [S3_LEFT ]) && (self -> WasObs [S3_RIGHT ])) {
389- return result ;
390- }
391- break ;
392- case S3_LEFT :
393- if ((self -> WasObs [S3_LEFT ]) && (!(self -> WasObs [S3_RIGHT ]))) {
394- return result ;
395- }
396- break ;
397- case S3_RIGHT :
398- if ((!(self -> WasObs [S3_LEFT ])) && (self -> WasObs [S3_RIGHT ])) {
399- return result ;
400- }
401- break ;
402- case S3_DETECTED :
403- if ((self -> WasObs [S3_LEFT ]) || (self -> WasObs [S3_RIGHT ])) {
404- return result ;
405- }
406- break ;
380+ case S3_CENTER :
381+ if (obsL && obsR ) result = 1 ;
382+ break ;
383+ case S3_LEFT :
384+ if (obsL && !obsR ) result = 1 ;
385+ break ;
386+ case S3_RIGHT :
387+ if (obsR && !obsL ) result = 1 ;
388+ break ;
389+ case S3_DETECTED :
390+ if (obsL || obsR ) result = 1 ;
391+ break ;
407392 }
408- !(result );
409- return result ;
393+
394+ if ((Condition == S3_WAS_NOT ) || (Condition == S3_IS_NOT )) result = !result ;
395+
396+ return result ;
410397}
411398
412399int32_t s3_lineSensor (int32_t Side )
@@ -429,39 +416,37 @@ int32_t s3_simpleLine(int32_t Condition, int32_t Location, int32_t Color)
429416 self -> WasLine [S3_LEFT ] = scribbler_line_sensor (S3_LEFT , (-1 ));
430417 self -> WasLine [S3_RIGHT ] = scribbler_line_sensor (S3_RIGHT , (-1 ));
431418 }
432- if ((Condition == S3_IS ) || (Condition == S3_WAS )) {
433- result = -1 ;
434- }
435419 if ((abs ((self -> WasLine [S3_LEFT ] - self -> WasLine [S3_RIGHT ]))) < 30 ) {
436420 // Low difference, not on an edge
437421 if ((self -> WasLine [S3_LEFT ] + self -> WasLine [S3_RIGHT ]) < 60 ) {
438422 // Average reading is dark
439423 if ((Color == S3_BLACK ) && ((Location == S3_CENTER ) || (Location == S3_DETECTED ))) {
440- return result ;
424+ result = 1 ;
441425 }
442426 } else {
443427 if ((Color == S3_WHITE ) && ((Location == S3_CENTER ) || (Location == S3_DETECTED ))) {
444428 // Average reading is light
445- return result ;
429+ result = 1 ;
446430 }
447431 }
448432 } else {
449433 // Over an edge
450434 if (Location == S3_DETECTED ) {
451- return result ;
435+ result = 1 ;
452436 } else {
453437 if ((self -> WasLine [S3_LEFT ] > self -> WasLine [S3_RIGHT ]) && (((Location == S3_LEFT ) && (Color == S3_BLACK )) || ((Location == S3_RIGHT ) && (Color == S3_WHITE )))) {
454438 // Left is brighter
455- return result ;
439+ result = 1 ;
456440 } else {
457441 if ((self -> WasLine [S3_RIGHT ] > self -> WasLine [S3_LEFT ]) && (((Location == S3_LEFT ) && (Color == S3_WHITE )) || ((Location == S3_RIGHT ) && (Color == S3_BLACK )))) {
458442 // Right is brighter
459- return result ;
443+ result = 1 ;
460444 }
461445 }
462446 }
463447 }
464- !(result );
448+ if ((Condition == S3_IS_NOT ) || (Condition == S3_WAS_NOT )) result = !result ;
449+
465450 return result ;
466451}
467452
@@ -481,31 +466,29 @@ int32_t s3_simpleLight(int32_t Condition, int32_t Location)
481466 self -> WasLight [S3_RIGHT ] = scribbler_light_sensor (S3_RIGHT );
482467 self -> WasLight [S3_CENTER ] = scribbler_light_sensor (S3_CENTER );
483468 }
484- if ((Condition == S3_IS ) || (Condition == S3_WAS )) {
485- result = -1 ;
486- }
487469 if (((self -> WasLight [S3_LEFT ] > (self -> WasLight [S3_RIGHT ] + 50 )) && (self -> WasLight [S3_LEFT ] > (self -> WasLight [S3_CENTER ] + 50 ))) || ((self -> WasLight [S3_LEFT ] > ((self -> WasLight [S3_RIGHT ] * 3 ) / 2 )) && (self -> WasLight [S3_LEFT ] > ((self -> WasLight [S3_CENTER ] * 3 ) / 2 )))) {
488470 if (Location == S3_LEFT ) {
489- return result ;
471+ result = 1 ;
490472 }
491473 } else {
492474 if (((self -> WasLight [S3_RIGHT ] > (self -> WasLight [S3_LEFT ] + 50 )) && (self -> WasLight [S3_RIGHT ] > (self -> WasLight [S3_CENTER ] + 50 ))) || ((self -> WasLight [S3_RIGHT ] > ((self -> WasLight [S3_LEFT ] * 3 ) / 2 )) && (self -> WasLight [S3_RIGHT ] > ((self -> WasLight [S3_CENTER ] * 3 ) / 2 )))) {
493475 if (Location == S3_RIGHT ) {
494- return result ;
476+ result = 1 ;
495477 }
496478 } else {
497479 if (((self -> WasLight [S3_CENTER ] > (self -> WasLight [S3_LEFT ] + 50 )) && (self -> WasLight [S3_CENTER ] > (self -> WasLight [S3_RIGHT ] + 50 ))) || ((self -> WasLight [S3_CENTER ] > ((self -> WasLight [S3_LEFT ] * 3 ) / 2 )) && (self -> WasLight [S3_CENTER ] > ((self -> WasLight [S3_RIGHT ] * 3 ) / 2 )))) {
498480 if (Location == S3_CENTER ) {
499- return result ;
481+ result = 1 ;
500482 }
501483 } else {
502484 if ((Location == S3_DETECTED ) && (((self -> WasLight [S3_LEFT ] + self -> WasLight [S3_CENTER ]) + self -> WasLight [S3_RIGHT ]) > 50 )) {
503- return result ;
485+ result = 1 ;
504486 }
505487 }
506488 }
507489 }
508- !(result );
490+ if ((Condition == S3_IS_NOT ) || (Condition == S3_WAS_NOT )) result = !result ;
491+
509492 return result ;
510493}
511494
@@ -646,38 +629,6 @@ int32_t s3_runWithoutResult(int32_t input)
646629 return input ;
647630}
648631
649- /*
650- Pub SerialStr(StringPointer)
651-
652- Serial.Str(StringPointer)
653-
654-
655- Pub SerialDec(Number)
656-
657- Serial.Dec(Number)
658-
659-
660- Pub SerialChar(Character)
661-
662- Serial.Tx(Character)
663-
664-
665- Pub SerialPositionX(Position)
666-
667- Serial.Tx(PX)
668- Serial.Tx(Position)
669-
670-
671- Pub SerialPositionY(Position)
672-
673- Serial.Tx(PY)
674- Serial.Tx(Position)
675-
676-
677- Pub SerialCharIn
678-
679- return Serial.RxCheck
680- */
681632int32_t s3_ping (int32_t Pin )
682633{
683634 int32_t MaxLoops , StartCnt , EndCnt ;
@@ -712,19 +663,4 @@ int32_t s3_ping(int32_t Pin)
712663 return 0 ;
713664 }
714665 return result ;
715- }
716-
717- /*
718- Pub Servo(Pin, Angle)
719-
720- ifnot 0 =< Pin and Pin =< 5
721- return 0
722-
723- Angle := (0 #> Angle <# 180) * 2_000 / 180 + 500
724- ServoDriver.Set(Pin, Angle)
725-
726-
727- Pub ServoStop(Pin)
728-
729- ServoDriver.Set(Pin, 0)
730- */
666+ }
0 commit comments