Unit issue in RangeFinderAdapter and EV3IRSensor

A place to discus the development of leJOS for the EV3. Please do not use this section to post questions about how to use leJOS or to report problems etc.
Guiz
New User
Posts: 3
Joined: Sat May 07, 2016 6:33 am

Unit issue in RangeFinderAdapter and EV3IRSensor

Postby Guiz » Sat May 07, 2016 7:48 am

Hi Dev Team,

I'm using a RotatingRangeScanner in my code with the EV3 IR sensor.
Since release 0.9.1 the rotating range scanner is no more working. The RangeReadings are all set to -1

The issue come from the RangeFinderAdapter that have been changed to return centimeter.

Code: Select all

   public float getRange() {
         fetchSample(buf,0);
         return buf[0] * 100;
      }


But the class EV3IRSensor already return samples in centimeter and the adaptor gives a range of 1000 when real range is 10 centimeters

Then when calling RotatingRangeScanner.getRangeValues() it check the range that can not exceed MAX_RELIABLE_RANGE_READING = 180 and return -1

I have wrote my own adapter for the IR sensor to fix this issue but maybe the EV3IRSensor class should be fixed to return distance in meter.

I hope it will help

User avatar
gloomyandy
leJOS Team Member
Posts: 6047
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Unit issue in RangeFinderAdapter and EV3IRSensor

Postby gloomyandy » Sat May 07, 2016 9:19 am

Hi,
thanks for the feedback on this. Actually the readings returned by the EV3IRSensor are not in cm they are actually in an arbitrary unit that varies with the distance returned. You can test this be setting up a series of measurements with the target at a short distance from the sensor and then moving it say 10cm at a time away from the sensor and plotting the results. You will not get a nice straight line. We couldn't decide what to do about this so in the end just return the "device" units.

If all your new adapter does is to change the scale of the sensor reading from (approx) cm to (approx) m then you should be able to use a sensor filter to do this. However at the moment I'm not totally sure which one is the best to use. I'll ask Aswin to take a look at this thread and comment.

Also I'm not convinced about the code in the RotatingRangeScanner class it seems to be making a number of assumptions about the underlying sensor that may not be true. It assumes that the max range is 180cm (not true if you user a laser for instance) and it also seems to assume an offset of 2cm (not true for many sensors). It also has a 50mS delay built in after rotating the sensor which may or may not be needed.
leJOS news https://lejosnews.wordpress.com/

Aswin
leJOS Team Member
Posts: 312
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands
Contact:

Re: Unit issue in RangeFinderAdapter and EV3IRSensor

Postby Aswin » Sat May 07, 2016 10:16 am

Hi Guiz,

The origin of your problem is that the IR sensor returns values that are in the same range as centimeters. They are however not centimeters. In leJOS EV3 we started using SI units, that is meters for length and distance. As the IR sensor returns something, but not centimeters, we did not bother to correct this. This we think is the users responsibility.
The RangeFinderAdapter provides backwards compatibility for use with the RangeFinder class. The RangeFinder class was developed in the NXT days when we didn't have strict rules for units. The RangeFinder was developed with the NXT US sensor and assumed centimeters.
So, what is happening is that in your setup the adapter is converting something that is comparable to centimeters from meters to centimeters.

The easiest solution for you would be to copy and alter the adapter class, that will give you something close to centimeters.

You could also try to use the LinearCalibrationFilter to get more precise values. This filter can correct for scale and offset. To calibrate take the following steps.
1. Make two markings at different distance to a wall. Make sure these two markings are within the range of the sensor.
2. You then specify the distance of these two markers to the filter for calibration using the setScaleCalibration(float lBound, float uBound) method. lBound is the distance between the wall and the marker that is closest to it. uBound is the distance between the wall and other marker. Make sure you use meters as the unit. You then instruct the filter to use both scale and offset calibration using setCalibrationType(LinearCalibrationFilter.OFFSET_AND_SCALE_CALIBRATION).
3. Position the robot on one of the markers
4. Start the calibration process using startCalibration
5. wait a bit
6. Position the robot on the other marker.
7. wait a bit.
8. end the calibration process.
If you want to you can store the calibration parameters on the file system using save() method, the can then be used later on using the open() method.

Aswin
My NXT blog: http://nxttime.wordpress.com/

Guiz
New User
Posts: 3
Joined: Sat May 07, 2016 6:33 am

Re: Unit issue in RangeFinderAdapter and EV3IRSensor

Postby Guiz » Sat May 07, 2016 3:52 pm

Thanks Gloomyandy and Aswin for your answers.

LinearCalibrationFilter class do the job.

And thanks for your great work on the leJOS API.


Return to “leJOS EV3 Development”

Who is online

Users browsing this forum: No registered users and 1 guest