|
|
@@ -1,5 +1,5 @@
|
|
|
char outputStr[100];
|
|
|
-int16_t averages[2][AVG_PERIODS];
|
|
|
+int16_t averages[AVG_PERIODS];
|
|
|
|
|
|
void loop() {
|
|
|
#ifdef SCAN_MODE
|
|
|
@@ -10,6 +10,9 @@ void loop() {
|
|
|
}
|
|
|
Serial.println();
|
|
|
#else
|
|
|
+ debugln();
|
|
|
+ debugln("===================");
|
|
|
+
|
|
|
int throttle = getThrottle();
|
|
|
throttle = restrictThrottlePower(throttle);
|
|
|
throttle = getAverage(throttle);
|
|
|
@@ -29,21 +32,15 @@ const int throtDeadHigh = THROT_NONE + THROT_DEAD_ZONE,
|
|
|
|
|
|
int getThrottle() {
|
|
|
int val = channelVals[THROT_CHANNEL];
|
|
|
-#ifndef GRAPH
|
|
|
- Serial.println();
|
|
|
- Serial.print("Channel value: ");
|
|
|
- Serial.print(val);
|
|
|
- Serial.print("\t");
|
|
|
-#endif
|
|
|
+
|
|
|
+ debug("Channel value: ");
|
|
|
+ debug(val);
|
|
|
+ debug("\t");
|
|
|
if(val <= THROT_OFF) {
|
|
|
-#ifndef GRAPH
|
|
|
- Serial.println("Throttle is off");
|
|
|
-#endif
|
|
|
+ debugln("Throttle is off");
|
|
|
return 0;
|
|
|
} else if(val < throtDeadHigh && val > throtDeadLow) {
|
|
|
-#ifndef GRAPH
|
|
|
- Serial.println("Throttle in dead zone");
|
|
|
-#endif
|
|
|
+ debugln("Throttle in dead zone");
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -53,10 +50,9 @@ int getThrottle() {
|
|
|
: map(val, THROT_NONE, THROT_MAX, 0, OUTPUT_RANGE);
|
|
|
|
|
|
throttle = constrain(throttle, -OUTPUT_RANGE, OUTPUT_RANGE);
|
|
|
-#ifndef GRAPH
|
|
|
- Serial.print("Throttle: ");
|
|
|
- Serial.println(throttle);
|
|
|
-#endif
|
|
|
+
|
|
|
+ debugln("Throttle: ", throttle);
|
|
|
+
|
|
|
return throttle;
|
|
|
}
|
|
|
|
|
|
@@ -64,10 +60,7 @@ int restrictThrottlePower(int throttle) {
|
|
|
// Reduce the average voltage to something safe for the motor to consume.
|
|
|
throttle = (throttle * MAX_POWER_PERCENT) / 100;
|
|
|
|
|
|
-#ifndef GRAPH
|
|
|
- Serial.print("Restricted throttle:\t");
|
|
|
- Serial.println(throttle);
|
|
|
-#endif
|
|
|
+ debugln("Restricted throttle:\t", throttle);
|
|
|
|
|
|
// Use the current value of the knob to reduce the speed.
|
|
|
int speedKnob = channelVals[SPEED_CHANNEL];
|
|
|
@@ -75,12 +68,8 @@ int restrictThrottlePower(int throttle) {
|
|
|
speedKnob = constrain(speedKnob, 0, 100);
|
|
|
throttle = (throttle * speedKnob) / 100;
|
|
|
|
|
|
-#ifndef GRAPH
|
|
|
- Serial.print("Speed knob:\t");
|
|
|
- Serial.println(speedKnob);
|
|
|
- Serial.print("Speed adjusted throttle:\t");
|
|
|
- Serial.println(throttle);
|
|
|
-#endif
|
|
|
+ debugln("Speed knob:\t", speedKnob);
|
|
|
+ debugln("Speed adjusted throttle:\t", throttle);
|
|
|
|
|
|
return throttle;
|
|
|
}
|
|
|
@@ -94,10 +83,7 @@ int getAverage(const int throttle) {
|
|
|
averages[AVG_PERIODS-1] = throttle;
|
|
|
total /= AVG_PERIODS;
|
|
|
|
|
|
-#ifndef GRAPH
|
|
|
- Serial.print("Average adjusted throttle:\t");
|
|
|
- Serial.println(total);
|
|
|
-#endif
|
|
|
+ debugln("Average adjusted throttle:\t", total);
|
|
|
|
|
|
return total;
|
|
|
}
|