/
wmigor
/
z-plane
Обзор
Документация
Войти
/
wmigor
/
z-plane
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
editor/src/PropellerEditor.cpp
142 строки
5 KB
wmigor
Параметры элементов лопасти пропеллера
12 авг 2026, 10:40
12 авг 2026, 10:40
29c26ef
Код
Авторство
О чём код?
#include "PropellerEditor.h" #include "ui_PropellerEditor.h" #include <asim/Constants.h> #include <asim/PistonEngine.h> #include <asim/Propeller.h> PropellerEditor::PropellerEditor(): QWidget(), _ui(std::make_unique<Ui::PropellerEditor>()) { _ui->setupUi(this); _ui->rootPitch->setValue(27.0); _ui->tipPitch->setValue(12.0); _ui->pitchPower->setValue(2.0); _ui->radius->setValue(0.953); _ui->hubRadius->setValue(0.2); _ui->rootChord->setValue(0.102); _ui->tipChord->setValue(0.076); _ui->midChord->setValue(0.125); _ui->midFraction->setValue(0.35); _ui->roundness->setValue(2.0); _ui->bladeCount->setValue(2); connect(_ui->simulateButton, &QPushButton::clicked, this, &PropellerEditor::simulate); connect(_ui->rootPitch, &QDoubleSpinBox::valueChanged, this, &PropellerEditor::simulate); connect(_ui->tipPitch, &QDoubleSpinBox::valueChanged, this, &PropellerEditor::simulate); connect(_ui->pitchPower, &QDoubleSpinBox::valueChanged, this, &PropellerEditor::simulate); connect(_ui->radius, &QDoubleSpinBox::valueChanged, this, &PropellerEditor::simulate); connect(_ui->hubRadius, &QDoubleSpinBox::valueChanged, this, &PropellerEditor::simulate); connect(_ui->rootChord, &QDoubleSpinBox::valueChanged, this, &PropellerEditor::simulate); connect(_ui->tipChord, &QDoubleSpinBox::valueChanged, this, &PropellerEditor::simulate); connect(_ui->midChord, &QDoubleSpinBox::valueChanged, this, &PropellerEditor::simulate); connect(_ui->midFraction, &QDoubleSpinBox::valueChanged, this, &PropellerEditor::simulate); connect(_ui->roundness, &QDoubleSpinBox::valueChanged, this, &PropellerEditor::simulate); connect(_ui->bladeCount, &QSpinBox::valueChanged, this, &PropellerEditor::simulate); simulate(); } PropellerEditor::~PropellerEditor() = default; void PropellerEditor::simulate() { _ui->output->setText(""); simulateWithParams(0.0, 1.0); simulateWithParams(210.0 / 3.6, 0.75); } std::vector<asim::Propeller::Element> buildPropellerElements( unsigned int count, double radius, double rootChord, double midChord, double tipChord, double midFraction, double roundness, double hubRadius, double rootPitch, double tipPitch, double pitchPower) { auto bladeLength = radius - hubRadius; auto elementLength = bladeLength / count; std::vector<asim::Propeller::Element> elements; elements.resize(count); for (auto i = 0; i < count; i++) { auto &element = elements[i]; element.radius = hubRadius + i * elementLength + elementLength * 0.5; auto fraction = (element.radius - hubRadius) / bladeLength; element.chord = fraction < midFraction ? glm::mix(rootChord, midChord, 1.0 - glm::pow(1.0 - fraction / midFraction, roundness)) : glm::mix(midChord, tipChord, glm::pow((fraction - midFraction) / (1.0 - midFraction), roundness)); element.length = elementLength; element.pitch = glm::mix(rootPitch, tipPitch, glm::pow(fraction, pitchPower)); } return elements; } void PropellerEditor::simulateWithParams(double velocity, double throttle) { asim::Propeller::Config propellerConfig(std::make_shared<asim::Airfoil>()); propellerConfig.airfoil = std::make_shared<asim::Airfoil>(); propellerConfig.airfoil->baseSettings.zeroLiftAngle = glm::radians(-5.25); propellerConfig.airfoil->baseSettings.dragMin = 0.01; propellerConfig.airfoil->baseSettings.liftSlope = 5.1; auto rootPitch = glm::radians(_ui->rootPitch->value()); auto tipPitch = glm::radians(_ui->tipPitch->value()); auto pitchPower = _ui->pitchPower->value(); propellerConfig.radius = _ui->radius->value(); auto hubRadius = _ui->hubRadius->value(); auto rootChord = _ui->rootChord->value(); auto tipChord = _ui->tipChord->value(); auto midChord = _ui->midChord->value(); auto midFraction = _ui->midFraction->value(); auto roundness = _ui->roundness->value(); propellerConfig.bladeCount = _ui->bladeCount->value(); auto engine = new asim::PistonEngine(160.0 * asim::Constants::HP_TO_W, 2700.0 / asim::Constants::TO_RPM); auto elements = buildPropellerElements( 10, propellerConfig.radius, rootChord, midChord, tipChord, midFraction, roundness, hubRadius, rootPitch, tipPitch, propellerConfig.bladeCount); auto propeller = std::make_unique<asim::Propeller>(propellerConfig, elements, engine); auto density = 1.2255; auto delta = 1.0 / 60.0; asim::Wrench wrench; asim::Input input; input.throttle = throttle; for (auto i = 0; i < 1000; i++) { auto angularVelocity = engine->angularVelocity; wrench = propeller->calculate(delta, input, asim::Constants::Forward * velocity, asim::Constants::Zero, asim::Constants::Zero, density); if (glm::abs(angularVelocity - engine->angularVelocity) < 0.01) break; } auto thrust = glm::dot(wrench.force, asim::Constants::Forward); auto output = QString("%1velocity: %2 km/h\nthrottle: %3 %\nRPM: %4\nThrust: %5\nPower: %6\n\n") .arg(_ui->output->toPlainText()) .arg(velocity * 3.6) .arg(throttle * 100.0) .arg((int) (engine->angularVelocity * asim::Constants::TO_RPM)) .arg(thrust) .arg((int) ((engine->torque * propeller->getAngularVelocity()) / asim::Constants::HP_TO_W)); _ui->output->setText(output); }