Go to Post Reading the directions is as important as reading the manual. - the man [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 24-01-2010, 17:10
FRC4ME FRC4ME is offline
Registered User
FRC #0339
 
Join Date: Feb 2008
Rookie Year: 2007
Location: Fredericksburg, VA
Posts: 324
FRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant future
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.
__________________
Go directly to queue. Do not pass pit.
Reply With Quote
  #2   Spotlight this post!  
Unread 25-01-2010, 03:21
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: Java PWM getPosition() integer division bug?

Quote:
Originally Posted by FRC4ME View Post
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
Reply With Quote
  #3   Spotlight this post!  
Unread 28-01-2010, 23:16
FRC4ME FRC4ME is offline
Registered User
FRC #0339
 
Join Date: Feb 2008
Rookie Year: 2007
Location: Fredericksburg, VA
Posts: 324
FRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant futureFRC4ME has a brilliant future
Re: Java PWM getPosition() integer division bug?

Quote:
Originally Posted by jhersh View Post
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
__________________
Go directly to queue. Do not pass pit.
Reply With Quote
  #4   Spotlight this post!  
Unread 29-01-2010, 00:56
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
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.
Reply With Quote
  #5   Spotlight this post!  
Unread 03-03-2010, 14:31
greekgod8591 greekgod8591 is offline
Registered User
FRC #2577
 
Join Date: Feb 2009
Location: New Jersey
Posts: 7
greekgod8591 is an unknown quantity at this point
Re: Java PWM getPosition() integer division bug?

We've observed the same issue, hopefully first will put out a fix for this.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
**FIRST EMAIL**/Java and Orbit Balls *****JAVA DISCUSSION*** Pjohn1959 Programming 37 31-08-2009 15:55
Using Integer variables programmr Programming 4 14-02-2009 17:26
Displaying a 16 bit integer on PIC 16F877? Ian Curtis Programming 4 20-06-2008 15:42
integer division ImmortalAres Programming 5 11-07-2005 21:19
Integer Number powercat Programming 2 18-02-2003 11:26


All times are GMT -5. The time now is 22:43.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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