Motor Mixing #2

I think I have a better way to mix motors that preserves both throttle and torque at the expense of dynamic range.

What it does is first compute the maximum dynamic range allowed from the current throttle and the min/max setting. If the throttle is close to min, the available dynamic range is small as to avoid going below min. Same when close to max.

The best dynamic range is when the throttle is in the middle.

Code is below:

void Motor_Mixer::update_mixing()
{
    math::vec3f speeds2d(-m_roll, m_pitch, 0.f);


    //first calculate the possible dynamic range from the throttle and min/max
    float dynamic_range = 0.f;
    {
        float min_v = math::max(m_throttle - m_min_output, 0.f);
        float max_v = math::max(m_max_output - m_throttle, 0.f);
        dynamic_range = math::min(max_v, min_v);
    }


    for (auto& motor: m_motors)
    {
        float output = math::dot(math::vec3f(motor.info.position, 0.f), speeds2d);
        if (motor.info.clockwise)
        {
            output += m_yaw;
        }
        else
        {
            output -= m_yaw;
        }
        output = math::clamp(output, -dynamic_range, dynamic_range) + math::max(m_throttle, m_min_output);
        motor.output = output;
        QASSERT(output >= m_min_output);
        QASSERT(output <= m_max_output);
    }
}

The only problem I can see with this is with full throttle. In this case the motors are at max and they usually have very different max thrust – so the UAV will tend to rotate one way or another. Since at max throttle I also have zero dynamic range I won’t be able to compensate the UAV rotation. I need to handle this case in a different way.

Maybe at max thrust (or over half thrust) I should favor dynamic range over preserving throttle… This way I get maximum maneuverability over raw climbing rate which is desirable…

For now I’ll just limit the max to 70-80% throttle to leave some dyn range for stability.

 

Advertisements

One thought on “Motor Mixing #2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s