Using a Time-Of-Flight LIDAR Sensor
mcuoneclipse.com
mcuoneclipse.com
static const struct {
unsigned address;
unsigned value;
} inits[] = {
{ 0x207, 0x01 },
{ 0x208, 0x01 },
{ 0x096, 0x00 },
...
};
for (size_t i = 0; i < ARRAYSIZE(init_writes); ++i) {
uint8_t res = VL_WriteReg8(i2cDeviceAddress,
inits[i].address,
inits[i].value);
if (res != ERR_OK) {
VL_OnError(VL_ON_ERROR_INIT_DEVICE);
return res;
}
}
return ERR_OK;I approach this issue in 3 different ways: #define what those series of addresses and values mean, have a function that calls each one semantically, or a function that wraps all of them (what OP is doing).
I was going to show an example specific to this, but unfortunately ST did a poor job this time documenting this specific init sequence. If you look at those application notes linked in the tutorial, they just state they are mandatory private registers, which is disheartening. Looking at the example code that ST provides with their Nucleo boards for the evaluation kit of this module, it doesn't shed much more light, except that it seems to be something to do with ranging, tuning, and up-scaling of the data. They have two functions VL6180x_RangeStaticInit() and VL6180x_UpscaleRegInit() that call this sequence, depending on if up-scaling was defined.
Software for Nucleo Board for the VL6180X: http://www.st.com/content/st_com/en/products/embedded-softwa...
At this point, if I was actually working with this part, I would contact a ST rep and ask them what is up, because it seems weird they are forcing you to write to "private" registers.
If you look at the OP's code, you will see that he does wrap this series of code with VL_InitDevice(), and since ST does not have it documented any better than "These settings should be applied in this order with no substitutions", this is what you get. Doing what is suggested, I don't think really gets you much further, imo, but does condense your code, for what it is worth.
[1] Classic is the uP resets and re-runs the init code on I2C bus peripherals that have already been configured.
This situation is crying out for either exception handling, or Go's "errors are values" pattern. (https://blog.golang.org/errors-are-values)
Interestingly, I'd argue this is actually a great argument for brittleness in this case. The table oriented code makes it clear to the reader that no such subtle edge cases exist, improving the readability of the code.
Although a local macro or better error handling system would also make such things a bit clearer too.
As an occasional embedded systems programmer, initialization code without subtle edge cases only exists in artificial examples like this one.
https://www.sparkfun.com/products/12784 - Is the little board I used, and used a logic level converter.
I attached a little polystyrene circle to the top of the hydrometer, for the IR to bounce off.
Unfortunately the approach didn't work too well because of yeast krausen pushing the hydrometer about.
[1] http://www.blog.pyoung.net/2015/01/28/ds18b20-crc-check-code...
[1] http://www.st.com/content/ccc/resource/technical/document/da...
There's nothing like the range, 180 deg scanning speed, and general industrial robustness of the SICK LIDARs.
Then again, these chips aren't the size of a small coffee maker, and don't weigh a ton, either.
I think these devices will occupy a nice niche for when you want something with a better resolution than either the Sharp IR sensors or some ultrasonic pinger - but don't mind the limited range.
https://github.com/pololu/vl53l0x-arduino https://github.com/pololu/vl6180x-arduino
I've been playing around with the VL53L0X.
http://i.imgur.com/KFezaqU.jpg http://i.imgur.com/YM5KLRw.jpg
The "accuracy" you mention is really what they call "Range Resolution", which is more a measure of precision than accuracy. The range (as well as this resolution) is determined by the modulation frequency of the device, which I presume is the setting you switch to change modes.
> I wonder where such short range measurements with such a low accuracy are useful.
Another commenter mentioned autonomous vehicles (small vaccum robot), however I think outside of that use case there's really not much. Honestly for most things at that kind of range, I'd probably prefer to use a PMD camera like the Pico Flexx [1][2]. It's a lot more expensive, but you get a much better range, higher frame rate, and takes full images instead of just a single range in front of whatever it is you're building. Granted the range is 0.1-4m because the modulation frequency is fixed, but for most applications where you want autonomous ranging I can't see this being too much of a problem.
[1] http://pmdtec.com/picoflexx/downloads/PMD_RD_Brief_CB_pico_f... [2] http://pmdtec.com/picoflexx/
A VR headset?
Tesla's model X gull wing doors?