-
Notifications
You must be signed in to change notification settings - Fork 0
/
follow_me_mode.ino
43 lines (29 loc) · 899 Bytes
/
follow_me_mode.ino
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
/* Object Following Simple Alogarithm
* Juni Adi Juni Adi 06/29/2020
*/
int forwardDistance = 100; // maximum distance to follow (move forward)
int stopDistance = 30; // maximum distance to stop
int backwardDistance = 20; // maximum distance to backup (move backward)
void followMode(){
Serial.println("Follow");
int distance = readPing();
Serial.println(distance);
if(distance <= forwardDistance && distance > stopDistance){
rMotor.setSpeed(255);
lMotor.setSpeed(255);
rMotor.run(FORWARD);
lMotor.run(FORWARD);
}else if(stopDistance <= 30 && distance > backwardDistance){
//stop
mStop();
}else if(distance <= backwardDistance ){
rMotor.setSpeed(255);
lMotor.setSpeed(255);
rMotor.run(BACKWARD);
lMotor.run(BACKWARD);
}else{
//stop
rMotor.run(RELEASE);
lMotor.run(RELEASE);
}
}