This commit is contained in:
Oleg Kalachev 2023-05-26 16:24:19 +03:00
parent c1aa0d9869
commit 88cc792287
3 changed files with 1 additions and 47 deletions

View File

@ -88,45 +88,3 @@ void sendMotors()
ledcWrite(2, pwmToDutyCycle(getPWM(motors[2], 2))); ledcWrite(2, pwmToDutyCycle(getPWM(motors[2], 2)));
ledcWrite(3, pwmToDutyCycle(getPWM(motors[3], 3))); ledcWrite(3, pwmToDutyCycle(getPWM(motors[3], 3)));
} }
// =====================
const uint32_t REVERSE_PAUSE = 0.1 * 1000000;
static uint8_t lastMotorDirection[4];
static uint32_t lastDirectionChange[4];
static void handleReversePause()
{
for (int i = 0; i < 4; i++) {
if (abs(sign(motors[i]) - lastMotorDirection[i]) > 1) { // 0 => 1 is not direction change, -1 => 1 is
lastDirectionChange[i] = stepTime;
}
if (stepTime - lastDirectionChange[i] < REVERSE_PAUSE) {
// wait before changing direction
motors[i] = 0;
}
lastMotorDirection[i] = sign(motors[i]);
}
}
// =====================
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
float motorThrust[1][10] = {
{0,0.5513626834,0.5387840671,0.6498951782,0.7023060797,0.7610062893,0.8679245283,1,0.9937106918,0.9916142558}
};
uint16_t minPwm = 1500;
uint16_t pwmStep = 100;
static float thrustToMotorInput(uint8_t n, float thrust)
{
for (int i = 0; i < ARRAY_SIZE(motorThrust[n]); i++) {
if (thrust <= motorThrust[n][i]) {
// TODO: pwm
return mapff(thrust, 0, 1, motorThrust[n][i-1], motorThrust[n][i]);
}
}
return 1;
}

View File

@ -7,14 +7,12 @@
#pragma once #pragma once
#include <iostream>
#include <cmath> #include <cmath>
#include <string> #include <string>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <sys/poll.h> #include <sys/poll.h>
using std::cout;
using std::max; using std::max;
using std::min; using std::min;
using std::isfinite; using std::isfinite;

View File

@ -34,8 +34,6 @@ static void controlManual();
static void controlRate(); static void controlRate();
void desaturate(float& a, float& b, float& c, float& d); void desaturate(float& a, float& b, float& c, float& d);
static void indicateSaturation(); static void indicateSaturation();
// cli
static void showTable(); static void showTable();
static void cliTestMotor(uint8_t n); static void cliTestMotor(uint8_t n);
@ -45,4 +43,4 @@ void calibrateGyro() { printf("Skip gyro calibrating\n"); };
void calibrateAccel() { printf("Skip accel calibrating\n"); }; void calibrateAccel() { printf("Skip accel calibrating\n"); };
void fullMotorTest(int n) {}; void fullMotorTest(int n) {};
void sendMotors() {}; void sendMotors() {};
void printIMUCal() { Serial.print("cal: N/A\n"); }; void printIMUCal() { printf("cal: N/A\n"); };