Transfer fullMotorTest function to motors.ino

This commit is contained in:
Oleg Kalachev 2023-12-03 20:43:55 +03:00
parent 80ecba8337
commit 94b483cda6
4 changed files with 14 additions and 69 deletions

View File

@ -98,7 +98,7 @@ void doCommand(String& command, String& value)
} else if (command == "mrl") {
cliTestMotor(MOTOR_REAR_LEFT);
} else if (command == "fullmot") {
fullMotorTest(value.toInt());
fullMotorTest(value.toInt(), false);
} else {
float val = value.toFloat();
// TODO: on error returns 0, check invalid value

View File

@ -61,3 +61,15 @@ void sendMotors()
ledcWrite(2, pwmToDutyCycle(getPWM(motors[2], 2)));
ledcWrite(3, pwmToDutyCycle(getPWM(motors[3], 3)));
}
void fullMotorTest(int n, bool reverse)
{
printf("Full test for motor %d\n", n);
for (int pwm = PWM_NEUTRAL; pwm <= 2300 && pwm >= 700; pwm += reverse ? -100 : 100) {
printf("Motor %d: %d\n", n, pwm);
ledcWrite(n, pwmToDutyCycle(pwm));
delay(3000);
}
printf("Motor %d: %d\n", n, PWM_NEUTRAL);
ledcWrite(n, pwmToDutyCycle(PWM_NEUTRAL));
}

View File

@ -1,67 +0,0 @@
// Copyright (c) 2023 Oleg Kalachev <okalachev@gmail.com>
// Repository: https://github.com/okalachev/flix
void _pwm(int n, uint16_t pwm)
{
printf("Motor %d: %d\n", n, pwm);
ledcWrite(n, pwmToDutyCycle(pwm));
delay(5000);
}
void fullMotorTest(int n)
{
printf("> Full test for motor %d\n", n);
bool reverse = false;
if (reverse) {
// _pwm(n, 700);
// _pwm(n, 800);
// _pwm(n, 900);
// _pwm(n, 1000);
// _pwm(n, 1100);
// _pwm(n, 1200);
// _pwm(n, 1300);
// _pwm(n, 1400);
// _pwm(n, 1410);
// _pwm(n, 1420);
// _pwm(n, 1430);
// _pwm(n, 1440);
// _pwm(n, 1450);
// _pwm(n, 1460);
// _pwm(n, 1470);
// _pwm(n, 1480);
// _pwm(n, 1490);
}
_pwm(n, 1500);
// _pwm(n, 1510);
// _pwm(n, 1520);
// _pwm(n, 1530);
// _pwm(n, 1540);
// _pwm(n, 1550);
// _pwm(n, 1560);
// _pwm(n, 1570);
// _pwm(n, 1580);
// _pwm(n, 1590);
_pwm(n, 1600);
_pwm(n, 1700);
_pwm(n, 1800);
_pwm(n, 1900);
_pwm(n, 2000);
_pwm(n, 2100);
_pwm(n, 2200);
_pwm(n, 2300);
_pwm(n, 1500);
}
void fullMotorsTest()
{
printf("Perform full motors test\n");
motors[0] = 0;
motors[1] = 0;
motors[2] = 0;
motors[3] = 0;
fullMotorTest(0);
fullMotorTest(1);
fullMotorTest(2);
fullMotorTest(3);
}

View File

@ -45,6 +45,6 @@ void cliTestMotor(uint8_t n);
void setLED(bool on) {};
void calibrateGyro() { printf("Skip gyro calibrating\n"); };
void calibrateAccel() { printf("Skip accel calibrating\n"); };
void fullMotorTest(int n) {};
void fullMotorTest(int n, bool reverse) { printf("Skip full motor test\n"); };
void sendMotors() {};
void printIMUCal() { printf("cal: N/A\n"); };