Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Garibaldi Integration! #190

Draft
wants to merge 23 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion avionics/common/include/buzzer_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
enum SongTypes {
SongTypes_SUCCESS,
SongTypes_NONCRITFAIL,
SongTypes_CRITICALFAIL
SongTypes_CRITICALFAIL,
SongTypes_LANDED,
};

/*Classes--------------------------------------------------------------*/
Expand Down
26 changes: 13 additions & 13 deletions avionics/common/include/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
/*Constants------------------------------------------------------------*/
// Double, triple check pin assignments
enum class Pin {
POWER_LED = 33, // kept in one place w/ FLIGHT_LED
FLIGHT_LED = 33, // required by state machine
BUILTIN_LED = 31, // PC13
STATUS_LED = 31, // uses BUILTIN_LED
BUZZER = 25, // PB9
MAIN_IGNITOR = 20, // PB4
MAIN_CONTINUITY_TEST = 33,
MAIN_CONTINUITY_READ = 200, // PB_0
DROGUE_IGNITOR = 15, // PA15
DROGUE_CONTINUITY_TEST = 33,
DROGUE_CONTINUITY_READ = 193, // PA_1
VOLTAGE_SENSOR = 33, // PC15 (unused)
SD_CHIP_SELECT = 196, // PA_4
// POWER_LED = 0, // N/A on Rev 2 board
// FLIGHT_LED = 0, // N/A on Rev 2 board
BUILTIN_LED = 33, // PC6
STATUS_LED = 33, // PC6, uses BUILTIN_LED
BUZZER = 41, // PB15
MAIN_IGNITOR = 14, // PB9, TODO!
MAIN_CONTINUITY_TEST = 2, // PA10, TODO!
MAIN_CONTINUITY_READ = 2, // PA10, TODO!
DROGUE_IGNITOR = 15, // PB8, TODO!
DROGUE_CONTINUITY_TEST = 8, // PA9, TODO!
DROGUE_CONTINUITY_READ = 8, // PA9, TODO!
VOLTAGE_SENSOR = 42, // PB14, unused
SD_CHIP_SELECT = 31, // PC9
};

/*Functions------------------------------------------------------------*/
Expand Down
28 changes: 20 additions & 8 deletions avionics/common/include/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,33 @@
Defined logging levels. Usage:
LOG_WARN("Warning message; warning code: " << 123 << " addnl string")
*/
#ifndef LOG_CONTROL_DISABLE_LOGGING
#ifdef LOG_CONTROL_DISABLE_LOGGING // LOG_CONTROL_DISABLE_LOGGING

#define LOG_DEBUG(expr)
#define LOG_INFO(expr)
#define LOG_WARN(expr)
#define LOG_ERROR(expr)

#else // LOG_CONTROL_DISABLE_LOGGING

// This is kinda a hack to get logging through serial
#ifdef LOG_CONTROL_SERIAL_LOGGING // LOG_CONTROL_SERIAL_LOGGING

#define LOG_DEBUG(expr) Serial.print("DEBUG: "); Serial.println(expr)
#define LOG_INFO(expr) Serial.print("INFO: "); Serial.println(expr)
#define LOG_WARN(expr) Serial.print("WARN: "); Serial.println(expr)
#define LOG_ERROR(expr) Serial.print("ERROR: "); Serial.println(expr)

#else // LOG_CONTROL_SERIAL_LOGGING

#define LOG_DEBUG(expr) LOG_AT_SPECIFIED_LEVEL(rktlog::Level::kDebug, expr)
#define LOG_INFO(expr) LOG_AT_SPECIFIED_LEVEL(rktlog::Level::kInfo, expr)
#define LOG_WARN(expr) LOG_AT_SPECIFIED_LEVEL(rktlog::Level::kWarn, expr)
#define LOG_ERROR(expr) LOG_AT_SPECIFIED_LEVEL(rktlog::Level::kErr, expr)

#else // LOG_CONTROL_DISABLE_LOGGING

#define LOG_DEBUG(expr)
#define LOG_INFO(expr)
#define LOG_WARN(expr)
#define LOG_ERROR(expr)
#endif // LOG_CONTROL_SERIAL_LOGGING

#endif // LOG_CONTROL_DISABLE_LOGGING
#endif // LOG_CONTROL_DISABLE_LOGGING

