samdrew / betaflight_gazebo

Plugins and models for vehicle simulation in Gazebo Sim with Betaflight and ArduPilot SITL controllers
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Motors Underpowered #2

Open samdrew opened 2 days ago

samdrew commented 2 days ago

The current settings and limits coming from the Betaflight FC are being interpreted such that even with the PWM output at full, the motors are still not spinning enough to enable flight.

samdrew commented 9 hours ago

Comparing the code from ardupilot_gazebo plugin to the code from aeroloop_gazebo (based on an earlier version of ardupilot), it is likely just the multiplier in ardupilot_gazebo that needs adjusting, although the exact parameters are unclear.

ardupilot_gazebo:src/ArduPilotPlugin:1634

                // convert pwm to raw cmd: [servo_min, servo_max] => [0, 1],
                // default is: [1000, 2000] => [0, 1]
                const double pwm = _pwm[this->dataPtr->controls[i].channel];
                const double pwm_min = this->dataPtr->controls[i].servo_min;
                const double pwm_max = this->dataPtr->controls[i].servo_max;
                const double multiplier = this->dataPtr->controls[i].multiplier;
                const double offset = this->dataPtr->controls[i].offset;

                // bound incoming cmd between 0 and 1
                double raw_cmd = (pwm - pwm_min)/(pwm_max - pwm_min);
                raw_cmd = gz::math::clamp(raw_cmd, 0.0, 1.0);
                this->dataPtr->controls[i].cmd =
                    multiplier * (raw_cmd + offset);

aeroloop_plugin:src/BetaflightPlugin:588

        if (i < MAX_MOTORS)
        {
            // std::cout << i << ": " << pkt.motorSpeed[i] << "\n";
            this->dataPtr->rotors[i].cmd = this->dataPtr->rotors[i].maxRpm *
                    pkt.motorSpeed[i];
        }

Where maxRpm is double maxRpm = 838.0