Skip to content

Commit

Permalink
Chovy 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rehaanahmad2013 committed May 2, 2023
1 parent 29cd853 commit ad34233
Show file tree
Hide file tree
Showing 16 changed files with 121,811 additions and 31 deletions.
3 changes: 2 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[platformio]
boards_dir = boards
default_envs = quail
default_envs = chovy

[env]
lib_archive = no

lib_compat_mode = off
lib_ldf_mode = chain+
platform = atmelsam
Expand Down
10 changes: 5 additions & 5 deletions src/chovy/AltimeterTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ void AltimeterTask::activity()
tasks_json[tasks[i].pcTaskName] = percent;
}

TwoBattery::two_cell_voltage_t srad = sys.srad_batt.readVoltage();
HackBattery::one_cell_voltage_t srad = sys.srad_batt.readVoltage();
HackBattery::one_cell_voltage_t cots = sys.cots_batt.readVoltage();

battData_srad.post(srad);
battData_cots.post(cots);

JsonObject bat_json = status_json.createNestedObject("bat");
bat_json["sradA"] = srad.cellA;
bat_json["sradB"] = srad.cellB;
bat_json["sradA"] = srad.cell;
bat_json["cots"] = cots.cell;

status_json["log"] = sys.tasks.logger.isLoggingEnabled();
Expand All @@ -65,8 +64,9 @@ void AltimeterTask::activity()
pyro_json.add(pyroC);
pyro_json.add(pyroD);

sys.tasks.logger.logJSON(status_json, "status");

// if (!sys.shitl) {
sys.tasks.logger.logJSON(status_json, "status");
// }
digitalWrite(ALT_LED, false);
}
}
3 changes: 1 addition & 2 deletions src/chovy/AltimeterTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <semphr.h>
#include <hal_rtos.h>
#include "Poster.hpp"
#include "./periph/TwoBattery/TwoBattery.hpp"
#include "./periph/HackBattery/HackBattery.hpp"
#include "Task.hpp"

Expand All @@ -18,7 +17,7 @@ class AltimeterTask : Task<2000>

public:
AltimeterTask(uint8_t priority);
Poster<TwoBattery::two_cell_voltage_t> battData_srad;
Poster<HackBattery::one_cell_voltage_t> battData_srad;
Poster<HackBattery::one_cell_voltage_t> battData_cots;

};
Expand Down
3 changes: 1 addition & 2 deletions src/chovy/Packet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ typedef struct __attribute__((__packed__)) rf_down_t

unsigned time : 18;

unsigned batt_srad_A : 8;
unsigned batt_srad_B : 8;
unsigned batt_srad : 8;
unsigned batt_cots : 8;

unsigned state : 3;
Expand Down
1 change: 0 additions & 1 deletion src/chovy/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ int main(void)
pinMode(28,OUTPUT);
pinMode(29,INPUT);


//start all RTOS tasks (this never returns)
vTaskStartScheduler();
}
5 changes: 2 additions & 3 deletions src/chovy/System.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class System;
#include "TelemetryTask.hpp"
#include "RadioTask.hpp"
#include "ArmingTask.hpp"
#include "../periph/TwoBattery/TwoBattery.hpp"
#include "../periph/HackBattery/HackBattery.hpp"

#include "ssi_adc.h"
Expand All @@ -39,8 +38,8 @@ class System
Pyro &pyro = pyrosquib;

ADC adc0 = ADC(ADC0);
TwoBattery srad_batt = TwoBattery(adc0,13,14);
HackBattery cots_batt = HackBattery(adc0,15);
HackBattery srad_batt = HackBattery(adc0, 13);
HackBattery cots_batt = HackBattery(adc0, 14);

Tone buzzer = Tone(5);

Expand Down
5 changes: 2 additions & 3 deletions src/chovy/TelemetryTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void TelemetryTask::activity()
if (sys.tasks.radio.isIdle())
{
gps_data_t data = sys.tasks.gps.locationData;
TwoBattery::two_cell_voltage_t srad = sys.tasks.alt.battData_srad;
HackBattery::one_cell_voltage_t srad = sys.tasks.alt.battData_srad;
HackBattery::one_cell_voltage_t cots = sys.tasks.alt.battData_cots;

rf_down_t down_packet;
Expand All @@ -40,8 +40,7 @@ void TelemetryTask::activity()
down_packet.filter_alt = compressFloat(sys.tasks.filter.filter.p_alt, -2000.0, 40000.0, 15);
down_packet.filter_vel = compressFloat(sys.tasks.filter.filter.p_vel, -1000.0, 1000.0, 11);

down_packet.batt_srad_A = compressFloat(srad.cellA, 1.0, 6.0, 8);
down_packet.batt_srad_B = compressFloat(srad.cellB, 1.0, 6.0, 8);
down_packet.batt_srad = compressFloat(srad.cell, 1.0, 6.0, 8);
down_packet.batt_cots = compressFloat(cots.cell, 1.0, 6.0, 8);

down_packet.lat = compressFloat(data.lat, 0.0, 10.0, 18);
Expand Down
4 changes: 3 additions & 1 deletion src/fc/AltFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void AltFilter::prefilter(SensorData& data){
}

Z(0) = p2alt(pres); //LOL gotta convert to meters oops
Z(1) = (data.adxl1_data.y) - 9.807; //Antenna connector facing up, ematch connector down
Z(1) = (data.adxl2_data.x * -1.0) - 9.807; //Antenna connector facing up, ematch connector down
//Z(1) = (data.adxl1_data.y * -1.0) - 9.807; //Antenna connector facing down, ematch connector up

//NEGATIVE! If the accelerometers read -9.8 (raw from the sensor) when the rocket is vertical,
Expand All @@ -105,5 +105,7 @@ void AltFilter::logState(){
JsonArray z_json = json.createNestedArray("z");
z_json.add(Z(0));
z_json.add(Z(1));
// if (!sys.shitl) {
sys.tasks.logger.logJSON(json, "filter_state");
// }
}
10 changes: 10 additions & 0 deletions src/fc/AltFilterTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ void AltFilterTask::activity()
digitalWrite(4, true);
filter.update(data);
plan.update(filter);
if (sys.shitl) {
// Serial.println("in shitl");
StaticJsonDocument<500> json;
json["tick"] = 0;
JsonArray x_json = json.createNestedArray("alt");
x_json.add(filter.getAltitude());
JsonArray z_json = json.createNestedArray("vel");
z_json.add(filter.getVelocity());
sys.tasks.logger.logJSON(json, "altitude");
}
digitalWrite(4, false);
}
}
2 changes: 2 additions & 0 deletions src/fc/LoggerTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ void LoggerTask::activity()

