An old truth in software development is to use tools of the proper level of abstraction for the task at hand. But all too often we find ourselves reaching for C or C++ even when absolute execution speed isn’t critically important. Developers end up dealing with issues like type conversion, memory management and implementing basic data structures without even knowing what benefit in speed the extra work brings.

I got the opportunity to look into the scripting language Lua for a client and I’m thrilled to see the great things this language offers. It’s a compact and flexible language that adds easy control over program flow and data structures. Calls and data sharing between C and Lua are fairly straight-forward. The platform-specific parts, heavy calculations and big data can stay in C or C++ to preserve performance while other components can enjoy replaceable code, garbage collection etc.

Lua is by no means an unknown language — it’s used as part in a great number of games and applications. For example, the photography suite Adobe Lightroom uses Lua to define the GUI, totalling a full 40% of the source code (source). Hit games World of Warcraft and Grand Theft Auto 4 use Lua. Although the standard distribution is very basic there are many plugins, for example Love 2D for creating games.

Maybe the biggest argument for a scripting language is the ability for third parties to change and adapt the program behavior without compiling code, creating native libraries or risking to compromise the system security. Both Lightroom and World of Warcraft use Lua for this.

Python is another scripting language that’s very popular for its ease of development and availability of libraries for almost any purpose. Indeed, I often use it myself and the whole Windsond PC application is written in Python. But binary size and memory footprint count in embedded systems and the lower demands of Lua make a big difference here. All Lua language features compiles to 182 KB with additional 244 KB needed for the standard libraries. When needed, Lua can allegedly be reduced to 100 KB with libraries. Standard Python is at least 1000 KB. Python-on-a-chip reimplements parts of Python to 55 KB program memory (flash) to potentially be a contender.

Lua also offers an alternative for for microcontroller projects, eLua. It adds direct access to many hardware features. It has support for some Cortex-M3 and AVR32 MCUs. The documentation is a bit fuzzy on the hardware requirements, but seem to be in the range of 100s of KB flash and down to 10 KB RAM.

Ground winds

Some data formats include a field for the ground wind speed and direction. At first glance, Windsond should be able to report this… but it can’t, since the wind is sensed by the balloon floating with the air movements (i.e. winds) as it rises. Before the balloon starts rising it’s anchored (typically by someone holding it…) and can’t measure winds.

But wait a moment, what exactly is meant by winds on the ground? Due to the physics of fluid mechanics, wind movement very near the ground will be much lower than expected, even approaching zero extremely close to the surface. The ground drag is felt up to 200-400m height, depending on the type of terrain. As it turns out, the standard is to measure ground wind at 10 meters height. Here’s another discussion, by Belfort Instrument. It takes Windsond several seconds to reach 10m height so the GPS has time to sense the change in speed and direction.

Still, the wind close to the ground is more turbulent than at altitude, so a single reading from Windsond cannot capture average conditions like a ground-based weather station can.

By the way, the GPS senses the movement by doppler effect. This is more accurate than calculating heading and distance between successive position reports — GPS position reports may experience sudden jumps and even at the best of times they have a degree of uncertainty that would severely limit the time resolution possible.

At the moment Windsond measures wind once a second and makes an average over the last three seconds when sending data to the ground station. A software extension could transmit all three values to the ground station. A future experiment is to measure five times a second and save this to on-board storage for downloading after the sounding finished.