// Log at a specified level. Strongly recommended to instead use the defined log
// level macros instead of this.
Expand Down
6 changes: 5 additions & 1 deletion avionics/common/include/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@
#define BODY // enable or disable body-avionics specific functionality
// #define SERVO //if drogue release utilizes CO2 canister
#define POW // if drogue release utilizes black powder charge
// #define TESTING //enable or disable debug output
#define TESTING //enable or disable debug output
// #define GROUND_TEST

// #define THERMOCOUPLE // if thermocouple is utilized or not

// Set the serial port to use UART5
#undef Serial
#define Serial Serial5

// Refer to README or the wiki for more information.
1 change: 1 addition & 0 deletions avionics/common/include/radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class Radio {
*/
template <typename Actor>
static void forwardCommand(Actor &command_receiver) {
return; // Hack to get this to work
static_assert(
can_receive_command<Actor>::value,
"act_upon does not have the expected signature void(uint8_t)");
Expand Down
2 changes: 1 addition & 1 deletion avionics/common/include/rocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CommandReceiver {
CommandReceiver(Rocket &rocket) : rocket_(rocket) {}

/**
* @brief performs some action depedning on the information from sensors based on command
* @brief performs some action depedning on the information from sensors based on command
* @param command selects which information is sent
*/
void run_command(Radio::command_t command) {
Expand Down
12 changes: 6 additions & 6 deletions avionics/common/include/state_machine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class StateMachine {

/**
* @brief Construct a new State Machine object
* @param map
* @param initial_state_
* @param map
* @param initial_state_
*/
StateMachine(StateMap map, StateId initial_state_)
: current_id_(initial_state_), state_map_(map) {
Expand All @@ -41,10 +41,10 @@ class StateMachine {
IState *current_state = state_map_[old_id];
const StateId new_id = current_state->getNewState(calc);
if (new_id != old_id) {
LOG_INFO("State changed (previous state "
<< static_cast<std::int32_t>(old_id) << ", new state "
<< static_cast<std::int32_t>(new_id) << ", time is "
<< static_cast<std::int32_t>(Hal::millis()) << "ms)");
LOG_INFO(("State changed (previous state "
+ std::to_string(static_cast<std::int32_t>(old_id)) + ", new state "
+ std::to_string(static_cast<std::int32_t>(new_id)) + ", time is "
+ std::to_string(static_cast<std::int32_t>(Hal::millis())) + "ms)").c_str());
state_map_[new_id]->onEntry();
Radio::sendState(Hal::tpoint_to_uint(Hal::now_ms()),
static_cast<uint16_t>(new_id));
Expand Down
5 changes: 5 additions & 0 deletions avionics/common/include/states/landed.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "cameras.h"
#include "scheduler.hpp"
#include "state_interface.h"
#include "buzzer.h"

namespace State {

Expand All @@ -28,6 +29,10 @@ class Landed : public IState {
* codes and used states. Note that the returned code may be the same state.
*/
StateId getNewState(Calculator const &) { return StateId::LANDED; }

void onEntry() override {
Scheduler::scheduleTask(Hal::now_ms() + Hal::ms(1), static_cast<int>(TaskID::BuzzerBeacon));
}
};

} // namespace State
28 changes: 28 additions & 0 deletions avionics/common/include/tasks/landed_buzzer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Landed Buzzer
*
* @file landed_buzzer.hpp
* @author UBC Rocket Avionics 2023/2024
* @description Class that allows landed buzzer to be run within a task
*/

#pragma once

/*Includes------------------------------------------------------------*/
#include "HAL/time.h"
#include "buzzer.h"

class LandedBuzzer {

private:
Buzzer buzzer_;

public:
LandedBuzzer(Buzzer &buzzer) : buzzer_(buzzer) {}

// run function to be called by a task
static void run(void *self) {
reinterpret_cast<LandedBuzzer *>(self)->buzzer_.sing(SongTypes_LANDED);
}
static constexpr Hal::ms freq{500};
};
6 changes: 4 additions & 2 deletions avionics/common/include/tasks/main_tasks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ReadEvalLog {
* @brief polss sensors, logs data, and updates state machine
*/
void run() {
LOG_DEBUG("ReadEvalLog task started");
auto &state_machine = rocket_.state_machine;
auto &init_status = rocket_.init_status;
auto &sensors = rocket_.sensors;
Expand All @@ -43,7 +44,7 @@ class ReadEvalLog {
std::tie(old_state, new_state) = state_machine.update(calc);
if (old_state != new_state) {
// state transition has occurred

// if (new_state == StateId::MAIN_DESCENT) {
// // restart the camera periodically once in main descent
// Scheduler::scheduleTask(
Expand Down Expand Up @@ -88,7 +89,7 @@ class RadioTxBulk {

/**
* @brief Construct a new Radio Tx Bulk object
* @param rkt
* @param rkt
*/
RadioTxBulk(Rocket &rkt) : rocket(rkt) {}
static constexpr Hal::ms freq{500};
Expand All @@ -99,6 +100,7 @@ class RadioTxBulk {
* @brief sends bulk sensor data
*/
void run() {
LOG_DEBUG("RadioTxBulk task started");
StateId state = rocket.state_machine.getState();
Radio::sendBulkSensor(
Hal::tpoint_to_uint(rocket.sensors.last_poll_time()),
Expand Down
32 changes: 23 additions & 9 deletions avionics/common/src/avionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "tasks/led_blinker.hpp"
#include "tasks/main_tasks.hpp"
#include "tasks/restart_camera.hpp"
#include "tasks/landed_buzzer.hpp"

#include "radio.h"
#include "rocket.h"
Expand Down Expand Up @@ -53,7 +54,7 @@ void registerTask(TaskID id, Scheduler::Task task, bool repeat = true,
int main(void) {
// Initialize Arduino
init();

// Before anything else there's some environment specific setup to be done
env_initialize();
LOG_INFO("Everything is starting now");
Expand All @@ -67,11 +68,13 @@ int main(void) {
while (!Serial) {
Hal::digitalWrite(Pin::BUILTIN_LED, Hal::PinDigital::HI);
Hal::sleep_ms(100);
Hal::digitalWrite(Pin::BUILTIN_LED, Hal::PinDigital::LO);
Hal::digitalWrite(Pin::BUILTIN_LED, Hal::PinDigital::LO);
Hal::sleep_ms(100);
}
Serial.println("Initializing...");
}
Hal::sleep_ms(1000);
Serial.println("[ TESTING MODE ]");
#endif
Serial.println("Initializing...");

Radio::initialize();
LOG_INFO("Initialized radio");
Expand All @@ -83,6 +86,15 @@ int main(void) {
auto &sensors = rocket.sensors;
auto &ignitors = rocket.ignitors;

if (rocket.datalog.ok()) {
Serial.println("Datalogging initialized");
} else {
Serial.println("Datalogging failed to initialize");
}

// Create instance of landed buzzer
LandedBuzzer landedBuzzer(rocket.buzzer);

if (init_status == RocketStatus::CRITICAL_FAILURE) {
LOG_ERROR("Critical failure; aborting in state machine");
state_machine.abort();
Expand All @@ -94,11 +106,12 @@ int main(void) {
/* Register all tasks */
typedef Scheduler::Task Task;

// Read sensors, evaluate state, log data, and send status
ReadEvalLog read_eval_logger(rocket);
Task read_eval_log(ReadEvalLog::run, &read_eval_logger, Hal::ms(50));
registerTask(TaskID::ReadEvalLog, read_eval_log);

// Radio needs to be scheduled later; sensors need to be read first
// // Radio needs to be scheduled later; sensors need to be read first
RadioTxBulk radio_txer(rocket);
Task radio_tx(RadioTxBulk::run, &radio_txer, RadioTxBulk::freq);
Scheduler::preregisterTask(static_cast<int>(TaskID::RadioTxBulk), radio_tx,
Expand All @@ -107,11 +120,12 @@ int main(void) {
static_cast<int>(TaskID::RadioTxBulk));

Task led_blink(LEDBlinker::toggle, nullptr, LEDBlinker::freq);
registerTask(TaskID::LEDBlinker, led_blink);

displayStatus(init_status, rocket.buzzer);
if (init_status == RocketStatus::NONCRITICAL_FAILURE) {
registerTask(TaskID::LEDBlinker, led_blink);
}
// displayStatus(init_status, rocket.buzzer);
// if (init_status == RocketStatus::NONCRITICAL_FAILURE) {
// registerTask(TaskID::LEDBlinker, led_blink);
// }

// RestartCamera restart_camera_(rocket.cam);
// // This tasks sets its own reschedule interval (since the same task is run
Expand Down
8 changes: 4 additions & 4 deletions avionics/common/src/gpio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@
*/
void initPins(void) {
/* Initialize and startup power status LEDs */
Hal::pinMode(Pin::POWER_LED, Hal::PinMode::OUTPUT);
Hal::digitalWrite(Pin::POWER_LED, Hal::PinDigital::HI);
// Hal::pinMode(Pin::POWER_LED, Hal::PinMode::OUTPUT);
// Hal::digitalWrite(Pin::POWER_LED, Hal::PinDigital::HI);

/* Initialize and startup flight status LEDs */
Hal::pinMode(Pin::FLIGHT_LED, Hal::PinMode::OUTPUT);
Hal::digitalWrite(Pin::FLIGHT_LED, Hal::PinDigital::LO);
// Hal::pinMode(Pin::FLIGHT_LED, Hal::PinMode::OUTPUT);
// Hal::digitalWrite(Pin::FLIGHT_LED, Hal::PinDigital::LO);

/* Initialize status LED - writing is performed in acutal status evaluation
*/
Expand Down
14 changes: 7 additions & 7 deletions avionics/common/src/hardware/ignitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ Ignitor::Ignitor(Pin ignitePin, Pin continuityPin, Pin continuityADCPin)
int continuity = Hal::analogRead(continuityADCPin_);

#ifdef TESTING
Serial.print("Continuity read for ignitor on pin ");
Serial.print("Continuity read for ignitor on pin ");
Serial.print(static_cast<uint8_t>(ignitePin_));
Serial.print(": ");
Serial.print(": ");
Serial.println(continuity);
#endif


if (continuity <= DISCONTINUOUS_THRESHOLD) {
status = HardwareStatus::FAILURE;
Expand All @@ -41,7 +41,7 @@ void Ignitor::fire() {
// different ignitions.
Radio::sendEvent(Hal::tpoint_to_uint(Hal::now_ms()),
EventId::IGNITOR_FIRED);
LOG_INFO("Firing ignitor at pin "
<< static_cast<int>(ignitePin_) << " at time "
<< static_cast<std::int32_t>(Hal::millis()) << "ms");
}
LOG_INFO(("Firing ignitor at pin " +
std::to_string(static_cast<int>(ignitePin_)) + " at time " +
std::to_string(static_cast<std::int32_t>(Hal::millis())) + "ms").c_str());
}
4 changes: 2 additions & 2 deletions avionics/common/src/ignitor_collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ IgnitorCollection::IgnitorCollection()
Serial.println("Main parachute ignitor failed");
#endif

LOG_ERROR("Broken ignitor for main parachute");
// LOG_ERROR("Broken ignitor for main parachute");
status_bitfield_[0] |= 0x80;
// status_ = RocketStatus::CRITICAL_FAILURE;
}
Expand All @@ -30,7 +30,7 @@ IgnitorCollection::IgnitorCollection()
Serial.println("Drogue parachute ignitor failed");
#endif

LOG_ERROR("Broken ignitor for drogue parachute");
// LOG_ERROR("Broken ignitor for drogue parachute");
status_bitfield_[0] |= 0x40;
// status_ = RocketStatus::CRITICAL_FAILURE;
}
Expand Down
4 changes: 2 additions & 2 deletions avionics/common/src/sensor_collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ constexpr char SensorCollection::LOG_FILE_HEADER[];
SensorCollection::SensorCollection()
: barometer(BEGIN + BAROMETER_INDEX),
gps(Hal::SerialInst::GPS, BEGIN + GPS_INDEX),
accelerometer(BEGIN + ACCEL_INDEX),
accelerometer(BEGIN + ACCEL_INDEX),
imuSensor(BEGIN + IMU_INDEX),
// battery(Pin::VOLTAGE_SENSOR, BEGIN + BATTERY_INDEX), // No voltage sensor for 2022/23
temperature(BEGIN + TEMP_INDEX) {

updateStatus();
}

Expand Down
3 changes: 2 additions & 1 deletion avionics/envs/board/include/log_control.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef LOG_CONTROL_HPP_69AACC47E45A456AB18C82C1F98F5B7B
#define LOG_CONTROL_HPP_69AACC47E45A456AB18C82C1F98F5B7B

#define LOG_CONTROL_DISABLE_LOGGING
// #define LOG_CONTROL_DISABLE_LOGGING
#define LOG_CONTROL_SERIAL_LOGGING

#endif
Loading