-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotor.cpp
87 lines (74 loc) · 2.44 KB
/
motor.cpp
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
#include "motor.h"
static Servo mot0, mot1, mot2, mot3;
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");
}
void setup_motors() {
mot0.attach(PIN_MOTOR_0, MIN_PULSE_LENGTH, MAX_PULSE_LENGTH);
mot1.attach(PIN_MOTOR_1, MIN_PULSE_LENGTH, MAX_PULSE_LENGTH);
mot2.attach(PIN_MOTOR_2, MIN_PULSE_LENGTH, MAX_PULSE_LENGTH);
mot3.attach(PIN_MOTOR_3, MIN_PULSE_LENGTH, MAX_PULSE_LENGTH);
}
void calib_motors() {
displayInstructions();
if (Serial.available()) {
char data;
data = Serial.read();
switch (data) {
// 0
case 48:
Serial.println("Sending minimum throttle");
mot0.writeMicroseconds(MIN_PULSE_LENGTH);
mot1.writeMicroseconds(MIN_PULSE_LENGTH);
mot2.writeMicroseconds(MIN_PULSE_LENGTH);
mot3.writeMicroseconds(MIN_PULSE_LENGTH);
break;
// 1
case 49:
Serial.println("Sending maximum throttle");
mot0.writeMicroseconds(MAX_PULSE_LENGTH);
mot1.writeMicroseconds(MAX_PULSE_LENGTH);
mot2.writeMicroseconds(MAX_PULSE_LENGTH);
mot3.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);
for (int i = MIN_PULSE_LENGTH; i <= MAX_PULSE_LENGTH; i += 5) {
Serial.print("Pulse length = ");
Serial.println(i);
mot0.writeMicroseconds(i);
mot1.writeMicroseconds(i);
mot2.writeMicroseconds(i);
mot3.writeMicroseconds(i);
delay(200);
}
Serial.println("STOP");
mot0.writeMicroseconds(MIN_PULSE_LENGTH);
mot1.writeMicroseconds(MIN_PULSE_LENGTH);
mot2.writeMicroseconds(MIN_PULSE_LENGTH);
mot3.writeMicroseconds(MIN_PULSE_LENGTH);
break;
}
}
}
void arm_motors() {
mot0.writeMicroseconds(MIN_PULSE_LENGTH);
mot1.writeMicroseconds(MIN_PULSE_LENGTH);
mot2.writeMicroseconds(MIN_PULSE_LENGTH);
mot3.writeMicroseconds(MIN_PULSE_LENGTH);
}
void set_motor_values(int *mixer_output) {
mot0.writeMicroseconds(mixer_output[0]);
mot1.writeMicroseconds(mixer_output[1]);
mot2.writeMicroseconds(mixer_output[2]);
mot3.writeMicroseconds(mixer_output[3]);
}