Skip to content

Commit

Permalink
Raspberry Pi Pico support and organizational changes (#155)
Browse files Browse the repository at this point in the history
<!-- Please Give Your PR a relevant title-->

## Description of Problem
These changes encompass everything that was needed to support a new
flight computer: Birdbrain. Birdbrain is roughly derived from
Catalyst-2, but includes several hardware changes, including a new
microcontroller, IMU, radio, SD card module and pyro channels.

## Notable Changes
<!-- Describe your thought process and the steps you took to find a
solution. If your process resulted in a new issue being created, link it
here-->
- replaced references to `Catalyst-2` with the new software name:
`Stimulant`
- Added a `sensors` directory with interfaces for some of the sensors
- added source code for `LSMDSOX`
- replaced `settings.h` with `config.h` and added a config for each
supported flight computer (`Catalyst-2` and `Birdbrain`)
- added build flags in `platformio.ini` to link source code
- modified unit tests to "work" with the new architecture (further
modification will be needed)

## Testing
<!-- Describe the testing that you did to validate your changes (i.e.
ran a unit test, loaded onto physical microcontroller etc.)-->
<!-- ex:
- Executed "throw test" on Catalyst to verify behavior
-->
- Flight tested with successful main parachute deploy (triggered by lack
of drogue failsafe) (Birdbrain)
- Ground "throw" tests (Birdbrain)


closes #15
  • Loading branch information
JonathanSafer authored Mar 20, 2024
1 parent f82891d commit ee9173b
Show file tree
Hide file tree
Showing 31 changed files with 594 additions and 232 deletions.
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Catalyst 2 Flight Computer
Designed for Teensy 4.1
# Stimulant
Hardware agnostic flight software for high power rockets.

Want to contribute? Start [here](https://github.com/Harlem-Launch-Alliance/Catalyst-2/blob/main/GETTING_STARTED.md).
Want to contribute? Start [here](https://github.com/Harlem-Launch-Alliance/Stimulant/blob/main/docs/GETTING_STARTED.md).

# NOTE: At this time we are only accepting contributions from [HLA](hla.nyc) members for issues with the `beginner` label.

[Instructions for use](https://github.com/Harlem-Launch-Alliance/Catalyst-2#instructions-for-use)
[Instructions for use](https://github.com/Harlem-Launch-Alliance/Stimulant#instructions-for-use)

## Goals:
| Feature | Status |
Expand All @@ -26,29 +26,32 @@ Want to contribute? Start [here](https://github.com/Harlem-Launch-Alliance/Catal
[Flow Chart](https://miro.com/app/board/uXjVPYUZ7mY=/?share_link_id=493963314311)

## Hardware:
This software can support any configuration of hardware with exactly one of each of the following types:
- Microcontroller
- Inertial Measurement Unit
- GPS
- Radio transceiver

The following hardware is currently supported:
- Teensy 4.1
- Adafruit BMP388 Barometric Altimeter
- RaspberryPi Pico
- Adafruit BMP388/BMP390 Barometric Altimeter
- GY521 IMU (MPU 6050)
- LSM6DSOX IMU
- Adafruit Ultimate GPS
- Xbee-PRO S3B
- 5V buzzer

## Dependencies:
- https://github.com/adafruit/Adafruit_BMP3XX
- https://github.com/adafruit/Adafruit_GPS

## Best Practices For Making Changes:
- make sure your code compiles to verify your changes
- comment your code
- if you are including a new library in your code, add the GitHub link to the dependencies list above
- multiple small functions are better than one big one. Remember, each function should only do one thing
- break out groups of functions into their own files. Long files are difficult to read. Ideally `main.ino` would only have `void setup()` and `void loop()`

## Instructions for use:
1. Connect all sensors and power source
2. Integrate Teensy with rocket (try to keep IMU aligned with axis of rotation)
2. Integrate flight computer with rocket (try to keep IMU aligned with axis of rotation)
3. Put rocket on launch rail
4. Power on Teensy
4. Power on flight computer
* **CAUTION**: Once powered on, any sudden movements may trigger launch detection
5. Wait at least 5 minutes between powering on and launching to allow for proper sensor calibration
6. Launch!
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 3 additions & 6 deletions main/apogee.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
* apogee detection and helper functions
*
****************************************************************************/
#pragma once

#include "Ewma.h"
#include "utils.h"

#define G_FORCE_TO_LAUNCH 3 //if acceleration exceeds this number the rocket will assume it has been launched
#define MAX_APOGEE_ACCEL 2 //we can rule out apogee if acceleration is about this amount (Gs)
//#define CHECK_FOR_APOGEE_HZ 4 //frequency that we check for apogee within the detect apogee function
#include "utils/datatypes.h"
#include "utils/Ewma.h"

/**
* @brief Detect if rocket has been launched using acceleration data
Expand Down
6 changes: 4 additions & 2 deletions main/attitude.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
//rates are magnitudes of rad/s
//assuming roll == 0, pitchRate will be equivalent to y, and yawRate will be equivalent to x

#include "Ewma.h"
#include "utils.h"
#pragma once

#include "utils/datatypes.h"
#include "utils/Ewma.h"

/// @brief this object tracks attitude/orientation as well as gyroscope calibration values
class Attitude {
Expand Down
35 changes: 35 additions & 0 deletions main/config/birdbrain.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*****************************************************************************
* This file is for any settings or constants that may be manually adjusted
* specific to the Birdbrain flight computer
****************************************************************************/
#pragma once

//tick times (microseconds)
constexpr uint32_t TICK_TIME_ONPAD = 10000;
constexpr uint32_t TICK_TIME_ASCENDING = 10000;
constexpr uint32_t TICK_TIME_DESCENDING = 50000;
constexpr uint32_t TICK_TIME_POST_FLIGHT = 1000000;

constexpr uint32_t GPS_WAIT_TIME = 900; //number of seconds to wait for GPS to acquire signal before moving on

constexpr uint32_t RING_QUEUE_LENGTH = 1000;//each 100 elements is 1 seconds of data at 100hz

// pin definitions
constexpr int BMP_CS = 7; //SPI chipSelect of bmp altimeter
constexpr int BUILTIN_SDCARD = 9; // SPI chipSelect of SD card
constexpr int RADIO_CS = 8; //SPI chipSelect of radio module
constexpr int IMU_CS = 6; //SPI chipSelect of IMU
constexpr int SPI0_SCK = 2; //SPI clock pin
constexpr int SPI0_MOSI = 3; //SPI MOSI pin
constexpr int SPI0_MISO = 4; //SPI MISO pin
constexpr int SPI1_SCK = 10;
constexpr int SPI1_MOSI = 11;
constexpr int SPI1_MISO = 12;
constexpr int BUZZER_PIN = 26;
constexpr int PYRO0_PIN = 14;
constexpr int PYRO1_PIN = 15;

constexpr int TONE_HZ = 2500; //frequency of buzzer tone

#define GPSSerial Serial1 //Hardware Serial Location of GPS
#define XBeeSerial Serial //Hardware Serial Location of XBee
31 changes: 16 additions & 15 deletions main/settings.h → main/config/catalyst2.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
/*****************************************************************************
* This file is for any settings or constants that may be manually adjusted
*
* specific to the Catalyst-2 flight computer
****************************************************************************/
#pragma once

#ifndef UNIT_TEST
#include <Arduino.h>
#else
#include "../test/lib/mock_arduino.h"
#endif // UNIT_TEST

//tick times (microseconds)
constexpr uint32_t TICK_TIME_ONPAD = 10000;
constexpr uint32_t TICK_TIME_ASCENDING = 10000;
Expand All @@ -18,14 +12,21 @@ constexpr uint32_t TICK_TIME_POST_FLIGHT = 1000000;

constexpr uint32_t GPS_WAIT_TIME = 300; //number of seconds to wait for GPS to acquire signal before moving on

constexpr uint32_t RING_QUEUE_LENGTH = 3000;//each 100 elements is 1 second of data at 100hz

// pin definitions
constexpr int BMP_CS = 10; //SPI chipSelect of bmp altimeter
#ifdef PICO
#define GPSSerial Serial1 //Hardware Serial Location of GPS
#define XBeeSerial Serial //Hardware Serial Location of XBee
constexpr uint32_t RING_QUEUE_LENGTH = 1000;//each 100 elements is 1 seconds of data at 100hz
#else
constexpr int SPI0_SCK = 11; //SPI clock pin (used for built in SD card)
constexpr int SPI0_MOSI = 12; //SPI MOSI pin
constexpr int SPI0_MISO = 13; //SPI MISO pin
constexpr int SPI1_SCK = SPI0_SCK;
constexpr int SPI1_MOSI = SPI0_MOSI;
constexpr int SPI1_MISO = SPI0_MISO;
constexpr int BUZZER_PIN = 33;
constexpr int PYRO0_PIN = 34;
constexpr int PYRO1_PIN = 35;

constexpr int TONE_HZ = 1000; //frequency of buzzer tone

#define XBeeSerial Serial1 //Hardware Serial Location of XBee
#define GPSSerial Serial2 //Hardware Serial Location of GPS
constexpr uint32_t RING_QUEUE_LENGTH = 3000;//each 100 elements is 1 seconds of data at 100hz
#endif // PICO
constexpr int BUZZER_PIN = 33;
24 changes: 24 additions & 0 deletions main/config/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*****************************************************************************
* This file is for any settings or constants that may be manually adjusted
* not specific to any hardware architecture
* all hardware specific settings should be in their own file
*
* all hardware architectures should be conditionally included here
****************************************************************************/
#pragma once

#ifdef UNIT_TEST
#include "../test/lib/mock_arduino.h"
#else
#include <Arduino.h>
#endif // UNIT_TEST

#if defined(BIRDBRAIN)
#include "config/birdbrain.h"
#elif defined(CATALYST2)
#include "config/catalyst2.h"
#endif

constexpr double MAIN_ALTITUDE = 200; //altitude to deploy main parachute at (meters)
constexpr double G_FORCE_TO_LAUNCH = 2; //if acceleration exceeds this number the rocket will assume it has been launched
constexpr double MAX_APOGEE_ACCEL = 1; //we can rule out apogee if acceleration is above this amount (Gs)
99 changes: 65 additions & 34 deletions main/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
* This file is for saving and transmitting data
* currently using an SD card and Xbee respectively
****************************************************************************/
#include "ringQueue.h"
#include "settings.h"
#include "utils.h"
#pragma once

#include "config/config.h"
#include "utils/datatypes.h"
#include "utils/ringQueue.h"

#include <SD.h>

#ifndef PICO
const int CS_SD = BUILTIN_SDCARD;
#else
const int CS_SD = 15;
#endif // PICO

char filename[50];
RingQueue<imuReading> imuQueue;
Expand Down Expand Up @@ -56,7 +55,7 @@ void setupSD(String date){
}
else
XBeeSerial.println("MicroSD card: successful");
String filestart = "Catalyst2-";
String filestart = "Stimulant-";
filestart.concat(date);
filestart.concat(".csv");
filestart.toCharArray(filename, 50);
Expand All @@ -67,6 +66,9 @@ void setupSD(String date){
}
else {
XBeeSerial.println("MicroSD card: error opening file");
XBeeSerial.print("Filename: ");
XBeeSerial.println(filename);
delay(5000);
}
}

Expand Down Expand Up @@ -112,7 +114,9 @@ void recordData(gpsReading sample, bool prelaunch){
*
*/
void backupToSD(){
XBeeSerial.println("backing up...");
File dataFile = SD.open(filename, FILE_WRITE);
char buffer[50];
if(!dataFile){
XBeeSerial.println("error opening datalog");
return;
Expand Down Expand Up @@ -140,27 +144,45 @@ void backupToSD(){
gpsQueue.dequeue();
}
}
dataFile.print(imuSample.time); dataFile.print(',');
if(altitude != 0)
dataFile.print(altitude, 1);
itoa(imuSample.time,buffer,10);
dataFile.print(buffer); dataFile.print(',');
if(altitude != 0) {
dtostrf(altitude, 6, 1, buffer);
dataFile.print(buffer);
}
dataFile.print(',');
if(latitude != 0)
dataFile.print(latitude, 4);
if(latitude != 0) {
dtostrf(latitude, 6, 4, buffer);
dataFile.print(buffer);
}
dataFile.print(',');
if(longitude != 0)
dataFile.print(longitude, 4);
if(longitude != 0) {
dtostrf(longitude, 6, 4, buffer);
dataFile.print(buffer);
}
dataFile.print(',');
dataFile.print(imuSample.gyro.x); dataFile.print(',');
dataFile.print(imuSample.gyro.y); dataFile.print(',');
dataFile.print(imuSample.gyro.z); dataFile.print(',');
dataFile.print(imuSample.accel.x); dataFile.print(',');
dataFile.print(imuSample.accel.y); dataFile.print(',');
dataFile.print(imuSample.accel.z); dataFile.print(',');
dataFile.print(imuSample.attitude.x); dataFile.print(',');
dataFile.print(imuSample.attitude.y); dataFile.print(',');
dataFile.print(imuSample.attitude.z); dataFile.print(',');
if(altitude != 0)
dataFile.print(state);
dtostrf(imuSample.gyro.x, 8, 4, buffer);
dataFile.print(buffer); dataFile.print(',');
dtostrf(imuSample.gyro.y, 8, 4, buffer);
dataFile.print(buffer); dataFile.print(',');
dtostrf(imuSample.gyro.z, 8, 4, buffer);
dataFile.print(buffer); dataFile.print(',');
dtostrf(imuSample.accel.x, 8, 4, buffer);
dataFile.print(buffer); dataFile.print(',');
dtostrf(imuSample.accel.y, 8, 4, buffer);
dataFile.print(buffer); dataFile.print(',');
dtostrf(imuSample.accel.z, 8, 4, buffer);
dataFile.print(buffer); dataFile.print(',');
dtostrf(imuSample.attitude.x, 8, 4, buffer);
dataFile.print(buffer); dataFile.print(',');
dtostrf(imuSample.attitude.y, 8, 4, buffer);
dataFile.print(buffer); dataFile.print(',');
dtostrf(imuSample.attitude.z, 8, 4, buffer);
dataFile.print(buffer); dataFile.print(',');
if(altitude != 0) {
itoa(state,buffer,10);
dataFile.print(buffer);
}
dataFile.println(',');
}
while(!bmpQueue.isEmpty()){
Expand All @@ -176,13 +198,20 @@ void backupToSD(){
gpsQueue.dequeue();
}
}
dataFile.print(bmpSample.time); dataFile.print(',');
dataFile.print(bmpSample.altitude, 1); dataFile.print(',');
if(latitude != 0)
dataFile.print(latitude, 4);
itoa(bmpSample.time,buffer,10);
dataFile.print(buffer); dataFile.print(',');
dtostrf(bmpSample.altitude, 6, 1, buffer);
dataFile.print(buffer); dataFile.print(',');
if(latitude != 0) {
dtostrf(latitude, 6, 4, buffer);
dataFile.print(buffer);
}
dataFile.print(',');
if(longitude != 0) {
dtostrf(longitude, 6, 4, buffer);
dataFile.print(buffer);
}
dataFile.print(',');
if(longitude != 0)
dataFile.print(longitude, 4);
dataFile.print(',');
dataFile.print(',');
dataFile.print(',');
Expand All @@ -193,8 +222,10 @@ void backupToSD(){
dataFile.print(',');
dataFile.print(',');
dataFile.print(',');
dataFile.print(bmpSample.state);
itoa(bmpSample.state,buffer,10);
dataFile.print(buffer);
dataFile.println(',');
}
dataFile.close();
dataFile.close();
XBeeSerial.println("back up complete");
}
Loading

0 comments on commit ee9173b

Please sign in to comment.