Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Java PWM getPosition() integer division bug? (http://www.chiefdelphi.com/forums/showthread.php?t=81045)

FRC4ME 24-01-2010 17:10

Java PWM getPosition() integer division bug?
 
After much troubleshooting trying to figure out why Servo.get() was returning 0.0 for any servo position other than 1.0, I noticed the following code in edu.wpi.first.wpilibj.PWM:

Code:

public double getPosition() {
    int value = getRaw();
    if (value < getMinNegativePwm()) {
        return 0.0;
    } else if (value > getMaxPositivePwm()) {
        return 1.0;
    } else {
        return (value - getMinNegativePwm()) / getFullRangeScaleFactor();
    }
}

Notice the final return statement. value, getMinNegativePwm(), and getFullRangeScaleFactor() are all of type int. Would this not cause the integer division to truncate to 0 for any result less than 1? I checked the C++ version of the same function, and sure enough, the numerator and denominator of the fraction are cast to float before the division.

jhersh 25-01-2010 03:21

Re: Java PWM getPosition() integer division bug?
 
Quote:

Originally Posted by FRC4ME (Post 906063)
After much troubleshooting trying to figure out why Servo.get() was returning 0.0 for any servo position other than 1.0, I noticed the following code in edu.wpi.first.wpilibj.PWM:

Code:

public double getPosition() {
    int value = getRaw();
    if (value < getMinNegativePwm()) {
        return 0.0;
    } else if (value > getMaxPositivePwm()) {
        return 1.0;
    } else {
        return (value - getMinNegativePwm()) / getFullRangeScaleFactor();
    }
}

Notice the final return statement. value, getMinNegativePwm(), and getFullRangeScaleFactor() are all of type int. Would this not cause the integer division to truncate to 0 for any result less than 1? I checked the C++ version of the same function, and sure enough, the numerator and denominator of the fraction are cast to float before the division.

Please post a bug report at: http://firstforge.wpi.edu/sf/tracker...ilib_java_bugs

Thanks,
-Joe

FRC4ME 28-01-2010 23:16

Re: Java PWM getPosition() integer division bug?
 
Quote:

Originally Posted by jhersh (Post 906364)
Please post a bug report at: http://firstforge.wpi.edu/sf/tracker...ilib_java_bugs

Thanks,
-Joe

I posted the bug report. Did I do everything correctly? Am I supposed to assign the bug to anyone in particular?

http://firstforge.wpi.edu/sf/go/artf...2647385673 24

jhersh 29-01-2010 00:56

Re: Java PWM getPosition() integer division bug?
 
Looks good to me. The right person isn't in the list. :( I'll make sure he hears about it.

greekgod8591 03-03-2010 14:31

Re: Java PWM getPosition() integer division bug?
 
We've observed the same issue, hopefully first will put out a fix for this.


All times are GMT -5. The time now is 09:26.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi