N4 Flight Software N4
Flight software used for the N4 flight computers
Loading...
Searching...
No Matches
N4 Flight Software

Introduction

Welcome to N4 Flight software docs. N4 Flight software is the code used to run N4 rockets at Nakuja Rocket Project. This code is built using FreeRTOS on the Arduino-ESP32 framework. It is designed to run either on AI-Thinker NodeMCU-ESP32 boards or ESP32-DOIT-DEVKIT V1.

Major features

This firmare has been improved tremendously from the previous versions and includes the following features:

Modularity

  • Most of the code is now contained in separate files each perfoming its own singular task to ensure code maintainability and testing.

System Logging

  • We have built a system logger to keep track of each and every operation that the flight computer undertakes. This can be be retrieved later and reviewed for post-flight analysis

HIL Testing Engine

  • A hardware-in-the-loop testing engine has been built into the flight software to allow us to "Test Like We Fly". This allows the flight computer to be tested and debugged way before flight day. Using an improvised XMODEM algorithm, we are able to upload test flight data and run necessary integration tests.
    Note
    See Integration and Testing Procedures for more info

Flight data logging

  • Flight data logging has been improved. Using an onboard SPI Flash memory, we are able log sensor data and flight states.

Data dump interface

  • A data dumping hardware interface has been added to ease the retrieval of data post flight data.

SAFE and FLIGHT modes

  • To prevent misfires during intergration and testing, this firmware implements SAFE_MODE that among others operations, disables the pyro-charges before POWERED_FLIGHT.

XBEE, MQTT, LORA, WIFI telemetry selection

  • For backward and forward compatibility, we implement a method to allow choice of data telemetry protocol being used.

Double ejection

  • We implement drogue and main chute ejection algorithms for successful vehicle recovery

Building, Compilation and Downloading.

System requirements

The following must be installed to build this release:

  1. PlatformIO Core. Download the core here: PlatformIO Core
  2. PlatformIO IDE (recommended on VS Code but you can use IDE of your choice). To install PlatformIO IDE, follow the steps listed here: PlatformIO IDE
  3. Serial Monitor tool e.g. Putty, Ai-Thinker Serial, RealTerm etc

Building the code

  • Clone the repo on your local machine
    git clone https://github.com/nakujaproject/N4-Flight-Software.git
Note
You can also download the folder as a zip file and extract it to a folder of your choice. But we recommend cloning it so you can keep up to date with the remote changes.
  • Change the directory to
    N4-Flight-Software\n4-flight-software
    . This is the folder containing
    platformio.ini
  • Install code dependencies
    pio pkg install
  • Build
    pio run
  • Connect your flight computer using a USB cable and make sure it is seen by your PC. It should be listed under Device Manager>Ports, if you are on windows
Note
If your ESP32 is note recognized, you have to install USB-TO-TTL chip driver manually. For ESP32 Boards using CH340 chip, download the driver here CH340 Driver-SparkFun. Run the driver and it will be automatically installed on your machine. For ESP32 Boards using CP2102 chip, follow the procedure here CP2102-driver-POLOLU. Run the driver and it will be automatically installed on your machine.

Upload and run Close any open serial ports connected to that ESP32 and run the command below

pio run -t upload

The firmware will be uploaded to the flight computer!

Hardware, pin assignment and peripherals

The pin assignment to ESP32 are listed in the following file: https://github.com/nakujaproject/N4-Flight-Software/blob/main/flight-computer-pin-assignment-version-1.xlsx

Integration and Testing Procedures

To perform testing and integration of the flight computer, follow the steps below:

Hardware setup

  • Referring to the N4 flight computer pinout, make sure the Test/Run toggle is set to TEST-MODE

  • Upload the n4-flight-software code to the flight computer as per the instructions in the [Upload and run] section above

How to use the Nakuja Flight Computer Testing Engine

The testing engine is built to streamline the testing procedures and help inteprate the commands received from the Device Under Test during the testing phase. It also helps in downloading the test data to the Flight Computer for simulation.

Installation

Note
In development

Downloading the test data

  • Double click on the app to open. The following window appears.
  • Select the COM port that the flight computer is connected to.
  • Select the baud rate
  • Choose the test-data CSV file.
  • Click Connect. The flight computer will be connected to the PC via serial. [Connected on COM[X] ] shows on the status bar.
  • On the flight computer, press on the RESET/EN button and observe the serial Monitor. A code 21 should be received on the Serial Monitor every 4 seconds. Here is the X-MODEM commands list for quick reference:
