-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservo_motor_controlls.ino
101 lines (72 loc) · 2.88 KB
/
servo_motor_controlls.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
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
void DCMotorZero() { // The function that turns off the motors. dcmotoZero() must go after ultrasonicCheck()
analogWrite(L_motors_speed, 0);
analogWrite(R_motors_speed, 0);
analogWrite(L1, 0);
analogWrite(L2, 0);
analogWrite(R1, 0);
analogWrite(R2, 0);
}
void goReverseShortDistance( int duration ) { // The function that makes us go in reverse for specified duration
analogWrite(L_motors_speed, 153); // 60, 100
analogWrite(R_motors_speed, 153);
analogWrite(L1, 0);
analogWrite(L2, 255);
analogWrite(R1, 255);
analogWrite(R2, 0);
delay(duration);
}
void goStraightShortDistance( int duration ) { // The function that makes us go straight for specified duration
analogWrite(L_motors_speed, 153); // 60, 100 // THESE COMMANDS MAKE ROBOT GO STRAIGHT
analogWrite(R_motors_speed, 153); // 153 // RIGHT HAS MORE TORQUE THAN LEFT
analogWrite(L1, 255); // 204
analogWrite(L2, 0);
analogWrite(R1, 0);
analogWrite(R2, 255); // 255 // 204
delay(duration);
}
void goStraightAfterObstacle( int duration ) { // The function that makes us go straight after turning away from obstacle
analogWrite(L_motors_speed, 220); // 51, 102
analogWrite(R_motors_speed, 220);
analogWrite(L1, 255); // 204
analogWrite(L2, 0);
analogWrite(R1, 0);
analogWrite(R2, 255); // 255 // 204
delay(duration);
}
void leftTurnTimed( int duration ) { // The function to make the robot turn left for specified duration
analogWrite(L_motors_speed, 220); // 120 // 204
analogWrite(R_motors_speed, 220); // 120
analogWrite(L1, 0); // 0
analogWrite(L2, 255); // 255
analogWrite(R1, 0); // 0
analogWrite(R2, 255); // 255
delay(duration); // 700
}
void rightTurnTimed( int duration ) { // The function to make the robot turn right for specified duration
analogWrite(L_motors_speed, 220); // 120 // 204
analogWrite(R_motors_speed, 220); // 120
analogWrite(L1, 255); // 255
analogWrite(L2, 0); // 0
analogWrite(R1, 255); // 255
analogWrite(R2, 0); // 0
delay(duration); // 800
}
void stopCar() { // The function that stops car for a long delay (100 seconds)
analogWrite(L_motors_speed, 0);
analogWrite(R_motors_speed, 0);
analogWrite(L1, 0); // 0
analogWrite(L2, 0); // 0
analogWrite(R1, 0); // 0
analogWrite(R2, 0); // 0
delay(100000); // Stop car for one hundred seconds
// WE ARE DONE IF WE REACH THIS POINT!!!
}
void stopCarTimed( int duration ) { // Stop the car for a specified duration. Useful for delays
analogWrite(L_motors_speed, 0);
analogWrite(R_motors_speed, 0);
analogWrite(L1, 0);
analogWrite(L2, 0);
analogWrite(R1, 0);
analogWrite(R2, 0);
delay(duration); // Stop car for amount of duration
}