diff --git a/skyward-boardcore b/skyward-boardcore index ead06db6a21548d24e3004a0027ae19a501bbaf1..3e6454b0287ca280e6095f42607a3074a5670b09 160000 --- a/skyward-boardcore +++ b/skyward-boardcore @@ -1 +1 @@ -Subproject commit ead06db6a21548d24e3004a0027ae19a501bbaf1 +Subproject commit 3e6454b0287ca280e6095f42607a3074a5670b09 diff --git a/src/ConRIG/Buttons/Buttons.cpp b/src/ConRIG/Buttons/Buttons.cpp index 69593bf16c66da2654a62707601071379c650a8f..8390a9494aaeeccff1c67dcba0a204da15672c8c 100644 --- a/src/ConRIG/Buttons/Buttons.cpp +++ b/src/ConRIG/Buttons/Buttons.cpp @@ -32,11 +32,7 @@ using namespace miosix; using namespace Boardcore; using namespace ConRIG; -Buttons::Buttons() -{ - resetState(); - state.arm_switch = false; -} +Buttons::Buttons() : state() {} bool Buttons::start() { @@ -50,18 +46,10 @@ mavlink_conrig_state_tc_t Buttons::getState() { return state; } void Buttons::resetState() { - state.n2o_filling_btn = false; - state.n2o_release_btn = false; - state.n2_filling_btn = false; - state.n2_release_btn = false; - state.n2_detach_btn = false; - state.n2o_venting_btn = false; - state.nitrogen_btn = false; - state.n2o_detach_btn = false; - state.n2_quenching_btn = false; - state.n2_3way_btn = false; - state.tars_btn = false; - state.ignition_btn = false; + // Preserve the arm switch state + auto armSwitch = state.arm_switch; + state = {}; + state.arm_switch = armSwitch; } void Buttons::periodicStatusCheck() @@ -85,9 +73,9 @@ void Buttons::periodicStatusCheck() { if (guard > Config::Buttons::GUARD_THRESHOLD) { - guard = 0; - state.n2o_filling_btn = true; - LOG_DEBUG(logger, "n2o filling button pressed"); + guard = 0; + state.ox_filling_btn = true; + LOG_DEBUG(logger, "ox filling button pressed"); } else { @@ -98,9 +86,9 @@ void Buttons::periodicStatusCheck() { if (guard > Config::Buttons::GUARD_THRESHOLD) { - guard = 0; - state.n2o_release_btn = true; - LOG_DEBUG(logger, "n2o release button pressed"); + guard = 0; + state.ox_release_btn = true; + LOG_DEBUG(logger, "ox release button pressed"); } else { @@ -124,9 +112,9 @@ void Buttons::periodicStatusCheck() { if (guard > Config::Buttons::GUARD_THRESHOLD) { - guard = 0; - state.n2o_venting_btn = true; - LOG_DEBUG(logger, "n2o venting button pressed"); + guard = 0; + state.ox_venting_btn = true; + LOG_DEBUG(logger, "ox venting button pressed"); } else { diff --git a/src/ConRIG/Radio/Radio.cpp b/src/ConRIG/Radio/Radio.cpp index 04a5ab8d19c71297e2d6f0f7067de2e5515aa949..af3e1cf783a54f6658200b941995d4e095973c00 100644 --- a/src/ConRIG/Radio/Radio.cpp +++ b/src/ConRIG/Radio/Radio.cpp @@ -82,19 +82,7 @@ void Radio::handleMessage(const mavlink_message_t& msg) { Lock<FastMutex> lock{buttonsMutex}; // Reset the internal button state - buttonState.n2o_filling_btn = false; - buttonState.n2o_release_btn = false; - buttonState.n2_filling_btn = false; - buttonState.n2_release_btn = false; - buttonState.n2_detach_btn = false; - buttonState.n2o_venting_btn = false; - buttonState.nitrogen_btn = false; - buttonState.n2o_detach_btn = false; - buttonState.n2_quenching_btn = false; - buttonState.n2_3way_btn = false; - buttonState.tars_btn = false; - buttonState.arm_switch = false; - buttonState.ignition_btn = false; + buttonState = {}; } break; @@ -173,19 +161,20 @@ void Radio::setButtonsState(mavlink_conrig_state_tc_t state) Lock<FastMutex> lock{buttonsMutex}; // The OR operator is introduced to make sure that the receiver // understood the command - buttonState.n2o_filling_btn |= state.n2o_filling_btn; - buttonState.n2o_release_btn |= state.n2o_release_btn; + buttonState.ox_filling_btn |= state.ox_filling_btn; + buttonState.ox_release_btn |= state.ox_release_btn; buttonState.n2_filling_btn |= state.n2_filling_btn; buttonState.n2_release_btn |= state.n2_release_btn; buttonState.n2_detach_btn |= state.n2_detach_btn; - buttonState.n2o_venting_btn |= state.n2o_venting_btn; + buttonState.ox_venting_btn |= state.ox_venting_btn; buttonState.nitrogen_btn |= state.nitrogen_btn; - buttonState.n2o_detach_btn |= state.n2o_detach_btn; + buttonState.ox_detach_btn |= state.ox_detach_btn; buttonState.n2_quenching_btn |= state.n2_quenching_btn; buttonState.n2_3way_btn |= state.n2_3way_btn; - buttonState.tars_btn |= state.tars_btn; - buttonState.arm_switch |= state.arm_switch; + buttonState.tars3_btn |= state.tars3_btn; + buttonState.tars3m_btn |= state.tars3m_btn; buttonState.ignition_btn |= state.ignition_btn; + buttonState.arm_switch |= state.arm_switch; } bool Radio::start() @@ -241,19 +230,4 @@ bool Radio::start() MavlinkStatus Radio::getMavlinkStatus() { return mavDriver->getStatus(); } -Radio::Radio() -{ - buttonState.n2o_filling_btn = false; - buttonState.n2o_release_btn = false; - buttonState.n2_filling_btn = false; - buttonState.n2_release_btn = false; - buttonState.n2_detach_btn = false; - buttonState.n2o_venting_btn = false; - buttonState.nitrogen_btn = false; - buttonState.n2o_detach_btn = false; - buttonState.n2_quenching_btn = false; - buttonState.n2_3way_btn = false; - buttonState.tars_btn = false; - buttonState.arm_switch = false; - buttonState.ignition_btn = false; -} +Radio::Radio() : buttonState() {} diff --git a/src/RIGv2/Actuators/Actuators.cpp b/src/RIGv2/Actuators/Actuators.cpp index 4125625826a6f9270b8c9553e9d890479de1d956..6f2f570b529ad4d884e56f5557e12fd87a59caff 100644 --- a/src/RIGv2/Actuators/Actuators.cpp +++ b/src/RIGv2/Actuators/Actuators.cpp @@ -239,7 +239,7 @@ void Actuators::closeAllServos() getModule<CanHandler>()->sendServoCloseCommand(ServosList::MAIN_VALVE); getModule<CanHandler>()->sendServoCloseCommand( - ServosList::N2O_VENTING_VALVE); + ServosList::OX_VENTING_VALVE); } bool Actuators::setMaxAperture(ServosList servo, float aperture) @@ -275,10 +275,15 @@ bool Actuators::isServoOpen(ServosList servo) bool Actuators::isCanServoOpen(ServosList servo) { Lock<FastMutex> lock(infosMutex); + if (servo == ServosList::MAIN_VALVE) return canMainOpen; - else if (servo == ServosList::N2O_VENTING_VALVE) - return canVentingOpen; + else if (servo == ServosList::NITROGEN_VALVE) + return canNitrogenOpen; + else if (servo == ServosList::OX_VENTING_VALVE) + return canOxVentingOpen; + else if (servo == ServosList::N2_QUENCHING_VALVE) + return canN2QuenchingOpen; else return false; } @@ -289,6 +294,11 @@ void Actuators::set3wayValveState(bool state) n2_3wayValveInfo.unsafeSetServoPosition(position); } +bool Actuators::get3wayValveState() +{ + return n2_3wayValveInfo.getServoPosition() == 1.0f; +} + void Actuators::openChamberWithTime(uint32_t time) { Lock<FastMutex> lock(infosMutex); @@ -335,8 +345,12 @@ void Actuators::setCanServoOpen(ServosList servo, bool open) Lock<FastMutex> lock(infosMutex); if (servo == ServosList::MAIN_VALVE) canMainOpen = open; - else if (servo == ServosList::N2O_VENTING_VALVE) - canVentingOpen = open; + else if (servo == ServosList::NITROGEN_VALVE) + canNitrogenOpen = open; + else if (servo == ServosList::OX_VENTING_VALVE) + canOxVentingOpen = open; + else if (servo == ServosList::N2_QUENCHING_VALVE) + canN2QuenchingOpen = open; } void Actuators::inject(DependencyInjector& injector) @@ -350,11 +364,11 @@ Actuators::ServoInfo* Actuators::getServo(ServosList servo) { switch (servo) { - case N2O_FILLING_VALVE: // OX_FIL + case OX_FILLING_VALVE: // OX_FIL return &infos[0]; - case N2O_RELEASE_VALVE: // OX_REL + case OX_RELEASE_VALVE: // OX_REL return &infos[1]; - case N2O_DETACH_SERVO: // OX_DET + case OX_DETACH_SERVO: // OX_DET return &infos[2]; case N2_FILLING_VALVE: // N2_FIL return &infos[4]; @@ -364,7 +378,7 @@ Actuators::ServoInfo* Actuators::getServo(ServosList servo) return &infos[6]; case NITROGEN_VALVE: // NITR return &infos[7]; - case N2O_VENTING_VALVE: // OX_VEN + case OX_VENTING_VALVE: // OX_VEN return &infos[8]; case N2_QUENCHING_VALVE: // N2_QUE return &infos[9]; diff --git a/src/RIGv2/Actuators/Actuators.h b/src/RIGv2/Actuators/Actuators.h index 75c413fcceee00f97e8cab0fd121d29335cd903e..0289b1a7812906c4e7925c55a602085917b7266c 100644 --- a/src/RIGv2/Actuators/Actuators.h +++ b/src/RIGv2/Actuators/Actuators.h @@ -100,6 +100,7 @@ public: // N2 3-way valve control void set3wayValveState(bool state); + bool get3wayValveState(); // Chamber valve control void openChamberWithTime(uint32_t time); @@ -138,8 +139,10 @@ private: 0; ///< Timestamp to close the chamber (0 if closed) long long chamberLastActionTs = 0; ///< Timestamp of last chamber action - bool canMainOpen = false; - bool canVentingOpen = false; + bool canMainOpen = false; + bool canNitrogenOpen = false; + bool canOxVentingOpen = false; + bool canN2QuenchingOpen = false; Boardcore::Logger& sdLogger = Boardcore::Logger::getInstance(); Boardcore::PrintLogger logger = Boardcore::Logging::getLogger("actuators"); diff --git a/src/RIGv2/Radio/Radio.cpp b/src/RIGv2/Radio/Radio.cpp index d35a38d320976c5db850cdb0160b87ef4697b56c..472eb5d10ec967853d538710de7c789db9abd39a 100644 --- a/src/RIGv2/Radio/Radio.cpp +++ b/src/RIGv2/Radio/Radio.cpp @@ -546,11 +546,11 @@ bool Radio::enqueueSystemTm(uint8_t tmId) tm.timestamp = TimestampTimer::getTimestamp(); // Sensors - tm.rocket_mass = sensors->getOxTankWeight().load; - tm.n2o_vessel_mass = sensors->getOxVesselWeight().load; + tm.rocket_mass = sensors->getOxTankWeight().load; + tm.ox_vessel_mass = sensors->getOxVesselWeight().load; - tm.n2o_vessel_pressure = sensors->getOxVesselPressure().pressure; - tm.n2o_filling_pressure = sensors->getOxFillingPressure().pressure; + tm.ox_vessel_pressure = sensors->getOxVesselPressure().pressure; + tm.ox_filling_pressure = sensors->getOxFillingPressure().pressure; tm.n2_filling_pressure = sensors->getN2FillingPressure().pressure; tm.n2_vessel_1_pressure = sensors->getN2Vessel1Pressure().pressure; tm.n2_vessel_2_pressure = sensors->getN2Vessel2Pressure().pressure; @@ -575,13 +575,14 @@ bool Radio::enqueueSystemTm(uint8_t tmId) sdLogger.log(cpuStats); // Valve states - tm.n2o_filling_valve_state = - actuators->isServoOpen(ServosList::N2O_FILLING_VALVE); - tm.n2o_release_valve_state = - actuators->isServoOpen(ServosList::N2O_RELEASE_VALVE); - tm.n2o_detach_state = 0; // TODO - tm.n2o_venting_valve_state = - actuators->isServoOpen(ServosList::N2O_VENTING_VALVE); + tm.ox_filling_valve_state = + actuators->isServoOpen(ServosList::OX_FILLING_VALVE); + tm.ox_release_valve_state = + actuators->isServoOpen(ServosList::OX_RELEASE_VALVE); + tm.ox_detach_state = + actuators->isServoOpen(ServosList::OX_DETACH_SERVO); + tm.ox_venting_valve_state = + actuators->isServoOpen(ServosList::OX_VENTING_VALVE); tm.n2_filling_valve_state = actuators->isServoOpen(ServosList::N2_FILLING_VALVE); @@ -589,22 +590,23 @@ bool Radio::enqueueSystemTm(uint8_t tmId) actuators->isServoOpen(ServosList::N2_RELEASE_VALVE); tm.n2_detach_state = actuators->isServoOpen(ServosList::N2_DETACH_SERVO); - tm.n2_quenching_valve_state = 0; // TODO - tm.n2_3way_valve_state = 0; // TODO + tm.n2_quenching_valve_state = + actuators->isServoOpen(ServosList::N2_QUENCHING_VALVE); + tm.n2_3way_valve_state = + actuators->isServoOpen(ServosList::N2_3WAY_VALVE); tm.main_valve_state = actuators->isServoOpen(ServosList::MAIN_VALVE); tm.nitrogen_valve_state = actuators->isServoOpen(ServosList::NITROGEN_VALVE); - tm.ignition_state = actuators->isChamberOpen(); + tm.chamber_valve_state = actuators->isChamberOpen(); // Internal states tm.gmm_state = getModule<GroundModeManager>()->getState(); - tm.tars_state = getModule<TARS1>()->isRefueling() ? 1 : 0; + tm.tars3_state = getModule<TARS1>()->isRefueling(); + tm.tars3m_state = 0; // TODO tm.arming_state = getModule<GroundModeManager>()->getState() == - GroundModeManagerState::ARMED - ? 1 - : 0; + GroundModeManagerState::ARMED; // Can data CanHandler::CanStatus canStatus = @@ -634,20 +636,20 @@ bool Radio::enqueueSystemTm(uint8_t tmId) tm.timestamp = TimestampTimer::getTimestamp(); // Sensors (either CAN or local) - tm.top_tank_pressure = sensors->getOxTankTopPressure().pressure; - tm.bottom_tank_pressure = + tm.ox_tank_top_pressure = sensors->getOxTankTopPressure().pressure; + tm.ox_tank_bot_pressure = sensors->getOxTankBottomPressure().pressure; tm.combustion_chamber_pressure = sensors->getCombustionChamberPressure().pressure; - tm.tank_temperature = sensors->getOxTankTemperature().temperature; - tm.battery_voltage = sensors->getMotorBatteryVoltage().voltage; + tm.ox_tank_temperature = + sensors->getOxTankTemperature().temperature; + tm.battery_voltage = sensors->getMotorBatteryVoltage().voltage; // Valve states tm.main_valve_state = - actuators->isCanServoOpen(ServosList::MAIN_VALVE) ? 1 : 0; - tm.venting_valve_state = - actuators->isCanServoOpen(ServosList::N2O_VENTING_VALVE) ? 1 - : 0; + actuators->isCanServoOpen(ServosList::MAIN_VALVE); + tm.ox_venting_valve_state = + actuators->isCanServoOpen(ServosList::OX_VENTING_VALVE); // Can data CanHandler::CanStatus canStatus = @@ -928,35 +930,35 @@ void Radio::handleConrigState(const mavlink_message_t& msg) lastManualActuation = currentTime; } - if (BUTTON_PRESSED(n2o_filling_btn)) + if (BUTTON_PRESSED(ox_filling_btn)) { - // The N2O filling switch was pressed + // The OX filling switch was pressed EventBroker::getInstance().post(MOTOR_MANUAL_ACTION, TOPIC_TARS); - getModule<Actuators>()->toggleServo(ServosList::N2O_FILLING_VALVE); + getModule<Actuators>()->toggleServo(ServosList::OX_FILLING_VALVE); lastManualActuation = currentTime; } - if (BUTTON_PRESSED(n2o_release_btn)) + if (BUTTON_PRESSED(ox_release_btn)) { - // The N2O release switch was pressed + // The OX release switch was pressed EventBroker::getInstance().post(MOTOR_MANUAL_ACTION, TOPIC_TARS); - getModule<Actuators>()->toggleServo(ServosList::N2O_RELEASE_VALVE); + getModule<Actuators>()->toggleServo(ServosList::OX_RELEASE_VALVE); lastManualActuation = currentTime; } - if (BUTTON_PRESSED(n2o_detach_btn)) + if (BUTTON_PRESSED(ox_detach_btn)) { - // The N2O detach switch was pressed + // The OX detach switch was pressed EventBroker::getInstance().post(MOTOR_MANUAL_ACTION, TOPIC_TARS); - getModule<Actuators>()->toggleServo(ServosList::N2O_DETACH_SERVO); + getModule<Actuators>()->toggleServo(ServosList::OX_DETACH_SERVO); lastManualActuation = currentTime; } - if (BUTTON_PRESSED(n2o_venting_btn)) + if (BUTTON_PRESSED(ox_venting_btn)) { - // The N2O venting switch was pressed + // The OX venting switch was pressed EventBroker::getInstance().post(MOTOR_MANUAL_ACTION, TOPIC_TARS); - getModule<Actuators>()->toggleServo(ServosList::N2O_VENTING_VALVE); + getModule<Actuators>()->toggleServo(ServosList::OX_VENTING_VALVE); lastManualActuation = currentTime; } @@ -993,7 +995,7 @@ void Radio::handleConrigState(const mavlink_message_t& msg) } // TODO: tars3 - if (BUTTON_PRESSED(tars_btn)) + if (BUTTON_PRESSED(tars3_btn)) { // The TARS switch was pressed EventBroker::getInstance().post(MOTOR_START_TARS, TOPIC_TARS); diff --git a/src/RIGv2/StateMachines/TARS1/TARS1.cpp b/src/RIGv2/StateMachines/TARS1/TARS1.cpp index b6806abf3b158366ba876131d98024c2cbd8c86a..2d1e27c004ddcf5845b3cba132cb95c99ae3f576 100644 --- a/src/RIGv2/StateMachines/TARS1/TARS1.cpp +++ b/src/RIGv2/StateMachines/TARS1/TARS1.cpp @@ -104,13 +104,13 @@ void TARS1::state_refueling(const Event& event) logAction(TarsActionType::WASHING); // Start washing - actuators->openServoWithTime(ServosList::N2O_VENTING_VALVE, + actuators->openServoWithTime(ServosList::OX_VENTING_VALVE, Config::TARS1::WASHING_OPENING_TIME); // Wait a bit so that the servo don't actuate at the same time Thread::sleep(Config::TARS1::WASHING_TIME_DELAY); - actuators->openServoWithTime(ServosList::N2O_FILLING_VALVE, + actuators->openServoWithTime(ServosList::OX_FILLING_VALVE, Config::TARS1::WASHING_OPENING_TIME); // After double the time we opened the valve, move to the next phase @@ -127,7 +127,7 @@ void TARS1::state_refueling(const Event& event) logAction(TarsActionType::OPEN_FILLING); // Open the filling for a long time - actuators->openServoWithTime(ServosList::N2O_FILLING_VALVE, + actuators->openServoWithTime(ServosList::OX_FILLING_VALVE, Config::TARS1::FILLING_OPENING_TIME); nextDelayedEventId = EventBroker::getInstance().postDelayed( @@ -176,11 +176,11 @@ void TARS1::state_refueling(const Event& event) logAction(TarsActionType::OPEN_VENTING); // Open the venting and check for pressure stabilization - actuators->openServo(ServosList::N2O_VENTING_VALVE); + actuators->openServo(ServosList::OX_VENTING_VALVE); // Calculate next check time based on the time the valve stays open unsigned int nextCheckTime = - actuators->getServoOpeningTime(ServosList::N2O_VENTING_VALVE) + + actuators->getServoOpeningTime(ServosList::OX_VENTING_VALVE) + Config::TARS1::PRESSURE_STABILIZE_WAIT_TIME * 5; nextDelayedEventId = EventBroker::getInstance().postDelayed(