Rangefinder

Rangefinder:

.

PIC_RangefinderEnable(); PIC_RangefinderEnable(); //enables the rangefinder to measure range every 20ms. This is the most common way to enable the rangefinder. Call this function at least one time before starting to read the rangefinder. This function can be called one time in your setup() function at the top of your sketch. This function is the same as calling PIC_RangefinderAutoInterval(1); .

PIC_RangefinderDisable(); PIC_RangefinderDisable(); //disables the rangefinder, stops auto-measurements This is the most common way to disable the rangefinder. This function is the same as calling PIC_RangefinderAutoInterval(0); .

PIC_RangefinderAutoInterval(); PIC_RangefinderAutoInterval(n); //Starts rangefinder making range measurement every n'th 20ms PIC cycle. Example: PIC_RangefinderAutoInterval(3); //Starts rangefinder making range measurement every 3rd 20ms PIC cycle.

Starts rangefinder to automatically make a range measurement every n'th 20ms PIC cycles. Setting the interval to 0 will disable the rangefinder.

.

PIC_ReadRangefinder(); PIC_ReadRangefinder(); //returns range in mm from last auto range reading. Populates the following global variables: rangeFinder, rangeGoodCounts This function is the most common way to read the rangefinder. You must call PIC_RangefinderEnable() at least once before this function will return good data. The global variable rangeFinder holds the range value in mm. Returned results will be between 0 and 1000.

The rangefinder needs to be nearly perpendicular to the surface being measured to get a good result (the rangefinder works by sending sound pings, which will bounce off in a different direction from surfaces at an angle). Each time the PIC measures a reading it considers to be good and reliable, the value of rangeGoodCounts will increase by 1. It will increase to a maximum of 250 (good range measurements can still be made, but rangeGoodCounts won't increase any further). Each time the PIC measures a reading it considers to be bad, out of range, or not reliable, rangeGoodCounts will go back to zero. In most cases, the range measurement rangeFinder will also go back to zero.

When reading the rangefinder, evaluate the resulting value. If the value is zero it can be assumed that a good reliable measurement hasn't been made. This can happen because the rangefinder is at too great an angle of the object or surface being measured, or if the range is extremely small (holding an object within 20mm of the rangefinder), or the object is over 1000mm away from the rangefinder. To determine the value is good and reliable, you may also evaluate if rangeGoodCounts is above a threshold you may choose.

.

Last updated