-
Notifications
You must be signed in to change notification settings - Fork 0
/
esc_calibration.ino
99 lines (84 loc) · 3 KB
/
esc_calibration.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
// ---------------------------------------------------------------------------
#include <Servo.h>
// ---------------------------------------------------------------------------
// Customize here pulse lengths as needed
#define MIN_PULSE_LENGTH 1000 // Minimum pulse length in µs
#define MAX_PULSE_LENGTH 2000 // Maximum pulse length in µs
// ---------------------------------------------------------------------------
Servo motA, motB, motC, motD;
char data;
// ---------------------------------------------------------------------------
/**
* Initialisation routine
*/
void setup() {
Serial.begin(9600);
motA.attach(4, MIN_PULSE_LENGTH, MAX_PULSE_LENGTH);
motB.attach(5, MIN_PULSE_LENGTH, MAX_PULSE_LENGTH);
motC.attach(6, MIN_PULSE_LENGTH, MAX_PULSE_LENGTH);
motD.attach(7, MIN_PULSE_LENGTH, MAX_PULSE_LENGTH);
displayInstructions();
}
/**
* Main function
*/
void loop() {
if (Serial.available()) {
data = Serial.read();
switch (data) {
// 0
case 48 : Serial.println("Sending minimum throttle");
motA.writeMicroseconds(MIN_PULSE_LENGTH);
motB.writeMicroseconds(MIN_PULSE_LENGTH);
motC.writeMicroseconds(MIN_PULSE_LENGTH);
motD.writeMicroseconds(MIN_PULSE_LENGTH);
break;
// 1
case 49 : Serial.println("Sending maximum throttle");
motA.writeMicroseconds(MAX_PULSE_LENGTH);
motB.writeMicroseconds(MAX_PULSE_LENGTH);
motC.writeMicroseconds(MAX_PULSE_LENGTH);
motD.writeMicroseconds(MAX_PULSE_LENGTH);
break;
// 2
case 50 : Serial.print("Running test in 3");
delay(1000);
Serial.print(" 2");
delay(1000);
Serial.println(" 1...");
delay(1000);
test();
break;
}
}
}
/**
* Test function: send min throttle to max throttle to each ESC.
*/
void test()
{
for (int i = MIN_PULSE_LENGTH; i <= MAX_PULSE_LENGTH; i += 5) {
Serial.print("Pulse length = ");
Serial.println(i);
motA.writeMicroseconds(i);
motB.writeMicroseconds(i);
motC.writeMicroseconds(i);
motD.writeMicroseconds(i);
delay(200);
}
Serial.println("STOP");
motA.writeMicroseconds(MIN_PULSE_LENGTH);
motB.writeMicroseconds(MIN_PULSE_LENGTH);
motC.writeMicroseconds(MIN_PULSE_LENGTH);
motD.writeMicroseconds(MIN_PULSE_LENGTH);
}
/**
* Displays instructions to user
*/
void displayInstructions()
{
Serial.println("READY - PLEASE SEND INSTRUCTIONS AS FOLLOWING :");
Serial.println("\t0 : Send min throttle");
Serial.println("\t1 : Send max throttle");
Serial.println("\t2 : Run test function\n");
}