Go to Post Remember, however, that such software limitations in no way approximate the functionality of a multiple-speed, mechanical transmission. They're simply a convenient way of limiting your students' lead feet. - Madison [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


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 09:26.

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