To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 144
143  |  145
Subject: 
Rotation sensor bug found (maybe!)
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Sat, 17 Apr 1999 15:07:24 GMT
Viewed: 
1339 times
  
I think I might have found a bug in the ds_rotation_handler (direct-sensor.c).
The problem arises when the STATE_0_VALUE is checked using the IN_RANGE macro.
As STATE_0_VALUE is 1023U<<6, which is about the max value for an unsigned,
adding to it the RANGE_SIZE to test the upper bound gets an unwanted result.
The value would be over the max possible unsigned value and the result of the
addition is 40U<<6 - 1.

This is one of the points:

    case STATE_1:
     if ( IN_RANGE ( STATE_0_VALUE ) ) {           <-- bug in this line
       state=STATE_0;
       cooked--;
     } else if( IN_RANGE ( STATE_2_VALUE ) ) {
       state=STATE_2;
       cooked++;
     }
     break;


Second problem. I checked many values for my two rotation sensors, and as I
wrote yesterday they are different from the ones inside direct-sensor.c. In
some cases they are out of the range specified in legOS.

State Min value Max value   Avg    legOS value +/- range
  0    65470      65470    65470   1023<<6 +/- 40<<6 = 65472 +/- 2560
  1    54520      55230    54875    833<<6 +/- 40<<6 = 53312 +/- 2560
  2    27960      28860    28410    405<<6 +/- 40<<6 = 25920 +/- 2560 !!!
  3    41600      42560    42080    623<<6 +/- 40<<6 = 39872 +/- 2560 !!!

I didn't receive any comment about this problem up to now. Please somebody with
better knowledge of C and legOS confirm if I am right or wrong.

Thanks

Mario



Message has 1 Reply:
  Re: Rotation sensor bug found (maybe!)
 
(...) You've got a point here. What if we hardwire STATE_0_VALUE to the following? #define STATE_0_VALUE (ds_unscale(1023U)-RANGE_SIZE) Or, for a more general approach: #define MIN(a,b) (a<b?a:b) #define MAX(a,b) (a>b?a:b) #define STATE_VALUE(k) ( \ (...) (26 years ago, 17-Apr-99, to lugnet.robotics.rcx.legos)

10 Messages in This Thread:



Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR