|
@@ -1,7 +1,12 @@
|
|
|
char outputStr[100];
|
|
char outputStr[100];
|
|
|
int16_t averages[AVG_PERIODS];
|
|
int16_t averages[AVG_PERIODS];
|
|
|
|
|
|
|
|
|
|
+const int throtDeadHigh = THROT_NONE + THROT_DEAD_ZONE,
|
|
|
|
|
+ throtDeadLow = THROT_NONE - THROT_DEAD_ZONE;
|
|
|
|
|
+
|
|
|
void loop() {
|
|
void loop() {
|
|
|
|
|
+ const long startTime = millis();
|
|
|
|
|
+
|
|
|
#ifdef SCAN_MODE
|
|
#ifdef SCAN_MODE
|
|
|
for(byte ch = LOW_CHANNEL; ch <= NUM_CHANNELS; ch++) {
|
|
for(byte ch = LOW_CHANNEL; ch <= NUM_CHANNELS; ch++) {
|
|
|
int val = channelVals[ch];
|
|
int val = channelVals[ch];
|
|
@@ -24,12 +29,10 @@ void loop() {
|
|
|
analogWrite(LEFT_MOTOR_PIN, throttle > 0 ? throttle : -throttle);
|
|
analogWrite(LEFT_MOTOR_PIN, throttle > 0 ? throttle : -throttle);
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
- delay(SCAN_DELAY);
|
|
|
|
|
|
|
+ const long now = millis();
|
|
|
|
|
+ delay(SCAN_DELAY + (startTime - now));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const int throtDeadHigh = THROT_NONE + THROT_DEAD_ZONE,
|
|
|
|
|
- throtDeadLow = THROT_NONE - THROT_DEAD_ZONE;
|
|
|
|
|
-
|
|
|
|
|
int getThrottle() {
|
|
int getThrottle() {
|
|
|
int val = channelVals[THROT_CHANNEL];
|
|
int val = channelVals[THROT_CHANNEL];
|
|
|
|
|
|
|
@@ -75,7 +78,7 @@ int restrictThrottlePower(int throttle) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int getAverage(const int throttle) {
|
|
int getAverage(const int throttle) {
|
|
|
- int total = throttle;
|
|
|
|
|
|
|
+ long long total = throttle;
|
|
|
for(byte i = 0; i < AVG_PERIODS-1; i++) {
|
|
for(byte i = 0; i < AVG_PERIODS-1; i++) {
|
|
|
total += averages[i];
|
|
total += averages[i];
|
|
|
averages[i] = averages[i+1];
|
|
averages[i] = averages[i+1];
|