Team2168 / 2015_Main_Robot

Source code for the 2015 season
2 stars 0 forks source link

AverageEncoder Rate returns NaN #55

Closed NotInControl closed 9 years ago

NotInControl commented 9 years ago

It looks like some changes were made to the WPILib encoder class which affects the average encoder rate returned. Sometimes the values will be NaN or infinity/ Right now, we have a work around in a new function called getRawRate() which should work as expected without creating NaN or infinity values, but we need to understand what changed in WPI, and why the original getRate function no longer works as expected.

Using getRawRate, bypasses any averaging at the moment. This discovery affects part of #35

jcorcoran commented 9 years ago

The getAverage() method is what's returning your values in most cases:

   private double getAverage() { 
         double sum = 0; 

         for (int i = 0; i < averagorSize; i++) 
             sum += averagorArray[i]; 

         return sum / averagorSize; 
     }

You're probably getting NaN if the averagorSize is zero. In this case you would have 0.0/0.0, which is arithmetically undefined. Hence NaN. I don't know how you're getting Infinity. I would think your denominator (averagorSize) would need to be zero and your numerator (sum) would need to be non-zero, but I don't see how this could be possible with the given code.