X-MODEM Commands
Command HEX DEC Description
SOH 01 1 Start of Heading
ACK 06 6 Positive acknowledge
NAK 15 21 Negative acknowledge
CAN 18 24 Cancel
EOT 04 4 End of transmission
  • Click on Link Data. The test engine will download the test data to the flight computer, and the progress will be indicated on the serial Monitor

Pre-flight software checks

The following checks MUST be performed pre-flight to ensure the software operates as designed:

  1. test mode pin toggle
  2. telemetry protocol selection
  3. clientID (rocket ID)
  4. arming check
  5. DEBUG_to_terminal check - defs.h
  6. LOG_TO_MEMORY - defs.h

WIFI network configuration

The software is written such that it allows connection to any WIFI being used, without hardcoding the WIFI credentials into the flight software. This will make the launch preparation faster as no code uploading needs to be done on-site. Follow the procedure below to connect to WIFI:

  • After uploading the flight software to the computer, the serial terminal will show the following response. Note the marked are which is of interest.

This shows that the flight computer has created a web portal and is waiting for connection from an external device.

  • When powered on, the flight computer will create an open WIFI network called "flight-computer-1". This network will be visible on any device within range.
  • The FC sets itself as an Access Point and will provide its own WIFI network to the for other devices to connect to.
  • On the ground station computer, or using a smartphone, connect to "flight-computer-1". (NOTE: The WIFI name will change depending on the name of the rocket being used )
  • Open the browser and go to the following IP address "192.168.4.1". This should open the following window in your browser.

  • Click on Configure WiFi. The window below opens.

    • Enter the WIFI SSID and password for the network you want to connect to. In this case it is the WIFI network used for telemetry transmission.
    • Press save. The flight computer will save the network credentials and auto-reconnect itself as a station to the launch WIFI network.

    – Assuming that the you have supplied the correct login credentials, the ESP32 will now be connected to the WiFi network.

    • You can now stream telemetry over that network.
    • Make sure that the ground station PC and the flight computer are on the same network.

MQTT configuration

Note
In Development

Flight Data Collection and Kalman Filtering

The main senors used in the flight computer are accelerometer and pressure sensors. We use the MPU6050 for acceleration and angular velocity measurements. We use the BMP180 for atmospheric pressure and altitude measurement. This data is collected as raw data which is then processed and filtered using the Kalman filter algorithm.

The Kalman Filter allows us to perform predictive recursive low pass filtering which greatly improves our collected sensor data which is safe for the state machine to consume.

To learn more about the Kalman filter implementation, refer to the kalman.h and kalman.cpp files in the src folder of the n4-flight-software.

Launch detection

Note
In development

Apogee detection

We detect apogee using the altitude values from the altimeter. The logic we use is that the * rocket's altitude increases as it ascends up continously. On reaching apogee, the rocket's altitude *starts decreasing.

To detect the decrease in altitude, we keep track of the last SIZE_OF_BUFFER items (see *ring_buffer.h). We then check the current altitude value against the oldest value in the ring *buffer. If the difference is more than the set THRESHOLD (usually 5 meters), we are sure that at *this point the rocket is coming down and we register APOGEE.

This is made possible using a ring buffer(circular buffer), that is implemented to always keep *track of the previous SIZE_OF_BUFFER. From this buffer we can infer apogee.

Parachute ejection

Note
In development

Contributors

Our thanks go to the following current and previous avionics team members for their contribution:

  1. Edwin Mwiti
  2. Junn Hope
  3. Jones Kisaka
  4. Ruth
  5. Safa Osman
  6. Tabby Achieng
  7. Sharlyn
  8. Pat
  9. Emmanuel Nindo
  10. Fortune
  11. Newton
  12. Rodney
  13. Sammy
  14. Michael Kimani
  15. George Bange
  16. Maisha
  17. Naomi Chesang
  18. Brian Munene
  19. Samson Onyambu
  20. Cate Kabura
  21. Amos Korir
  22. Graig Kipkorir
  23. Jerry Mumo
  24. Esther Mamai
  25. Martin Simbona
  26. Jeff Mboya
  27. Washington Kamadi
  28. Ian Muchiri
  29. Kibandi
  30. Emmanuel Obara
  31. Victoria

    Ad Astra!!