Protocols servo throw limited to 100% ???

More
14 Nov 2017 08:41 - 14 Nov 2017 09:26 #65815 by vlad_vy
By the way, many protocols have servo throw limited to 100%:

static u16 convert_channel(u8 num)
{
    s32 ch = Channels[num];
    if (ch < CHAN_MIN_VALUE) {
        ch = CHAN_MIN_VALUE;
    } else if (ch > CHAN_MAX_VALUE) {
        ch = CHAN_MAX_VALUE;
    }
    return (u16) ((ch * 500 / CHAN_MAX_VALUE) + 1500);
}

I think CHAN_MIN_VALUE correspond to -100% and CHAN_MAX_VALUE correspond to +100%. Right calculation will be:

static u16 convert_channel(u8 num)
{
    s32 value = (s32)Channels[num] * (100%_value) / CHAN_MAX_VALUE + middle_value;
           if (value > +150%_value) //or +125%_value if it's the max for protocol
               value = +150%_value;
           else if (value < -150%_value) //or -125%_value if it's the max for protocol
               value = -150%_value;
    return (u16) value;
}

for above example it will be:
s32 value = (s32)Channels[num] * 400 / CHAN_MAX_VALUE + 1500;
with 100% scale it will be 1100 - 1500 - 1900,
with 125% scale it will be 1000 - 1500 - 2000,
with 150% scale it will be 900 - 1500 - 2100.
Last edit: 14 Nov 2017 09:26 by vlad_vy.

Please Log in or Create an account to join the conversation.

Time to create page: 0.029 seconds
Powered by Kunena Forum