This year’s “Pi Day” (3/14) is approaching, so I crafted a way for an autopilot to participate…
Here’s less than 100 lines of Lua (3.1415kb) that will calculate Pi to 500 digits (499 decimal places) on a capable autopilot, output to the SD card as
pi.txt. Set SCR_HEAP_SIZE to 204800 or more to take full advantage of the implementation.
pi-day.lua (3.1 KB)
Initially, I thought it’d be fun to showcase the scripting environment with a script that would incrementally/iteratively calculate Pi during an auto mission, but the spigot algorithm I chose turned out to be a bit of a memory hog, so the resulting script just starts crunching numbers 5 seconds after boot time and then exits when complete. I didn’t want to risk someone experiencing an OS panic/crash while airborne!
I tested on a Matek H743-WLITE - the least fully featured, scripting enabled autopilot in my collection. Results were compared against those found here.
If someone can beat my 500 digits by an order of magnitude or more, I’d love to see the method. I’m sure it’s entirely possible!