Using libdc to power my arduino dive computer project
scm007 opened this issue · 4 comments
I'm wondering if people have used libdc as the algorithm backend for a dive computer? I have an arduino box reading live depth measurements and I want a robust library to take those depth measurements and instruct me with regards to deco stops, safety stops, etc.
You mean the deco code from subsurface, not libdc. Libdc itself does no deco calculations, only reports what the dive computer says.
So what you'd need to look at is src/deco.c in the subsurface project, not in the libdc downloader code.
And it sounds interesting, but the code is really not written for that, and while people compare it to real dive computers, it's not seriously validated.
Also, I think at least the traditional arduinos are bad at floating point - not just that they are slow, but a "double" is actually the same as a float (ie 32-bit, not higher precision), so the code that subsurface is actually using ahs all been tested with much higher precision. It could easily make a difference.
Most real dive computers historically do things in fixed-point because the hardware is fairly weak, and that would be even more of a conversion thing.
End result: it sounds doable, but the math validation would need some major checking.
@scm007: I fully agree with what Linus said above - including that at this stage Subsurface is not suitable as a base to build your own dive computer.
But to give you another avenue to investigate, there is a family of dive computers on the market that uses open source firmware, they are made by Heinrichs Weikamp, and the source to their firmware is freely available, including one version written in C: https://code.heinrichsweikamp.com/public/ostc4/
This code is already written for STM32F4, which is also supported by Arduino, so this might work for you, possibly requiring a change of hardware. Note that STM32F4 hardware supports 32 bit floats, so the issue of having to contend with running algorithms on integers (incurring a plethora of scaling and rounding issues) is elegantly avoided here.
I still feel that I need to re-iterate Linus' statement about validation: I am not sure what your training level is, and how much the risks of incomplete or missed decompression, and the potential for injury, permanent disability, or even death resulting from it was covered. But it is definitely a complete NO-NO to make dives based solely on software that has not been validated in its entirety - even if the algorithm it uses was copy - pasted from a source that was validated as a whole. So always use a commercial off the shelf dive computer as the computer controlling your dive, and only carry your own creation to validate its output against the output of the other dive computer!
I'd love to see someone using and adapting subsurface deco code to some embedded platform for real time deco calculations.
On the topic of the code might contain bugs, sure, all code does. The subject of decompression contains enough uncertainty factors to begin with, so even perfect math is just a mathematical approximation of a not completely understood process, so there's risks in it no matter your validations.
On that topic, my guesstimate is that subsurface deco code is one of the more cross compared ones, because its compared to all supported divecomputer manufacturers calculations and I'm not aware of any cases where they diverge too much from other implementations.
So i'd say go for it, but treat it as for it is, a home built prototype to play with, and don't use it without a solid backup plan, as I'd do for any divecomputer. Pre-calculated tables in your wetnotes and a bottom timer is a good MVP for a backup plan.
I've had enough commercial dive computers fail on me during dives so I dive with two different ones nowadays with another one in bottom timer mode as third backup in a pocket.
Thanks guys. I will report back if I get it running on an embedded device.
Out of curiosity how much format verification do the commercial dive computer companies actually do? Is there some sort of governing body that assures some level of verification of their code bases?
Thanks for the link to the other project as well!