Skip to content
Zach Garcia edited this page Oct 2, 2022 · 7 revisions

Welcome to the oop-flight-code wiki!

Code Overview

This code is structured based on Lodestar, a small scale electric demonstrator for the belly-flop and tail-sitting control algorithms necessary for SpaceX's Starship.

Both ClockManager and TimedControlTask are from PAN.

The clang-format file is from this thread.

main.cpp

This file is comparable to a .ino file you would see in the Arduino IDE (notice setup and loop are exactly the same as they would be in an Arduino file).

MainControlLoop

The MainControlLoop initializes and executes every monitor and control task.

MissionManager

The CubeSat has different modes with distinct entrance and exit conditions. MissionManager sets which mode the CubeSat should be in based on these exit/entrance conditions. Please see the Mission Modes page for more details.

SFR

SFR stands for State Field Registry. It contains the mode of each system, all sensor values, and universal flags that should be available to the entire CubeSat.

Control Tasks

Control tasks are any file that actuates/performs a task based on a value in the SFR.

Monitors

Monitors simply read input from sensors and update the sensor values in the SFR.

constants.hpp

Constants contains values that will never be changed. This prevents "magic numbers".

Getting Started

  • Install VSCode
  • Install Git
    • Make a GitHub account if you do not have one already
  • In VSCode, click on "Extensions" on the left hand toolbar. Search for and install PlatformIO IDE.
  • On the top toolbar, click "Terminal" and then "New Terminal". This should open a terminal at the bottom of your screen if it was not open already.
  • In the terminal, type "git clone https://github.com/Alpha-CubeSat/oop-flight-code.git"
  • Now at the bottom of your screen in the blue toolbar you should see a check, arrow, and serial monitor icon (it looks like an electrical cord). If you do not see the blue toolbar make sure you have the cloned git repo folder open.
  • If you would just like to compile code but not upload to the teensy, press the check.
  • If you would like to upload to the teensy, press the arrow.
  • You can also use pio run -e debug -t upload to upload code with debugging print statements, or pio run -e teensy35 -t upload to upload code without debugging print statements.
  • Use pio test to run unit tests.
  • To view the serial monitor press the electrical cord icon.
  • Navigate to View -> Command Palette
  • Search "settings" and select Preferences: Open Settings (JSON)
  • Enter the following in the settings JSON and save

{ "C_Cpp.clang_format_style": "file", "editor.formatOnSave": true, }

  • If the autoformat github action fails upon push, run clang-format -i ./src/*.cpp ./src/*.hpp ./src/**/*.cpp ./src/**/*.hpp in terminal to manually autoformat the source files and retry pushing the code

FAQ:

Q: What should I do if VSCode says, "Found Device But Unable to Read." A: You should mount the 49-teensy.rules file to the /etc/udev/rules.d Ubuntu directory (use command "sudo mv ~/Downloads/49-teensy.rules /etc/udev/rules.d"). After that, restart the machine.

You can either ask someone on the team for the file or create it yourself. The contents should be as follows:

`# UDEV Rules for Teensy boards, http://www.pjrc.com/teensy/

The latest version of this file may be found at:

This file must be placed at:

/etc/udev/rules.d/49-teensy.rules (preferred location)

or

/lib/udev/rules.d/49-teensy.rules (req'd on some broken systems)

To install, type this command in a terminal:

sudo cp 49-teensy.rules /etc/udev/rules.d/49-teensy.rules

After this file is installed, physically unplug and reconnect Teensy.

ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789]?", ENV{ID_MM_DEVICE_IGNORE}="1" ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789]?", ENV{MTP_NO_PROBE}="1" SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789]?", MODE:="0666" KERNEL=="ttyACM*", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789]?", MODE:="0666"

If you share your linux system with other users, or just don't like the

idea of write permission for everybody, you can replace MODE:="0666" with

OWNER:="yourusername" to create the device owned by you, or with

GROUP:="somegroupname" and mange access using standard unix groups.

If using USB Serial you get a new device each time (Ubuntu 9.10)

eg: /dev/ttyACM0, ttyACM1, ttyACM2, ttyACM3, ttyACM4, etc

apt-get remove --purge modemmanager (reboot may be necessary)

Older modem proding (eg, Ubuntu 9.04) caused very slow serial device detection.

To fix, add this near top of /lib/udev/rules.d/77-nm-probe-modem-capabilities.rules

SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789]?", GOTO="nm_modem_probe_end" `

Clone this wiki locally