Skip to content

armgit / flix

Public Imported from GitHub
0

Making an ESP32-based quadcopter from scratch

Keep only one floating point version of map function Two variants are redundant

Oleg Kalachev1a017ccb9715
diff --git a/flix/motors.ino b/flix/motors.ino
index 8574551..6b2af65 100644
--- a/flix/motors.ino
+++ b/flix/motors.ino
@@ -38,9 +38,9 @@ void setupMotors() {
int getDutyCycle(float value) {
value = constrain(value, 0, 1);
- float pwm = mapff(value, 0, 1, PWM_MIN, PWM_MAX);
+ float pwm = mapf(value, 0, 1, PWM_MIN, PWM_MAX);
if (value == 0) pwm = PWM_STOP;
- float duty = mapff(pwm, 0, 1000000 / PWM_FREQUENCY, 0, (1 << PWM_RESOLUTION) - 1);
+ float duty = mapf(pwm, 0, 1000000 / PWM_FREQUENCY, 0, (1 << PWM_RESOLUTION) - 1);
return round(duty);
}
diff --git a/flix/util.h b/flix/util.h
index d6ac26d..21c416a 100644
--- a/flix/util.h
+++ b/flix/util.h
@@ -12,11 +12,7 @@
const float ONE_G = 9.80665;
extern float t;
-float mapf(long x, long in_min, long in_max, float out_min, float out_max) {
- return (float)(x - in_min) * (out_max - out_min) / (float)(in_max - in_min) + out_min;
-}
-
-float mapff(float x, float in_min, float in_max, float out_min, float out_max) {
+float mapf(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}