FRC-Utilities / LibDS

Library for controling FRC robots
MIT License
38 stars 20 forks source link

Serious Problem with controller Axis call. #6

Closed RustyRaptor closed 6 years ago

RustyRaptor commented 6 years ago

This problem isn't present in the LabView driverstation. When I use a joystick it seems to not return any value until the joystick is pushed all the way to 1 or -1. I am guessing it's converting the float to an integer so you end up with 0 until you hit 1. I've tried multiple joysticks from different vendors.

Could this be the function causing it? I am not entirely certain how it works.

float DS_GetJoystickAxis (int joystick, int axis)
{
    if (CFG_GetRobotEnabled() && joystick_exists (joystick)) {
        DS_Joystick* stick = get_joystick (joystick);

        if (stick->num_axes > axis)
            return stick->axes [axis];
    }

    return 0;
}
alex-spataru commented 6 years ago

Thanks for the report. Do the joystick axes move correctly in the "joysticks" tab of the DS? This is to know if the problem is with SDL/QJoysticks or the LibDS protocol implementation.

RustyRaptor commented 6 years ago

They do seem to move correctly in the joysticks tab. speaking of which I tried using the virtual joystick and setting it's range to 99 and it didn't work.

jacksondm33 commented 6 years ago

Same problem here. I'll take a look to see if I can find the source of the problem.

alex-spataru commented 6 years ago

@jacksondm33 Thanks! Let me know if you have any questions about the source code of LibDS.

jacksondm33 commented 6 years ago
uint8_t DS_FloatToByte (const float value, const float max)
{
    if (value != 0 && max != 0 && value <= max) {
        int percent = (int) (value / max) * (0xFF / 2);
        return (uint8_t) (percent & 0xFF);
    }

    return 0;
}

The problem is here. When calculating the percent, it converts value / max to an integer before multiplying it by 0xFF / 2. Fixed in #9

RustyRaptor commented 6 years ago

Awesome. Thanks. Now we can stop having to put up with the monster known as labview DS :) . I wish they would legalize this station in competitions honestly.