Cosmic

C++20 engine for telemetry and simulation apps

I built Cosmic to run my own engineering software. It is a C++20 engine and editor for 2D apps on Windows, and it runs SF_Telem, the telemetry app for my combat robot.

Language
C++20
Graphics
OpenGL 4.5 core
Platform
Windows x64
Libraries
Dear ImGui, ImPlot, EnTT, Jolt, GLFW
Started
December 2025
Built with Cosmic

Apps that run on Cosmic

Two apps run on Cosmic today. SF_Telem is the one I use on real hardware. PendulumLab is the sample app I check against a known answer. More are planned, starting with to-9km-and-beyond.

Replay of a weapon test, paused just after the quick spin-up: the motor speed falls under load while the current climbs to its peak.
In use on the robot

SF_Telem

Live ESC telemetry and drivetrain analysis for my 30 lb combat robot, Shear Force.

  • 3 ESCs over one Bluetooth link
  • 60 Hz recording, replay at 0.1 to 10x
  • Drivetrain spin-up model and gearing tools
Sample app

PendulumLab

A damped pendulum simulation, integrated with RK4 at 240 Hz and checked against the analytic solution.

  • RK4 at a 1/240 s step
  • Within 1e-4 rad of the analytic solution over 10 s
  • Packaged as a standalone exe
Planned

to-9km-and-beyond

Trajectory animation and plots for my C++ subsonic airplane MDA tool. A test app with synthetic trajectory data already builds and packages against Cosmic; the real integration waits for real to-9km-and-beyond data.

Intent

Why I built it

I wanted an engine and renderer that helps my engineering projects and is not behind a paywall. I also think the best engine for a task is one built for that task. Unity and Unreal are far better for most work; they are not necessarily better for mine, which is live telemetry, test benches and simulations whose physics I write myself.

That split is deliberate. The engine is a tool: Cosmic takes care of the rendering and the boilerplate around it. The apps I build on it are mine, including their physics and engineering logic: SF_Telem's drivetrain model is a port of my command-line drivetrain calculator, and its weapon model is a port of my weapon speed spreadsheet. PendulumLab, below, is the engine's sample app rather than one of my projects; the apps I build next will follow the SF_Telem pattern.

Cosmic was mostly written with AI tools. I started it myself, writing the OpenGL graphics code and the application loop, and then AI tools took over most of the implementation and optimization while I set the direction and approved the high-level design decisions. It was also how I learned to work with AI tools and how an engine works at a high level: an application's run loop is close to a flight computer's main loop, and I wanted to understand how a computer turns data into pixels.

Case study

SF_Telem: telemetry and drivetrain analysis

SF_Telem is the app I built on Cosmic for Shear Force, my 30 lb combat robot. It has two halves: live telemetry from the robot's three ESCs, and the drivetrain analysis I use to choose wheels and pulleys.

Live telemetry

Replay of a weapon test, paused just after the quick spin-up: the motor speed falls under load while the current climbs to its peak.

I started SF_Telem to check my drivetrain calculations against real data. Copying numbers from the Arduino serial monitor by hand, and then a third-party serial plotter, was not reliable enough, so I wrote my own app on Cosmic.

The ESP32 reads each ESC's telemetry UART, checks every frame's CRC, decodes the fields and re-aligns the stream when bytes are lost. It sends each reading as a tagged text line with an XOR checksum over Bluetooth. SF_Telem checks the checksum and converts the fields to volts, amps, rpm and speed with motor and gearing constants I can edit while it runs, so a change needs no reflash.

  1. Weapon + 2 drive ESCsKISS telemetry frames, 115200 baud
  2. ESP32CRC check, decode, re-align
  3. Bluetooth SPPtagged lines + XOR checksum
  4. PC COM port
  5. SF_Telem on Cosmicchecksum, units, plots, recording

