“Dealing with physical units in modern C++”

by Nikola Jelić

Abstract

Since almost all embedded devices interact with the physical world, the reoccurring problem is how to deal with the various values from the physical world. One sensor may measure the current in milliamperes, while another may measure it in microamperes. There are also different measurement systems, such as metric and imperial (e.g. gallons and litres, metres and yards, etc.), but there are also units that overlap with others (e.g. litres and metres cubed, Kelvin and Celsius). Even worse, we must ensure that all arithmetic operations with physical values must be valid (e.g. we can’t add Volts and Kelvins, but we can multiply them). Thankfully, modern C++ offers a lot of built-in language functionalities to make this job easy, transparent and surprisingly optimal in the run time.

This work was motivated by a past project where many subtle bugs were caused by inconsistent treatment of measured values.

You will learn:
– How can we use SI system of units for our benefit
– What are the typical requirements and constraints on the real embedded projects concerning the physical units
– Which features from modern C++ are useful for this job
– What’s the difference between absolute and relative values
– How to write your own implementation
– How to make the refactored code readable and succinct

About the speaker

Nikola JelićNikola Jelić, Embedded Software Architect in Zuehlke from 2016.

Graduated in Computer Science at Faculty of Mathematics in Belgrade, Serbia. 11+ years of embedded development experience mostly focused on Linux, C++ and real-time systems. I prefer functional paradigm to all others, but I’m pragmatic about it.

Slides

View the slides for this presentation here…

Video