File tree 1 file changed +17
-2
lines changed 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change 2
2
3
3
#define SENSOR_DELAY 10
4
4
5
+ #define MAX_QUIRKS 3
6
+
5
7
#define ENA_PIN 10
6
8
#define ENB_PIN 9
7
9
#define IN1_PIN 2
@@ -41,6 +43,9 @@ int prd;
41
43
int pld;
42
44
char pdir;
43
45
46
+ // quirk counter - triggers "circuir breaker" on reaching MAX_QUIRKS
47
+ int qc = 0 ;
48
+
44
49
void setup () {
45
50
#ifdef DEBUG
46
51
Serial.begin (9600 );
@@ -98,9 +103,19 @@ int lDist() {
98
103
}
99
104
100
105
char chooseDirection (int cdist, int rdist, int ldist) {
101
- // below "0" is a sensor quirk: continue with previously chosen direction in this case
106
+ // below or equal "0" is a sensor quirk ...
102
107
if ((cdist <= 0 ) or (rdist <= 0 ) or (ldist <= 0 )) {
103
- return pdir;
108
+ // ... continue with previously chosen direction before reaching MAX_QUIRKS
109
+ if (qc < MAX_QUIRKS) {
110
+ qc++;
111
+ return pdir;
112
+ }
113
+ // ... pull back after reaching MAX_QUIRKS
114
+ qc = 0 ;
115
+ return _BCK;
116
+ } else {
117
+ // reset quirk counter if sensor quirk is not the case
118
+ qc = 0 ;
104
119
}
105
120
106
121
// we got stuck: spin left or right ...
You can’t perform that action at this time.
0 commit comments