What it does

  • Live, zoomable plots for the weapon and each drive side.
  • Recording at 60 Hz to one CSV per ESC plus a binary file, with a 5 s rolling autosave. Replay at 0.1 to 10x, in reverse or scrubbed.
  • Test benches for one drive ESC, the weapon ESC or both drive ESCs, and a hex sniffer, each with a matching ESP32 sketch the app copies to the clipboard.
  • A simulator sketch that makes the ESP32 send made-up data for all three ESCs, so I can test the whole path without the robot.
  • A weapon spin-up model, ported from my weapon speed spreadsheet (aerodynamic drag from a quadratic fit to CFD data, the weapon's inertia from CAD), drawn as a predicted top-speed line on the live weapon rpm and tip-speed plots.
SF_Telem with the motors in view: a no-load motor test before the motors went in. Also on the Shear Force page.
The same run in one view: an early spin-up that stopped suddenly, then the full quick spin-up.
Replay of a no-load motor test, paused at the top of a right-drive spin-up.
The drive ESC test bench, waiting for telemetry. No ESC was connected for this capture.
The weapon ESC test bench, waiting for telemetry. No ESC was connected for this capture.

SF_Telem recorded the weapon ESC data behind the ESC root cause analysis on the Shear Force page.

Drivetrain analysis

SF_Telem's Analysis screen: my drivetrain spin-up model for the front and rear wheels, with the Simulation V2 tabs below. The curves and values are model predictions for the default inputs, not measurements.

The Analysis screen starts from my drivetrain spin-up model, a port of the drivetrain tool on the Shear Force page (Simulation V1). The motor's torque-speed line goes through the 19:1 gearbox and the belt pulleys to each wheel, is capped by traction, and is stepped forward in time into speed, acceleration, force and distance for the front (2.5 in) and rear (3.5 in) wheels. It flags a traction-limited launch. I compared its predictions with live telemetry during testing.

Around it are the Simulation V2 tools for changing the gearing when the axle heights are fixed: a lift planner that lists the whole-tooth pulley swaps that keep both wheels in sync for the same chassis lift, a same-pulley range, a feasibility check, a wheel-diameter sweep and a pulley-ratio table.

Case study

PendulumLab: simulation checked against theory

PendulumLab running in the editor: the angle plot, energy gauge and phase plot, all read from the data bus.

PendulumLab is the sample app for the Cosmic app workflow: a C++ service does the physics, the screens are made in the editor, and the data bus is the only link between them. A pendulum's small-angle motion has an analytic solution, so the integrator can be tested against it.

The service integrates the full nonlinear pendulum equation with fourth-order Runge-Kutta (RK4) at a fixed 1/240 s step. It publishes angle, angular velocity, energy and a period estimate; the Lab screen plots them, and a flow-graph rule opens a Stopped screen when the energy falls below 0.01. It packages to a standalone PendulumLab.exe.

Unit-test bars, L = 1 m, g = 9.80665 m/s², released from 5°.
CheckBar
Small-angle mode against the analytic solution, 10 swithin 1e-4 rad
Damping 0.05: energy over 10 snever increases; ends at 0.55 to 0.65 of the start (analytic 0.61)
Period estimate against 2π√(L/g)within 1 %
Two runs of the same casebit-identical
PendulumLab's phase plot: angle against angular velocity for a 5° swing.
Under the hood

How Cosmic works

Cosmic is a C++20 engine for 2D real-time apps on Windows, with an editor, Starforge, built on the same runtime. An app is a set of screens whose widgets (plots, gauges, readouts, sliders, buttons) are bound to a live data bus, a flow graph that decides which screen is shown, and C++ services that publish the numbers.

The engine and each app are built separately, so changing an app never rebuilds the engine. Simulations run on a fixed timestep: 60 Hz by default, adjustable from 1 to 1,000 Hz.

In Starforge I lay out screens, bind widgets to data bus channels, draw the flow graph, and jump from any widget to the C++ that feeds it. When I save a C++ file during a run, the editor rebuilds the app's DLL, swaps it in and resumes on the same screen with the data kept; a compile error stops the run and shows the error. File > Package makes a standalone folder with the app's own exe.

Starforge (editor)Lays out screens and the flow graph. On save during a run, it rebuilds the app DLL and swaps it in.
CosmicApp.exe (host)
App DLL: SF_Telem or PendulumLabC++ services publish numbers; screens show them; the flow graph picks the screen.
  • C++ services
  • Screens
  • Flow graph
Cosmic.dll (engine)Data bus (kept across a rebuild), 2D renderer, serial link, recorder and replay, fixed-step loop.
Laying out PendulumLab's Lab screen in Starforge with the rect gizmo.
After a C++ change was saved during a run: the editor rebuilt the app and resumed on the same screen.