This commit is contained in:
2024-03-09 09:38:21 +07:00
parent 4a85827150
commit 007a3fd16f
3 changed files with 13 additions and 21 deletions

View File

@@ -173,33 +173,24 @@ void FlightController::stopAllRotors() {
void FlightController::setHeightControllerParams(float p, float i, float d) { void FlightController::setHeightControllerParams(float p, float i, float d) {
if (_status == DeviceStatus::Idle) { if (_status == DeviceStatus::Idle) {
_heightController->Kp = p; _heightController->setParams({.p = p, .i = i, .d = d});
_heightController->Ki = i;
_heightController->Kd = d;
_heightController->save();
} }
} }
void FlightController::setYawControllerParams(float p, float i, float d) { void FlightController::setYawControllerParams(float p, float i, float d) {
if (_status == DeviceStatus::Idle) { if (_status == DeviceStatus::Idle) {
_yawController->Kp = p; _heightController->setParams({.p = p, .i = i, .d = d});
_yawController->Ki = i;
_yawController->Kd = d;
_heightController->save();
} }
} }
void FlightController::setPitchControllerParams(float p, float i, float d) { void FlightController::setPitchControllerParams(float p, float i, float d) {
if (_status == DeviceStatus::Idle) { if (_status == DeviceStatus::Idle) {
_tailRotorController->Kp = p; _heightController->setParams({.p = p, .i = i, .d = d});
_tailRotorController->Ki = i;
_tailRotorController->Kd = d;
_heightController->save();
} }
} }
PidSettings FlightController::pidSettings() const { PidSettings FlightController::pidSettings() const {
PidSettings settings; PidSettings settings{};
settings.flightController = {.p = _heightController->Kp, .i = _heightController->Ki, .d = _heightController->Kd}; settings.flightController = {.p = _heightController->Kp, .i = _heightController->Ki, .d = _heightController->Kd};
settings.yawController = {.p = _yawController->Kp, .i = _yawController->Ki, .d = _yawController->Kd}; settings.yawController = {.p = _yawController->Kp, .i = _yawController->Ki, .d = _yawController->Kd};
settings.pitchController = {.p = _tailRotorController->Kp, .i = _tailRotorController->Ki, .d = _tailRotorController->Kd}; settings.pitchController = {.p = _tailRotorController->Kp, .i = _tailRotorController->Ki, .d = _tailRotorController->Kd};

View File

@@ -26,13 +26,14 @@ public:
this->Kp = params.p; this->Kp = params.p;
this->Ki = params.i; this->Ki = params.i;
this->Kd = params.d; this->Kd = params.d;
save();
} }
std::shared_ptr<PidParams> getParams() { PidParams getParams() {
std::shared_ptr params = std::make_unique<PidParams>(); PidParams params{};
params->p = Kp; params.p = Kp;
params->i = Ki; params.i = Ki;
params->d = Kd; params.d = Kd;
return params; return params;
} }

View File

@@ -17,11 +17,11 @@ void setup() {
new MPU(new MPU6050(MPU6050_DEFAULT_ADDRESS, &i2c)), new MPU(new MPU6050(MPU6050_DEFAULT_ADDRESS, &i2c)),
new Kalman2DFilter(10.f, 1.f, 1.8f), new Kalman2DFilter(10.f, 1.f, 1.8f),
new BatteryController(BATTERY_DATA_PIN, BATTERY_DATA_SWITCH_PIN)), new BatteryController(BATTERY_DATA_PIN, BATTERY_DATA_SWITCH_PIN)),
new SavedPidRegulator(3.5f, 0.0015f, 0.01f, "HeightController"), // height new SavedPidRegulator(3.5f, 0.0015f, 0.01f, "HeightControl"), // height
new SavedPidRegulator(2.f, 12.f, 0.f, "YawController"), // yaw new SavedPidRegulator(2.f, 12.f, 0.f, "YawControl"), // yaw
new BrushedMotor(1, 2, 3, 4, 1), new BrushedMotor(1, 2, 3, 4, 1),
new BrushedMotor(1, 2, 3, 4, 1), new BrushedMotor(1, 2, 3, 4, 1),
new PIDController(0.6f, 3.5f, 0.03f, new BrushedMotor(1, 2, 3, 4, 3), "RollController"), // pitch new PIDController(0.6f, 3.5f, 0.03f, new BrushedMotor(1, 2, 3, 4, 3), "RollControl"), // pitch
true))); true)));
} }