char *p = lineBuffer;
TickType_t timeout = 0;
uint32_t shitltimer = xTaskGetTickCount();
while (true)
{
//Step 1: read in all the logs
Expand Down Expand Up @@ -184,6 +185,7 @@ void LoggerTask::activity()
}
else
{ //if timeout is NEVER, we don't ever reach this (no SHITL)
vTaskDelayUntil(&shitltimer, 10);
readSHITL();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/guppy/AltimeterTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ void AltimeterTask::activity()

pyro_json.add(pyroA);
pyro_json.add(pyroB);

// if (!sys.shitl){
sys.tasks.logger.logJSON(status_json, "status");

digitalWrite(ALT_LED, false);
}
}
4 changes: 4 additions & 0 deletions src/guppy/GPSTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,18 @@ void GPSTask::activity()
gps_json["alt"] = parser.altitude.meters();
gps_json["sat"] = parser.satellites.value();
gps_json["failed"] = parser.failedChecksum();
// if (!sys.shitl){
sys.tasks.logger.logJSON(gps_json, "gps");
// }
updateTimer = xTaskGetTickCount();
}
else if ((xTaskGetTickCount() - updateTimer) > 1000)
{
StaticJsonDocument<1024> gps_json;
gps_json["updated"] = false;
// if (!sys.shitl){
sys.tasks.logger.logJSON(gps_json, "gps");
// }
updateTimer = xTaskGetTickCount();
}
}
Expand Down
17 changes: 12 additions & 5 deletions src/guppy/RadioTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ void RadioTask::activity()
logStats();
time = xTaskGetTickCount();
}

// Serial.println("before first waitbit");
uint32_t flags = xEventGroupWaitBits(evgroup, 0b11, true, false, NEVER);
// Serial.println("after first waitbit");
uint16_t irq = lora.getIrqStatus();
lora.clearIrqStatus();

Expand All @@ -118,9 +119,9 @@ void RadioTask::activity()
{
log(info, "Preamble");
uint32_t time = lora.symbolToMs(32); //time of a packet header

// Serial.println("before second waitbit");
flags = xEventGroupWaitBits(evgroup, 0b01, true, false, time); //wait for another radio interupt for 500ms

// Serial.println("after second waitbit");
if (!(flags & 0b01))
{
log(warning, "Missed Header");
Expand All @@ -136,8 +137,9 @@ void RadioTask::activity()
{
log(info, "wait RxDone");
uint32_t time = lora.getTimeOnAir(255) / 1000; //TODO: read this out of the header to make timeout tighter
// Serial.println("before third wait bit");
flags = xEventGroupWaitBits(evgroup, 0b01, true, false, time); //wait for radio interupt for 500ms

// Serial.println("after third wait bit");
if (!(flags & 0b01))
{
log(warning, "Missed RxDone");
Expand Down Expand Up @@ -194,7 +196,9 @@ void RadioTask::activity()
lora.standby();
lora.setCad();
uint32_t time = lora.symbolToMs(12) + 50;
// Serial.println("before fourth waitbit");
xEventGroupWaitBits(evgroup, 0b01, true, false, time);
// Serial.println("after fourth waitbit");
irq = lora.getIrqStatus();
lora.clearIrqStatus();
} while (!(irq & SX126X_IRQ_CAD_DONE) || irq & SX126X_IRQ_CAD_DETECTED);
Expand All @@ -207,10 +211,11 @@ void RadioTask::activity()

uint32_t time = lora.getTimeOnAir(packet.len) / 1000; //get TOA in ms
time = (time * 1.1) + 100; //add margin

logPacket("TX", packet);
lora.startTransmit(packet.data, packet.len);
// Serial.println("before fifth waitbit");
flags = xEventGroupWaitBits(evgroup, 0b01, true, false, time);
// Serial.println("after fifth waitbit");
irq = lora.getIrqStatus();
lora.clearIrqStatus();

Expand All @@ -227,7 +232,9 @@ void RadioTask::activity()

lora.startReceive();
time = lora.symbolToMs(32); //this can be tuned
// Serial.println("before sixth waitbit");
xEventGroupWaitBits(evgroup, 0b01, false, false, time); //wait for other radio to get a chance to speak
// Serial.println("after sixth waitbit");
}
else
{
Expand Down

0 comments on commit ad34233

Please sign in to comment.