Creating a SpaceX Crew Dragon simulator autopilot in Clojure

Creating a SpaceX Crew Dragon simulator autopilot in Clojure

In preparation for the SpaceX Crew Dragon’s first crewed mission Demo-2 in late May, SpaceX released a pretty cool little WebGL docking simulator, featuring the Dragon spacecraft. After getting the docking done successfully a few times, I realised this is a perfect opportunity to write a docking autopilot! How does one even approach a problem like this?

In preparation for the SpaceX Crew Dragon’s first crewed mission Demo-2 in late May, SpaceX released a pretty cool little WebGL docking simulator, featuring the Dragon spacecraft. After getting the docking done successfully a few times, I realised this is a perfect opportunity to write a docking autopilot! How does one even approach a problem like this?

An orbital spacecraft is a bit different from what you would consider a normal vehicle, like a car or an airplane. In space, you have all 6 Degrees of Freedom (DoF), meaning you can go up-down, left-right, roll clockwise-anti-clockwise etc.

Image for post

That is great, but how do we actually dock?

In the context of the simulator, a successful docking means that:

  • We are perfectly aligned with the docking port on the ISS
  • Our final approach rate on contact is below a certain value
  • We don’t want to crash our multi-million dollar spaceship into anything along the way

If you break it down, the problem simply consists of aligning the Dragon how it should be (aligned with the ISS docking port), and flying it to where it should be (at the docking port) slowly.

For the language, I am using Clojure, a Lisp-like *functional programming *language that runs on the JVM. It is highly extensible, simple, with lots of libraries and powerful concurrency abstractions, which we will absolutely need later.

The first step is to obviously figure out how to *control *the simulator. The best way to drive the browser these days is using WebDriver, and some API or client library to send commands to and from it. On our side, all we have to do is create a control interface in our code. In the entire project I am using Etaoin, which is a fantastic pure Clojure implementation of the WebDriver protocol.

clojure dragon automation functional-programming spacex

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Functional Programming

Functional Programming: Functional Programming is a Declarative style of Programming Paradigm for writing computer programs.

Are functions from programming really functions?

Are functions from programming really functions? If you are reading this, then most probably you already know quite well what functions are in programming.

Functional Programming Concepts

Part 1 — Functional Programming Journey.What does it mean to program in a functional way? Well, code written that way is based on, yes you guessed it, functions…these functions are tiny chunks of code that do something specific with the data that was passed to them. And in comparison with the object-oriented programming paradigm, these functions can be passed as arguments to other functions, which will receive them, execute them, perform some other computations and then either return some value or may this function is passed as an argument to another one.

Functional Programming: Higher Order Functions

Functional Programming: Higher Order Functions. A Better Take on JavaScript’s Higher Order Functions. Functional Programming is awesome! It makes programming fun.

Functional Programming Series (2): What Is a Monoid?

A monoid is fundamental to the functional programming world. For those interested in functional programming, I’ll talk about monoids and why they’re very important to understand ahead of time.