Making an ESP32-based quadcopter from scratch
Python arduinoautopilotcontrol-theorydroneesp32flight-controlflight-controllermavlinkquadcopterquadcopter-firmwareuav
Simplify motors duty cycle computation
Oleg Kalachevca355e0162ff
diff --git a/flix/motors.ino b/flix/motors.inoindex 5b25f3f..7287aca 100644--- a/flix/motors.ino+++ b/flix/motors.ino@@ -26,14 +26,15 @@ void setupMotors() {Serial.println("Motors initialized");}-uint8_t signalToDutyCycle(float signal) {- float duty = mapff(signal, 0, 1, 0, (1 << PWM_RESOLUTION) - 1);- return round(constrain(duty, 0, (1 << PWM_RESOLUTION) - 1));+uint8_t getDutyCycle(float value) { // TODO: for canonical+ value = constrain(value, 0, 1);+ float duty = mapff(value, 0, 1, 0, (1 << PWM_RESOLUTION) - 1);+ return round(duty);}void sendMotors() {- ledcWrite(MOTOR_0_PIN, signalToDutyCycle(motors[0]));- ledcWrite(MOTOR_1_PIN, signalToDutyCycle(motors[1]));- ledcWrite(MOTOR_2_PIN, signalToDutyCycle(motors[2]));- ledcWrite(MOTOR_3_PIN, signalToDutyCycle(motors[3]));+ ledcWrite(MOTOR_0_PIN, getDutyCycle(motors[0]));+ ledcWrite(MOTOR_1_PIN, getDutyCycle(motors[1]));+ ledcWrite(MOTOR_2_PIN, getDutyCycle(motors[2]));+ ledcWrite(MOTOR_3_PIN, getDutyCycle(motors[3]));}