An attempt at fiddling together a distributed infrastructure similar to ROS
Ah, asdf does indeed have a local config option
It didn't seem to work and now it does.
HOKAY Physics can now send info about its bodies and ground to Foxglove.

heads

tip
browse log

clone

read-only
https://hg.sr.ht/~icefox/goatherd
read/write
ssh://hg@hg.sr.ht/~icefox/goatherd

#What is this

...For sheep are stupid, and have to be driven. But goats are intelligent, and need to be led.

-- Terry Pratchett

This is a toy system for playing around with autonomous drone/quadcopter simulations, using Elixir. Right now it is not intended to be used for real drones or to do anything fancy, but maybe someday that will change. It is mostly just a proof-of-concept for building robotics systems using Elixir and the Erlang VM.

#Usage

Easiest to just use asdf, for better or for worse.

source ~/.asdf/asdf.whatever
asdf plugin add erlang
asdf plugin add elixir
asdf plugin add elixir-ls
mix deps.get
iex -S mix

#Tools

  • Build system: mix (required for Nerves, which is worth it)
  • Unit tests: exunit or whatever
  • Linting/typing: dialyzer
  • Integration and deployment: It does not use Nerves yet, but if it ever gets to the point where it actually runs on a drone then it will be Nerves.
  • Math: Graphmath, which actually does pretty well with Erlang's JIT + type guards -- https://github.com/crertel/graphmath/issues/43
  • UI: Foxglove + Phoenix websockets -- https://kobrakai.de/kolumne/bare-websockets (Websockets is TCP will need a UDP system sooner or later)
  • Networking and distribution: Websockets and/or Distributed Erlang on reliable connections, TBD for unreliable connections; has to be UDP-based. QUIC? DDS? Something else?
  • Flight controller: Right now just a very simple simulator, if it becomes real it will use PX4 + mavlink
  • Logging and data recording: Elixir's Logger and Telemetry, will probably write a MCAP output for it so it can export stuff that Foxglove can read.
  • Geography and geodesy: GDAL? Probably not a concern yet.

Things this lib provides:

  • Core algorithms like PID control and Kalman filters
  • Simple flight controller
  • Simple physics simulator
  • Simple sensors simulation (IMU + altimeter)
  • Transform/TF tree
  • Timing and stuff
  • Localization (GPS or otherwise)
  • Autonomy executive/decision making

#Design discussion

A lot of the design here is a direct reaction to using ROS/ROS2, so it uses different design assumptions to see if everything I've been complaining about with ROS can actually be fixed as easily as I think it can. Thus it assumes as much as possible is on a single computer, embraces the simplicity of a central authority for coordination/etc, and makes a strict separation between onboard reliable communications and offboard unreliable communications.

  • Elixir+Rust -- After much soul-searching, the system will be written in and for Elixir, with Rust for optimizations as necessary. Using other languages like Erlang or Gleam are probably possible but not in-scope.
  • Opinionated -- This is designed for flying copters of some kind or another, mayyyybe someday hybrid aircraft with VTOL capability. Fixed-wing aircraft are much pickier about what they can do.
  • Stateless -- As much as possible is stateless or state is passed around explicitly
  • Centralized -- Information and coordination is centralized rather than distributed, simple and robust. Start off assuming a single main controller for the aircraft.
  • Unreliable comms -- Distributed Erlang and/or TCP will be used only on reliable connections -- Unreliable communications like in-flight telemetry will go over their own protocol
  • Integrated -- This will be split apart into separate libraries as much as is useful, and no further. Being able to "easily" swap out basic infrastructure like math libs or core libs is not a goal.
  • Soft realtime operation -- Try to make latency of decision making and comms low, steady and predictable. Actual proofs of this, even very loose ones, would be nice to try to do someday. Hard realtime constraints will be delegated to flight control firmware running on a microcontroller
  • Drone swarms -- This is not a goal to start with, but I do want to play with both managing many independent drones as well as drones that can coordinate with each other

#Drone interface

Velocity control seems like the obvious place to start, nice compromise between high-level and low-level. Basically the autonomy system tells the flight controller "fly forward at 3 m/s and rotate CCW at 0.1 radians per second" or whatever X times per second and the flight controller does it. This is fairly simple to implement on both ends and means that the autonomy system only needs to know the basics about the aircraft's flight performance -- speed and acceleration limits. More info might make the autonomy better, but only incrementally. Other options might exist in the future.

When we get to using a real flight controller, we will assume it is PX4 and talk to it via MAVLink, PX4's data networking protocol.

This should be able to work with any size/shape drone between 10cm and full-size helicopter, as long as it can hover, fly at up to a reasonable speed (<200 kph?) and isn't too picky about things like glide slopes. Anything needing to know about actual aerodynamics of the vehicle is a problem for another time.

#Environment and sensor assumptions

We will start off assuming only the most basic of sensors -- IMU and maybe altimeter. A real drone will always try to have GPS, but in reality GPS is noisy and unreliable and sometimes you wanna fly indoors, so I want to start off making sure we can fly without GPS. SLAM with a lidar or cameras or both is a research project for another time. Intermittent GPS is a research project for another time. If we can fly well without awareness of the environment then obstacle avoidance and pathfinding and stuff starts becoming possible.

Once you start flying >1 km away from its origin the curvature of the earth starts becoming detectable and you need to deal with it, this isn't gonna happen at first but part of the goal of this is to figure out how to handle it well.

It needs to understand that wind exists and be able to do something about it.

It needs to understand that sensors are noisy and be able to do something about it. Detecting and making decisions about outright failed sensors is out of scope for now.

It needs to understand that the ground is a real thing that can hurt you, and that the ground where you land may not be at the same altitude as the ground where you took off.

#References