I was wondering if I could get any help programming a Maxbotix XL-EZ4. (in C++) I did read through the API, and the spec sheets for the sensor but I’m still a little confused. So I know that the XL is approximately 4.9mv per inch. On the arduino which I tested the sensor, I could simply get the value of the sensor (1-1024) and that would be the cms.
This is a quote from the spec sheet:
Analog output of distance reading: (Vcc/1024) / cm (4.9 mV/cm when input voltage Vcc = 5 V)
The analog on the CRIO however is scaled to 10v instead of the 5v from the arduino, although the output from the analog sidecar is 5. I also don’t understand whether I should use the GetVoltage or GetValue, and I also don’t understand how I scale it. (And an explanation of how you came up with the numbers would be appreciated as I attempt to understand)
Sorry if this is a stupid question- it’s my first time using an analog sensor with the CRIO.
GetVoltage will return the input voltage. It’s scaled in the Analog Breakout, but I believe it’s unscaled in WPILib. If it isn’t the math to un scale yourself is easy since it’s a linear scale.
Once you have the unscaled voltage, just multiply your voltage by 0.0049 and you’ll have inches.
Thanks! That makes a lot of sense. However, the voltage is scaled in WPILib.
"Get a scaled sample straight from this channel on the module. The value is scaled to units of Volts using the calibrated scaling data from getLSBWeight() and getOffset(). "
That’s the part I don’t understand.
The “scaling” mentioned in the library is simply a conversion from raw A/D counts to volts. What you get out of GetVoltage() is the measured voltage on the pins.
That makes sense! So is get voltage in mv? Do you just times get voltage by .0049
Voltage * .0049 = distance in inches. That’s it.
The units in the spec sheet is 4.9 mv/cm To get cm, you would divide by .0049v/cm. You could then convert to inches if desired.