Error fixes and base flight logic

This commit is contained in:
2024-04-03 20:38:44 +07:00
parent 47f91eeae5
commit 0cb666c860
13 changed files with 113 additions and 61 deletions

View File

@@ -14,8 +14,8 @@ public:
assert(rotor != nullptr);
_rotor = rotor;
_isEnabled = isEnabled;
this->_dt = dt;
setLimits(0, _rotor->maxDuty());
setLimits(-_rotor->maxDuty(), _rotor->maxDuty());
setDirection(REVERSE);
_pid_timer = millis();
ESP_LOGI(_tag, "PID %s initialized with params (%f, %f, %f)", name, Kp, Ki, Kd);
}
@@ -23,6 +23,7 @@ public:
void enable() {
_isEnabled = true;
_rotor->setDuty(0);
integral = 0;
}
void disable() {
@@ -30,10 +31,12 @@ public:
_rotor->setDuty(0);
}
void tick() {
if (millis() - _pid_timer >= _dt and _isEnabled) {
_rotor->setDuty((uint16_t) getResultTimer());
_pid_timer = millis();
void update() {
if (_isEnabled) {
//ESP_LOGI(_tag, "Setpoint: %f", setpoint);
//ESP_LOGI(_tag, "Input: %f", input);
//ESP_LOGI(_tag, "Output: %d", (int16_t) round(getResultNow()));
setRotorDuty((int16_t) round(getResultNow()));
}
}
@@ -43,7 +46,7 @@ public:
}
private:
uint16_t _dt;
//uint16_t _dt;
BrushedMotor *_rotor = nullptr;
uint32_t _pid_timer = 0;
bool _isEnabled = false;