mirror of
https://github.com/okalachev/flix.git
synced 2026-01-10 21:16:50 +00:00
Keep only one floating point version of map function
Two variants are redundant
This commit is contained in:
@@ -38,9 +38,9 @@ void setupMotors() {
|
|||||||
|
|
||||||
int getDutyCycle(float value) {
|
int getDutyCycle(float value) {
|
||||||
value = constrain(value, 0, 1);
|
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;
|
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);
|
return round(duty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,11 +12,7 @@
|
|||||||
const float ONE_G = 9.80665;
|
const float ONE_G = 9.80665;
|
||||||
extern float t;
|
extern float t;
|
||||||
|
|
||||||
float mapf(long x, long in_min, long 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 (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) {
|
|
||||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user