Getting Started If New - Terrapin-Rocket-Team/SRAD-Avionics GitHub Wiki

Home/Getting Started/Getting Started if New

Getting Started as a New Member

First off, welcome to the team! This page is designed to help anyone who recently joined but may lack experience in the areas we work in. It will cover setting up your coding environment and defining common concepts. There is also a short "project" at the end that is intended to teach you how to use the State class and get some code running on an Arduino.

If you haven't already, read the General Overview page, as it gives basic information about the club, the Avionics subteam, and the tools we use.

Essentially, we develop a flight computer for TRT that handles telemetry gathering and transmitting. In our case, a flight computer represents a custom-built PCB, sensors, and an Arduino-based Teensy that we call the Unified Board. This board has a number of sensors and a radio transmitter on it. It gathers GPS, Acceleration, and Barometric data, merges them as necessary to better estimate the state, or position, of the rocket, and then logs that data to a file and sends it to the ground station.

Avionics members contribute to multiple aspects of Flight Computer development. We do 3D modeling and printing, PCB design, and software development. This page will focus on the software development aspect. See the Hardware page for information on the other aspects.

Environment Setup

To develop the software for this board, we use a VSCode extension called PlatformIO. This extension allows us to write code in C++ and compile it for the Teensy. It also allows us to upload the code to the Teensy and monitor the Teensy's output. To get ready to code, you will need to install both of these tools and git.

First, install git. Download the appropriate version for your operating system from git-scm.com. It's recommended to just download the installer (the first link on each OS's page) and run it. The default settings should be fine, unless you know what you're doing.

When that's done, install VSCode, followed by PlatformIO. As the VSCode page says, we also recommend the C/C++ extension for syntax highlighting and IntelliSense.

If you need a crash course in git, check out this page. That will teach you the basics of git and how to use it with GitHub.

From there, you should be ready to clone the SRAD_Avionics repository and start coding. You can copy this URL to clone the repository:

https://github.com/Terrapin-Rocket-Team/SRAD_Avionics.git

Code Basics

The code for the flight computer is written in C++ and is compiled using PlatformIO. It can be found under Spaceport/23-24/Code/Teensy-based Avionics/. The Install PlatformIO page has more information about how to set up your environment to run the code on the Teensy. This will be a general overview, but the Documentation page has more detailed information.

There are a number of main and auxiliary files that combine to make the flight computer work. main.cpp is the entry point. It establishes the sensors and initializes everything. Every 100ms (10hz), it makes a call to the State object to update itself. State represents, perhaps unsurprisingly, the state of the rocket. It knows what stage it's in, where it is, and how fast it's going. As it updates itself with new data from the sensors, it logs that data to the SD card. Two times per second, main sends the latest update to the ground station via radio. There are also Sensor files, Testing files, Math files, and more.

The team encourages Object-Oriented Programming (OOP) practices. This means that we try to write code that is modular and reusable. The Sensor classes are good examples of this. Each sensor has its own class that inherits from the Sensor class. This allows us to write code that is specific to each sensor, but also write code that is general to all sensors. For example, the BMP390 class has a method that reads the barometric pressure from the sensor. The BMP390 class inherits from the Sensor class, which has a method that updates the sensor's data. This means that we can write code that updates all sensors at once without having to write code for each sensor.

A Short Project -- Will change for the 24/25 year

This is designed to get you familiar with the code and how it's all laid out and interconnected.

Start by opening the project in VSCode, making sure you're on the main branch, and creating a new branch. You can do that via command line (git checkout -b <branch-name>), through the Source Control tab in VSCode, GitHub Desktop, or one of the myriad of git extensions. The branch name should have your name in it and state that this is the tutorial project, something like <name>-tutorial.

The project is to create a new sensor class. This class will be called TestSensor and will inherit from the Sensor class. It will have at least two fields called data (int) and deltaT (double). The TestSensor class will implement update to set data to a random number between 0 and 100 and deltaT to the elapsed time since the last update. Start by creating TestSensor.h and TestSensor.cpp files. If you need help with how to structure classes and files in C++, check out the C++ page.

Remember that Copy and Paste are your friends, don't be afraid to just copy another sensor and rip out the parts you don't need. In this case, because it's not a real sensor, simply have init set initialized to true and return true. Modify other methods as necessary (e.g. getName, getDataString).


Note: Part of the idea is to think about code structure. Most intro CS classes have you create 'getters' and 'setters' for every internal variable. Here, setters are generally discouraged because the only time you will change the value that a sensor holds, unless explicitly designed for something else, is when you run update(). Lacking a setter helps others understand that outside sources can read data from this class, but not modify it themselves. Similarly, this is why variables should not be public. If you need to access a variable from outside the class, you should write a getter for it. This allows you to control how the variable is accessed and what can be done with it.


Once you have this class set up, go ahead and commit your changes to git. Again, you can use any method you like. Once committed, you can publish or push the branch to GitHub. This will allow the team to see your changes and give you feedback once you're done. Again, if you need an intro to git, check out this page.

Once that's done, we can implement the TestSensor into State. Start by adding a new private method to state called checkTestSensor() that will check if deltaT is greater than 100ms. If it is, use the RecordData library to write a log entry as a warning that it took a while to update, along with how long it took. Then, update updateState() to call checkTestSensor(). Finally, edit getStateString() to include the data field from TestSensor in the string that is returned, as the last column.

Commit these changes again, with a message that describes what you did.

The last part of the project is to add your sensor to the main.cpp file. Include your TestSensor.h and declare a TestSensor object in the top of the main file similar to the other sensors. In the setup() function, add a line that adds your sensor to State.

At this point, you are ready to test your sensor. You need a Teensy, which you can get from the Cypress building. Let anyone on the team know you're ready, and they can help coordinate with you.

Once you have the Teensy, compile and upload the code to it. You can do this by pressing the right-facing arrow in the bottom toolbar of the VSCode window. If you have any errors, check the output in the terminal at the bottom of the window. If you can't figure it out, ask for help in the #avionics channel on Slack or on GitHub. Once it's uploaded, open the Serial Monitor and make sure that the Teensy is updating the TestSensor data by looking at the last column of the Serial output. See if there are any warnings about the time it took to update, although there may not be.

If you see the data updating, congratulations! You've successfully added a new sensor to the flight computer. Unplug the Teensy to stop it, and look at the most recent flight file on the SD card to see how it logged the data from your sensor. You can also look at the log file to see if it logged any warnings about the time it took to update.

The very last step is to make sure you've pushed your changes to GitHub. Let someone know you've finished, and they can take a look. You can create a pull request for practice, in which you'd describe your changes and the 'why' behind them. However, because this is a tutorial project, the PR will be closed without merging. This is just to get you familiar with the process.

If you have any questions, feel free to ask in the #avionics channel on Slack or on GitHub. We're happy to help you learn and grow as a member of the team.

See Also

⚠️ **GitHub.com Fallback** ⚠️