Holds all flight software for the UConn Propulsive Landing team rockets. 😄
All source code utilizes Hungarian Notation.
Create features in branches originating from the dev
branch. When a feature is complete, make a pull request to merge it into dev
.
- How to Run
- Building the Source Code
- Hardware Configuration
- Software-in-the-Loop Testing
- Systemd Service Setup
- Clone this repo.
- Install the CMake Tools extension on VS Code.
- Run
sudo apt install libeigen3-dev
. - Build the repo (ensure you're in either debug or release mode depending on your need).
- Run the executable that gets created in the
build/
folder.
-
Clone the repository:
git clone https://github.com/Propulsive-Landing/ferda.git
-
Enter the new folder:
cd ferda
-
Generate the build files using CMake:
- For release:
(this uses the actual hardware sensors)
cmake -Bbuild -DCMAKE_BUILD_TYPE=Release .
- For debug:
cmake -Bbuild -DCMAKE_BUILD_TYPE=Debug .
- For Simulation:
cmake -Bbuild -DCMAKE_BUILD_TYPE=Simulation .
- For release:
-
Enter the newly generated
build
folder:cd build
-
Build the source:
make all
-
Run the executable inside the
build
folder:sudo ./Ferda
-
Create a
logs
folder in the root of the project (without it, no logs will be saved).
The Xbee module is a radio module which is used by our flight computer to send and receive data from the ground control, such as when we want to instruct the rocket to launch, or when we want to tell it to abort. To use the Xbee from our Raspberry Pi, we must configure it properly, here's how:
- Xbee is currently (9/28/2024) configured to act as a terminal that only outputs values when there is a newline character.
- Use
stty
to configure the device:(stty -F /dev/ttyS0
/dev/ttyS0
may change per device). - Configure settings:
Disable settings using a minus sign and enable settings without it.
stty -F /dev/ttyS0 -settingToDisable settingToEnable
- The device configuration should resemble:
speed 9600 baud; line = 0; -echo
Our Custom PCB communicates with various sensors through different protocols which generate multiple device files which may change. To account for the device files changing, we have a script which creates symbolic links (shortcuts) to each of the devices and each link is in a predictable location which is then referenced from the flight software. Here's how to add that script:
-
Create a shell script to perform device detection and symbolic link creation:
/home/pi/fsw_startup.sh
#!/bin/bash # Define the home directory for symbolic links HOME_DIR="/home/pi" LOG_FILE="/home/pi/fsw_startup.log" # Log function to append messages to the log file log() { echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE" } # Define the symbolic links ACCEL_LINK="${HOME_DIR}/accel_device" BAROMETER_LINK="${HOME_DIR}/barometer_device" GYROSCOPE_LINK="${HOME_DIR}/gyroscope_device" # Remove old links if they exist rm -f "$ACCEL_LINK" "$BAROMETER_LINK" "$GYROSCOPE_LINK" log "Starting device linking script..." sleep 0.5 # Iterate over the IIO device directories for device in /sys/bus/iio/devices/iio:device*; do if [[ -d "$device" ]]; then if [[ -f "$device/in_accel_scale_available" ]]; then ln -s "$device" "$ACCEL_LINK" echo "IMU device found: $device" log "IMU device found and linked: $device" elif [[ -f "$device/in_pressure_scale" ]]; then ln -s "$device" "$BAROMETER_LINK" echo "Barometer device found: $device" log "Barometer device found and linked: $device" elif [[ -f "$device/in_anglvel_scale" ]]; then ln -s "$device" "$GYROSCOPE_LINK" echo "Gyroscope device found: $device" log "Gyro device found and linked: $device" fi fi done sleep 2.0 # Uncomment if you want fsw to start automatically on next boot # cd /home/pi/ferda/build # /home/pi/ferda/build/Ferda
-
Make the script executable:
sudo chmod +x fsw_startup.sh
Software-in-the-loop (SIL) testing allows you to connect your flight software to MATLAB's Simulink environment for real-time simulation. Follow the steps below to set up and run the SIL testing environment.
Install WSL2 - help
To run your flight software in a Linux environment on Windows, you need to install WSL2 (Windows Subsystem for Linux). The steps can varry depending on your setup so you may have to do some troubleshooting to install it properly. Follow these steps:
-
Open PowerShell as Administrator and run:
wsl --install
-
Set up your preferred Linux distribution (e.g., Ubuntu) as your default WSL instance.
-
Ensure WSL2 is set as the default version:
wsl --set-default-version 2
-
Once your distribution is set up, enter your WSL terminal and update your package list:
sudo apt update
To build the flight software, you need to install several tools in your WSL environment:
-
CMake – for managing the build process:
sudo apt install cmake
-
Make – a build automation tool:
sudo apt install build-essential
-
Clang – a C++ compiler:
sudo apt install clang
-
Git – to clone and manage your repositories:
sudo apt install git
-
GitHub CLI (gh) – for interacting with GitHub:
sudo apt install gh
To interact with private GitHub repositories and push code, you need to authenticate with GitHub CLI:
-
Log in using the GitHub CLI:
gh auth login
-
Follow the prompts to authenticate via a web browser or with a GitHub token. Choose HTTPS as the protocol when prompted.
-
To get the host machine's IP: Open a WSL terminal and run:
ip route show | grep -i default | awk '{ print $3}'
Look for the IP address under the "Ethernet adapter vEthernet (WSL)" section.
-
To get the WSL instance's IP: In your WSL terminal, run:
hostname -I
-
Clone the flight software repository in your WSL terminal and switch to the correct branch (likely dev):
git clone https://github.com/Propulsive-Landing/ferda.git cd ferda git switch dev
-
Build the software in simulation mode using the:
cmake -DCMAKE_BUILD_TYPE=Simulation -DSIM_LOCAL_PORT=8002 -DSIM_SERVER_PORT=8003 -DSIM_SERVER_IP="[Insert Host IP here]" -Bbuild . cd build make all
Note: Ports may change in future versions of simulation.
- In MATLAB, open the Simulink model for flight simulation.
- Set the UDPSend block to the WSL IP and port 8002, and ensure the UDPReceive is set to receive from any source.
- Install Simulink Desktop Real-Time to run the simulation in real-time using the Add-on manager in Matlab
- Make sure you have the Real-Time Kernel installed. A guide on this is shown here
- Set Simulink to Connected IO mode and start the simulation.
Switch back to WSL and run the flight software:
sudo ./Ferda
For users who prefer running the flight software directly on Windows without WSL, you can follow this guide to set up and run the simulation loop using Windows native tools and loopback IP. However, please note that the flight computer uses a linux based OS and therefore, discrepancies may occur.
To build and run the flight software natively on Windows, you'll need to install several development tools:
-
CMake – Download and install from the official website: CMake.
- Make sure to add CMake to your system path during installation.
-
Visual Studio (or Build Tools for Visual Studio) – This will provide a C++ compiler. You can install the Desktop development with C++ workload via the Visual Studio Installer or download Build Tools for Visual Studio from here.
- Ensure that the "MSVC" compiler and CMake support are selected during installation.
-
Git – Download and install Git from the Git website. This will allow you to clone the repository and manage version control.
-
GitHub CLI (gh) – Install GitHub CLI by downloading it from GitHub. Once installed, authenticate via:
gh auth login
Follow the prompts to authenticate with your GitHub account.
-
Clone the Repository: Open a Git Bash or command prompt on Windows and clone the repository:
git clone https://github.com/Propulsive-Landing/ferda.git cd ferda git switch dev
-
Generate the Build Files Using CMake: In your Git Bash, command prompt, or terminal of choice, configure the build for simulation mode:
cmake -Bbuild -DCMAKE_BUILD_TYPE=Simulation -DSIM_LOCAL_PORT=8002 -DSIM_SERVER_PORT=8003 -DSIM_SERVER_IP="127.0.0.1"
Explanation of flags:
-DCMAKE_BUILD_TYPE=Simulation
: This flag sets the build for simulation.-DSIM_LOCAL_PORT=8002
: Port used to receive data from Simulink.-DSIM_SERVER_PORT=8003
: Port to send data to Simulink.-DSIM_SERVER_IP="127.0.0.1"
: Since we are running everything on the same machine, use127.0.0.1
(loopback IP).
-
Compile the Software: Navigate to the build directory and compile the software:
cd build cmake --build .
This will generate the
Ferda.exe
executable file in the build folder. -
Create a Logs Directory (Optional): If logging is enabled, make sure you have a
logs
directory in the root of the project:mkdir logs
-
Launch MATLAB and Simulink: Open the Simulink model for flight simulation in MATLAB.
-
Configure UDPSend/UDPReceive Blocks:
- Set the UDPSend block to send data to the loopback IP (
127.0.0.1
) on port8002
. - Ensure that the UDPReceive block is configured to listen on port
8003
.
- Set the UDPSend block to send data to the loopback IP (
-
Install Simulink Desktop Real-Time: You need the Simulink Desktop Real-Time add-on to run simulations in real-time. You can install this via the Add-On Manager in MATLAB.
-
Set Simulink to Connected IO Mode:
- Set Simulink to Connected IO mode to simulate real-time hardware.
-
Start the Simulation: Start the Simulink simulation.
- The rocket should remain static until your flight software commands it.
- Make sure your model is running in real-time with 1:1 real-time to simulation
-
Return to the Command Prompt: Switch back to your command prompt or Git Bash.
-
Run the Flight Software: Start the flight software by running:
./Ferda.exe
Notes:
- Run ferda (FSW) through WSL first if you're having trouble communicating with the simulation
- WSL can be tricky to initially set up but there is plenty of available documentation to resolve these issues, start here and use google if you still are having issues.
The flight software should be connected with the Simulink simulation, sending actuator commands and receiving simulated sensor data.
For convenience, it is preferable to have the startup script run automatically. We can accomplish this by using systemd as demonstrated below.
-
Create the service file to run the startup script at boot:
/etc/systemd/system/fsw_startup.service
[Unit] Description=Link IIO Devices After=local-fs.target [Service] Type=oneshot ExecStart=/home/pi/fsw_startup.sh RemainAfterExit=yes [Install] WantedBy=multi-user.target
-
Enable the service:
sudo systemctl enable fsw_startup.service
-
Start the service (optional):
sudo systemctl start fsw_startup.service