-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathisrcontroller.cpp
More file actions
45 lines (38 loc) · 1.23 KB
/
Copy pathisrcontroller.cpp
File metadata and controls
45 lines (38 loc) · 1.23 KB
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
#ifndef ISRCONTROLLER_CPP
#define ISRCONTROLLER_CPP
#include "isrcontroller.h"
#include "logger.h"
#define ISR_SERVO_DEBUG 2
ISRController::ISRController() {
using namespace config::thrusters;
Logger::debug(F("ISR init\n\r"));
SAMD_ISR_Servos.useTimer(TIMER_TCC);
m_pins[0] = thrusters::fr_lo_le;
m_pins[1] = thrusters::fr_lo_ri;
m_pins[2] = thrusters::fr_hi_le;
m_pins[3] = thrusters::fr_hi_ri;
m_pins[4] = thrusters::ba_lo_le;
m_pins[5] = thrusters::ba_lo_ri;
m_pins[6] = thrusters::ba_hi_le;
m_pins[7] = thrusters::ba_hi_ri;
for (int i = 0; i < 8; i++) {
m_isrServos[i] =
SAMD_ISR_Servos.setupServo(m_pins[i], pulse_min[i], pulse_max[i]);
}
SAMD_ISR_Servos.setReadyToRun();
for (int i = 0; i < 8; i++) {
SAMD_ISR_Servos.setPulseWidth(m_isrServos[i], pulse_med[i]);
}
}
void ISRController::setThruster(int idx, int power) {
int pulse = pulse_med[idx];
if (power < 0) {
pulse = map(power, -100, 0, pulse_min[idx], pulse_med[idx]);
}
if (power > 0) {
pulse = map(power, 0, 100, pulse_med[idx], pulse_max[idx]);
}
pulse = constrain(pulse, 1000, 2000);
SAMD_ISR_Servos.setPulseWidth(m_isrServos[idx], pulse);
}
#endif