ECS but better
This is a redesign of the current Engine Control System. In addition to the before aims of safety and reliability, this redesign focuses on better readability through object-oriented design.
Currently, we are using a RaspberryPi based electronics system to control the test stand. On the actual rocket, we will be using a custom PCB.
From here, your first step should be to clone the most recent version of the Engine Control Software (ECS):
git clone --recurse-submodules https://gitlab.com/aeronu/dollar-per-foot/better-engine-control-software.git
if you forgot the --recurse-submodules
flag (aka a regular git clone
), you need to run
git submodule init
git submodule sync
git submodule update
as well.
The current working code should be in the main
branch
TODO: Add picture of the wiring system we have here
To get started you'll first need a Pi, a 5V, a 2-2.5A power supply, a micro-sd card (if not already in the pi), and an ethernet cable.
If the Pi has not been set up yet, you will need to flash the OS to the microSD card. We are currently using the default version of the RaspberryPi OS Lite (without Desktop).
Once the operating system has been flashed, the easiest way to connect to the Pi will be over ssh. Connect
your laptop to the Pi via ethernet and run ssh [email protected]
. The default password for any new Pi
OS is raspberry
.
If you are not cross-compiling, you will need to do the below as well
From here, your first step should be to clone the most recent version of the Engine Control Software
(ECS): git clone https://gitlab.com/aeronu/dollar-per-foot/better-engine-control-software.git
. From here, switch to the
appropriate branch (or use main
if you're just testing the simulator).
Before building you'll need to install CMake: sudo apt-get install cmake
. CMake is the build system we use for
all of our C++ code. While it is generally bundled as part of certain operating systems or as part of IDEs, it
is not installed by default on the Pi.
Before moving on you should check the version of cmake with cmake --version
. If you have less than 3.16,
run sudo apt-get update
and then sudo apt-get upgrade
to update your packages.
To build this repo, you will need a C++ and C compiler, and CMake
Typically these systems will include a C++ and C compiler out of the box, usually GCC. However, it might be out of date because we are using C++20, one of the newest versions. Chances are CMake isn't included either.
To install, download using your distro's package manager. For Debian/Ubuntu this should be apt-get
.
For example you will probably type
sudo apt-get install [WHATEVER THE NEWEST GCC COMPILER PACKAGE IS]
sudo apt-get install cmake
into the command line on a Debian/Ubuntu system
TODO: Apple's C++ compiler, AppleClang is really slow to implement new features. We have to install a newer one
The easiest way to build on Windows is probably to use Microsoft Visual C (MSVC), which comes with Visual Studio. It's really big but the only way I've found to make it actually work on Windows. CLion deals with all the cmake/make stuff for you, and allows for debugging.
- Download Visual Studio Commuinty, and run it
- Click 'Continue'
- We'll just want 'Desktop development with C++'.
Now that you have the dependencies installed
- navigate to the ECS repository you cloned in the command line
- run the following command
cmake -S . -B build
This process will create a build
directory that will house all of the build files and keep the clutter out of
the source repository. CMake is responsible for creating the Makefile/Ninjafiles that will build the code.
There are three executables that can be built and used: ecs_sim
, ecs_pi
, and ecs_quick
.
ecs_sim
is an entirely simulated version of the control system. The simulator can be configured by modifying the simulator config (planned feature).ecs_pi
is the executable used to actively control relays and read sensors from the stand. Because of its dependencies it is likely impossible to build local, but should build fine on the pi. This is the executable that should be used on the test stand.ecs_quick
is if you want to quickly build and try a test script, just don't forget to tweak the CMake file!
NOT CURRENTLY IN THE REDESIGN: ecs_hybrid
is a mix of ecs_sim
and ecs_pi
. It runs two versions of the control software simultaneously and is used for actively controlling the stand while providing synthetic
data from the simulation. This is ideal for training scenarios as it can be treated as a real test where the operator is actuating valves and reading real-looking values. Because this executable has the same
dependencies as ecs_pi
it will not be able to be built locally.
- If we see a need for it, we can add it
Once you have determined which executable you would like the build, you can run the command
cmake --build build -t [EXECUTABLE NAME]
where [EXECUTABLE NAME]
is replaced with the appropriate executable name.
some highlights you will probably be running are
cmake --build build -t ecs_sim # our simulated ecs binary
cmake --build build -t all_tests # our test suite
If you would like to build all executables at once (again, only possible on the pi itself and will take some time), you can just run
cmake --build build
All executables will be placed inside the build/
directory. Inside the build directory you should be able to find your [executable name]
executable, it might be buried in some folders though.
If you don't want to build through the cmdline, you can use your IDE.
I don't have a runthrough for VSCode, but it should be easy enough to search up
Here are some directions for CLion:
We can now import our project into CLion. In CLion, go to "Open" -> "better-engine-control-software/CMakeLists.txt" -> "Ok" -> "Open as Project"
In the Open Project Wizard, add our MSVC "toolchain" with "Manage toolchains" -> + sign -> Visual Studio. Click OK and OK
Navigate to src/main_sim.cpp
, click the green arrow next to int main()
and click Run
.
Cross-compiling is when you build a program on one kind of computer, but make it run on another. In our case, we can cross compile for Raspbian (the Pi os) from Ubuntu pretty easily.
We use docker for this, because I found a Docker image (sorta like a VM) for Ubuntu that has everything set up for us already. However, note that you can't actually run the executable on your computer, even in the Docker container. That's because Docker isn't really a fully fledged virtual machine. For example, if your computer's architecture differs (RPi is ARM, if your computer is x86 for instance), Docker doesn't abstract over than, your binary will fail to run.
Here's the steps to cross-compile the ecs_pi
executable, which you run from the root directory of this project:
You may need to follow these Docker install instructions if
sudo apt install docker.io
doesn't work. Then, add yourself to the docker group:
# Probably unneeded, it makes one automatically
sudo groupadd docker
sudo usermod -aG docker $USER
# Run this, or log out and then in, to register changes
newgrp docker
To actually build, use ./cross_compile_ecs_pi_debug.sh
or ./cross_compile_ecs_pi_release.sh
. The debug
variation will spit out more helpful data in case of a crash, the release
variation will be more efficient
How it works (from Matt): I copied a bunch of toolchain file stuff from wpilib (thanks wpilib!). The script above starts a docker container, creates the cmake makefile stuff with
cmake -B build-pi -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=CMake/arm-pi-gnueabihf.toolchain.cmake
, and then builds it.
To then copy to the Pi, run ./install_docker.sh
. For convienence, you can install your SSH key onto the Pi:
- If you don't yet have a id_rsa.pub in ~/.ssh, create it with
ssh-keygen
- Install with
ssh-copy-id [email protected]
If running the ECS locally, connect the GUI to localhost:9002
If running the ECS on the pi with a laptop connected via ethernet, connect the GUI to raspberrypi.local:9002
This project uses C++ for implementation, CMake for building, and Catch2 for unit-testing. Below are some tutorial links if you want to get a idea of how these tools work.
C++ is a FAMOUSLY hard language to learn. And unfortunately, most of the online tutorials are DOGSHIT. I'll probably run through some basic C++ classes during some meetings. But I've also started a folder of references/tutorials in the c++_tutorial_markdowns
folder, take a look!
- Note: We are not using the latest version of Catch2. Newer versions have abandoned the single-header include. As we do not currently need sophisticated features for our tests, we use the older single header-file due to its convenience
- A pretty in-depth tutorial
- The official quick tutorial
- just ignore the "Getting Catch2" section because we are using the old versions