cleanup
This commit is contained in:
parent
f247a103d2
commit
9e25b917f6
@ -1,26 +0,0 @@
|
||||
#include <SPI.h>
|
||||
#include <nRF24L01.h>
|
||||
#include <RF24.h>
|
||||
RF24 radio(9, 8); // CE, CSN
|
||||
const byte address[6] = "00001"; //address through which two modules communicate
|
||||
|
||||
|
||||
void setup() {
|
||||
while (!Serial)
|
||||
;
|
||||
Serial.begin(9600);
|
||||
Serial.println("#200 Reciever Init");
|
||||
radio.begin();
|
||||
radio.openReadingPipe(0, address); //set the address
|
||||
radio.startListening(); //Set module as receiver
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
//Read the data if available in buffer
|
||||
if (radio.available()) {
|
||||
char text[64] = { 0 };
|
||||
radio.read(&text, sizeof(text));
|
||||
Serial.println(text);
|
||||
}
|
||||
}
|
||||
4
sender/ISSUES.md
Normal file
4
sender/ISSUES.md
Normal file
@ -0,0 +1,4 @@
|
||||
# Problems
|
||||
|
||||
- Arduino Nano Couldn't power up the sd card reader, need to input 5V to micro SD card reader.
|
||||
- Couldn't make Arduino Nano work with nRF24 - maybe same issue
|
||||
26
sender/README.md
Normal file
26
sender/README.md
Normal file
@ -0,0 +1,26 @@
|
||||
# Sender module
|
||||
|
||||
## Stages of flight
|
||||
|
||||
1. Preflight - Remove before flight button or smthing like that
|
||||
- no communication, blocked parachute ejection, all systems down
|
||||
2. Ready - Signal from groundstation
|
||||
- sys check (modules calibration, battery check, atd...), blocked parachute ejection, wait for launch pin removed, only send data, do not save them
|
||||
3. Launch - Removed pin from the rocket
|
||||
- launch, all systems sending and saving data on sd card
|
||||
4. Apogee - Detected that rocket is in apogee with accelerometer
|
||||
- parachute ejection, all systems working, gps check and height check
|
||||
5. Return - Rocket has no velocity
|
||||
- all not needed systems shutdown/sleep, buzz on, gps sending location, battery check, turn off gyro and accelerometer
|
||||
|
||||
## Modules
|
||||
|
||||
- nRF24L01 - Communication with groundstation
|
||||
- SD card reader - Write all recieved data to the SD card
|
||||
- Buzzer - To find our rocket after launch
|
||||
- Servo motors - Ejection of parachute
|
||||
|
||||
## Tasks
|
||||
|
||||
- send signal of listening
|
||||
- wait for recieve
|
||||
263
sender/sender_module_final.ino
Normal file
263
sender/sender_module_final.ino
Normal file
@ -0,0 +1,263 @@
|
||||
#include <SPI.h>
|
||||
#include <SD.h>
|
||||
#include <Servo.h>
|
||||
#include "Arduino_BMI270_BMM150.h"
|
||||
|
||||
const int BUZZER_PIN = 2;
|
||||
const int SERVO_A_PIN = 7;
|
||||
const int CHIP_SELECT = 4;
|
||||
|
||||
// Create objects for modules
|
||||
File dataFile;
|
||||
Servo A;
|
||||
|
||||
// Flight stages
|
||||
enum FlightStage
|
||||
{
|
||||
READY,
|
||||
ARM,
|
||||
ASCENT,
|
||||
DESCENT,
|
||||
LANDED
|
||||
};
|
||||
|
||||
FlightStage current_stage = READY;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Initialize Serial
|
||||
Serial.begin(115200);
|
||||
|
||||
//while (!Serial)
|
||||
// ;
|
||||
//Serial.println("# Welcome to CobraV2");
|
||||
delay(1000);
|
||||
|
||||
pinMode(BUZZER_PIN, OUTPUT);
|
||||
digitalWrite(BUZZER_PIN, LOW);
|
||||
|
||||
A.attach(SERVO_A_PIN);
|
||||
A.write(80);
|
||||
// Start with preflight stage
|
||||
current_stage = READY;
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
switch (current_stage)
|
||||
{
|
||||
case READY:
|
||||
ready_stage();
|
||||
break;
|
||||
case ARM:
|
||||
arm_stage();
|
||||
break;
|
||||
case ASCENT:
|
||||
ascent_stage();
|
||||
break;
|
||||
case DESCENT:
|
||||
descent_stage();
|
||||
break;
|
||||
case LANDED:
|
||||
landed_stage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void beep()
|
||||
{
|
||||
digitalWrite(BUZZER_PIN, HIGH);
|
||||
delay(1000);
|
||||
digitalWrite(BUZZER_PIN, LOW);
|
||||
}
|
||||
|
||||
void ready_stage()
|
||||
{
|
||||
Serial.println("# READY stage");
|
||||
analogWrite(LED_BUILTIN, HIGH);
|
||||
beep();
|
||||
|
||||
if (!IMU.begin())
|
||||
{
|
||||
Serial.println("Failed to initialize IMU!");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
|
||||
// SD card
|
||||
//if (!SD.begin(CHIP_SELECT))
|
||||
//{
|
||||
// Serial.println("# Fail SD module init");
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// Serial.println("# Success SD module init");
|
||||
//}
|
||||
//
|
||||
//if (SD.exists("data.txt"))
|
||||
//{
|
||||
// Serial.println("# File exists");
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// Serial.println("# File does not exist");
|
||||
// dataFile = SD.open("data.txt", FILE_WRITE);
|
||||
//}
|
||||
//
|
||||
//if (dataFile)
|
||||
//{
|
||||
// Serial.println("# File opened");
|
||||
// dataFile.println("# CobraV2 flight data");
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// Serial.println("# Error opening file");
|
||||
//}
|
||||
|
||||
Serial.print("# Accelerometer sample rate = ");
|
||||
Serial.print(IMU.accelerationSampleRate());
|
||||
Serial.println(" Hz");
|
||||
|
||||
//dataFile.print("# Accelerometer sample rate = ");
|
||||
//dataFile.println(IMU.accelerationSampleRate());
|
||||
//dataFile.close();
|
||||
|
||||
current_stage = ARM;
|
||||
}
|
||||
|
||||
void arm_stage()
|
||||
{
|
||||
// System check
|
||||
// Block parachute ejection
|
||||
// Wait for launch pin removed
|
||||
// Start sending data
|
||||
Serial.println("# ARM stage");
|
||||
beep();
|
||||
beep();
|
||||
|
||||
// Accelerometer Gyroscope
|
||||
int counter = 0;
|
||||
float x, y, z;
|
||||
|
||||
bool toggle = false;
|
||||
//dataFile = SD.open("data.txt", FILE_WRITE);
|
||||
//dataFile.println("# ARM stage");
|
||||
while (true)
|
||||
{
|
||||
if (IMU.accelerationAvailable())
|
||||
{
|
||||
IMU.readAcceleration(x, y, z);
|
||||
Serial.print(x);
|
||||
Serial.print(", ");
|
||||
Serial.print(y);
|
||||
Serial.print(", ");
|
||||
Serial.println(z);
|
||||
|
||||
|
||||
//dataFile.print(x);
|
||||
//dataFile.print(" ");
|
||||
//dataFile.print(y);
|
||||
//dataFile.print(" ");
|
||||
//dataFile.println(z);
|
||||
|
||||
if (x > 1)
|
||||
{
|
||||
Serial.println("# Launch Detect");
|
||||
counter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (counter < 15)
|
||||
{
|
||||
Serial.println("# Launching");
|
||||
//dataFile.println("# Launching");
|
||||
break;
|
||||
}
|
||||
|
||||
if (toggle)
|
||||
{
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
}
|
||||
toggle = !toggle;
|
||||
}
|
||||
|
||||
current_stage = ASCENT;
|
||||
//dataFile.close();
|
||||
}
|
||||
|
||||
void ascent_stage()
|
||||
{
|
||||
Serial.println("# ASCENT Stage");
|
||||
unsigned long StartTime = millis();
|
||||
int FailOrientationCounter = 0;
|
||||
//File dataFile = SD.open("data.txt", FILE_WRITE);
|
||||
//dataFile.println("# ASCENT stage");
|
||||
while (true)
|
||||
{
|
||||
unsigned long CurrentTime = millis();
|
||||
unsigned long ElapsedTime = CurrentTime - StartTime;
|
||||
Serial.println(ElapsedTime);
|
||||
|
||||
if (IMU.gyroscopeAvailable())
|
||||
{
|
||||
float x, y, z;
|
||||
IMU.readGyroscope(x, y, z);
|
||||
}
|
||||
|
||||
if ((ElapsedTime > 9000))
|
||||
{
|
||||
dataFile.println("# Apogee detected by time");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
current_stage = DESCENT;
|
||||
//dataFile.close();
|
||||
}
|
||||
|
||||
void descent_stage()
|
||||
{
|
||||
Serial.println("# DESCENT stage");
|
||||
//File dataFile = SD.open("data.txt", FILE_WRITE);
|
||||
//dataFile.println("# DESCENT stage");
|
||||
A.write(80);
|
||||
delay(1000);
|
||||
A.write(180);
|
||||
|
||||
Serial.println("# Parachute deployed");
|
||||
|
||||
unsigned long StartTime = millis();
|
||||
while (true)
|
||||
{
|
||||
unsigned long CurrentTime = millis();
|
||||
unsigned long ElapsedTime = CurrentTime - StartTime;
|
||||
|
||||
if (ElapsedTime > 300000)
|
||||
{
|
||||
//dataFile.println("# Landing detected");
|
||||
break;
|
||||
}
|
||||
}
|
||||
current_stage = LANDED;
|
||||
//dataFile.close();
|
||||
}
|
||||
|
||||
void landed_stage()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Serial.println("# LANDED stage");
|
||||
beep();
|
||||
delay(200);
|
||||
}
|
||||
}
|
||||
20
sender/shell.nix
Normal file
20
sender/shell.nix
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
}:
|
||||
pkgs.callPackage (
|
||||
{
|
||||
mkShell,
|
||||
arduino,
|
||||
arduino-cli,
|
||||
arduino-ide
|
||||
}:
|
||||
mkShell {
|
||||
strictDeps = true;
|
||||
nativeBuildInputs = [
|
||||
arduino
|
||||
arduino-cli
|
||||
arduino-ide
|
||||
];
|
||||
}
|
||||
) { }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user