diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 2ae159515ee83c9ae31157d17da269cc426044dc..b73c7ffe70c2cdd88ec7e4ac336204f949f62211 100755 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -74,6 +74,7 @@ "HSE_VALUE=8000000", "SYSCLK_FREQ_168MHz=168000000", "_MIOSIX", + "HILSimulation", "__cplusplus=201103L" ], "includePath": [ diff --git a/.vscode/settings.json b/.vscode/settings.json index d64d9495c135a6f23bd27faa31950c80082b3441..743392d0cbad610129652fe8bcf299b7831f3e7f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,10 +1,7 @@ { - "cmake.configureSettings": { - "CMAKE_C_COMPILER_LAUNCHER": "ccache", - "CMAKE_CXX_COMPILER_LAUNCHER": "ccache" - }, "cmake.parallelJobs": 1, "files.associations": { + "**/miosix-kernel/**": "c", "sstream": "cpp", "format": "cpp", "any": "cpp", @@ -92,7 +89,38 @@ "specialfunctions": "cpp", "splines": "cpp", "matrixfunctions": "cpp", - "tensorsymmetry": "cpp" + "tensorsymmetry": "cpp", + "ios": "cpp", + "charconv": "cpp", + "compare": "cpp", + "concepts": "cpp", + "forward_list": "cpp", + "locale": "cpp", + "queue": "cpp", + "stop_token": "cpp", + "xfacet": "cpp", + "xhash": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocbuf": "cpp", + "xlocinfo": "cpp", + "xlocmes": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xloctime": "cpp", + "xmemory": "cpp", + "xstddef": "cpp", + "xstring": "cpp", + "xtr1common": "cpp", + "xtree": "cpp", + "xutility": "cpp" + }, + "editor.formatOnSave": true, + "[c]": { + "editor.formatOnSave": false + }, + "[cmake]": { + "editor.formatOnSave": false }, "cSpell.words": [ "Aeroutils", @@ -138,5 +166,9 @@ "VREF", "Xbee" ], - "C_Cpp.errorSquiggles": "Enabled" -} + "C_Cpp.errorSquiggles": "Enabled", + "cmake.configureSettings": { + "CMAKE_C_COMPILER_LAUNCHER": "ccache", + "CMAKE_CXX_COMPILER_LAUNCHER": "ccache" + } +} \ No newline at end of file diff --git a/skyward-boardcore b/skyward-boardcore index 1bbf7e74e4b606d6ca63004291380f844b16b4de..692092c0d434f43a0f0e858d5fad8f0a8490b1a7 160000 --- a/skyward-boardcore +++ b/skyward-boardcore @@ -1 +1 @@ -Subproject commit 1bbf7e74e4b606d6ca63004291380f844b16b4de +Subproject commit 692092c0d434f43a0f0e858d5fad8f0a8490b1a7 diff --git a/src/boards/Main/Configs/AirBrakesControllerConfig.h b/src/boards/Main/Configs/AirBrakesControllerConfig.h index 63b3665d70dd096bff0202462059870045086d8a..bb613acb559d6f0769d933c02e7777ce8099d753 100644 --- a/src/boards/Main/Configs/AirBrakesControllerConfig.h +++ b/src/boards/Main/Configs/AirBrakesControllerConfig.h @@ -44,7 +44,7 @@ constexpr float MACH_LIMIT = 0.8; // Vertical speed limit beyond which the airbrakes need to be disabled. constexpr float DISABLE_VERTICAL_SPEED_TARGET = 10.0; -static const Boardcore::AirBrakesConfig ABK_CONFIG{ +static const Boardcore::AirBrakesConfig BASE_ABK_CONFIG{ .N000 = 0.4884, .N100 = -1.4391, .N200 = 6.6940, @@ -74,9 +74,6 @@ static const Boardcore::AirBrakesConfig ABK_CONFIG{ .S0 = 0.017671458676443, .SURFACE = 0.009564 * Main::ActuatorsConfigs::ABK_SERVO_ROTATION * EIGEN_PI / 180.0, - .KP = 20, - .KI = 5, - .TS = UPDATE_PERIOD / 1000.0, }; } // namespace AirBrakesControllerConfig diff --git a/src/boards/Main/Configs/AirBrakesControllerConfigInterp.h b/src/boards/Main/Configs/AirBrakesControllerConfigInterp.h new file mode 100644 index 0000000000000000000000000000000000000000..ed2f25d60e7245c9e7a365b96963ac70a9b499a4 --- /dev/null +++ b/src/boards/Main/Configs/AirBrakesControllerConfigInterp.h @@ -0,0 +1,44 @@ +/* Copyright (c) 2022 Skyward Experimental Rocketry + * Author: Alberto Nidasio + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#pragma once + +#include <AirBrakesControllerConfig.h> +#include <algorithms/AirBrakes/AirBrakesInterpConfig.h> + +namespace Main +{ + +namespace AirBrakesControllerConfig +{ + +static const Boardcore::AirBrakesInterpConfig ABK_CONFIG( + BASE_ABK_CONFIG, + 0.3, // INITIAL_FILTER_COEFF + 12, // INITIAL_T_FILTER + 2.5, // DELTA_T_FILTER + 2 // FILTER_RATIO +); + +} // namespace AirBrakesControllerConfig + +} // namespace Main diff --git a/src/boards/Main/Configs/AirBrakesControllerConfigPI.h b/src/boards/Main/Configs/AirBrakesControllerConfigPI.h new file mode 100644 index 0000000000000000000000000000000000000000..5131baf64fa7a9d3649cd9122553ae282219ee42 --- /dev/null +++ b/src/boards/Main/Configs/AirBrakesControllerConfigPI.h @@ -0,0 +1,43 @@ +/* Copyright (c) 2022 Skyward Experimental Rocketry + * Author: Alberto Nidasio + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#pragma once + +#include <Main/Configs/AirBrakesControllerConfig.h> +#include <algorithms/AirBrakes/AirBrakesPIConfig.h> + +namespace Main +{ + +namespace AirBrakesControllerConfig +{ + +static const Boardcore::AirBrakesPIConfig ABK_CONFIG(BASE_ABK_CONFIG, + 20, // KP + 5, // KI + UPDATE_PERIOD / + 1000.0 // TS +); + +} // namespace AirBrakesControllerConfig + +} // namespace Main diff --git a/src/boards/Main/Radio/Radio.cpp b/src/boards/Main/Radio/Radio.cpp index 0597b93d5b84731a158510aecc4ef21ca19b43ea..e1a542bf49b0eaa10b6804bcee1164527bec8e21 100644 --- a/src/boards/Main/Radio/Radio.cpp +++ b/src/boards/Main/Radio/Radio.cpp @@ -122,7 +122,7 @@ Radio::Radio() new SX1278(Buses::getInstance().spi5, sensors::sx127x::cs::getPin()); SX1278::Config config = {}; - config.freq_rf = 412000000; + config.freq_rf = 412000000; // Use default configuration transceiver->init(config); diff --git a/src/boards/Main/StateMachines/AirBrakesController/AirBrakesController.cpp b/src/boards/Main/StateMachines/AirBrakesController/AirBrakesController.cpp index 4f16ac3ad66637f3a84c7b5c5e52e5a8cb988440..47f502cf8fc0af56899f301a52679159a1da6d2f 100644 --- a/src/boards/Main/StateMachines/AirBrakesController/AirBrakesController.cpp +++ b/src/boards/Main/StateMachines/AirBrakesController/AirBrakesController.cpp @@ -25,8 +25,9 @@ #include <Main/Actuators/Actuators.h> #include <Main/BoardScheduler.h> #include <Main/Configs/ActuatorsConfigs.h> -#include <Main/Configs/AirBrakesControllerConfig.h> #include <Main/StateMachines/NASController/NASController.h> +#include <algorithms/AirBrakes/AirBrakesInterp.h> +#include <algorithms/AirBrakes/AirBrakesPI.h> #include <common/events/Events.h> #include <drivers/timer/TimestampTimer.h> #include <events/EventBroker.h> @@ -36,8 +37,10 @@ #endif #ifdef INTERP +#include "Main/Configs/AirBrakesControllerConfigInterp.h" #include "TrajectorySetInterp.h" #else +#include "Main/Configs/AirBrakesControllerConfigPI.h" #include "TrajectorySet.h" #endif @@ -66,11 +69,11 @@ void AirBrakesController::update() auto currentPoint = TimedTrajectoryPoint{NASController::getInstance().getNasState()}; - if (!abk.isRunning() && status.state == AirBrakesControllerState::ACTIVE && + if (!abk->isRunning() && status.state == AirBrakesControllerState::ACTIVE && currentPoint.getMac() < MACH_LIMIT) - abk.begin(); + abk->begin(); - abk.update(); + abk->update(); } AirBrakesControllerStatus AirBrakesController::getStatus() @@ -174,7 +177,7 @@ void AirBrakesController::state_end(const Event& event) { logStatus(AirBrakesControllerState::END); - abk.end(); + abk->end(); Actuators::getInstance().setServoAngle(AIR_BRAKES_SERVO, 0); return; @@ -183,22 +186,23 @@ void AirBrakesController::state_end(const Event& event) } AirBrakesController::AirBrakesController() - : FSM(&AirBrakesController::state_init), - abk( + : FSM(&AirBrakesController::state_init) +{ + this->abk = new AirBrakesPI( #ifndef HILMockNAS - []() { - return TimedTrajectoryPoint{ - NASController::getInstance().getNasState()}; - }, + []() { + return TimedTrajectoryPoint{ + NASController::getInstance().getNasState()}; + }, #else // HILMockNAS - []() { return Sensors::getInstance().state.kalman->getLastSample(); }, + []() { return Sensors::getInstance().state.kalman->getLastSample(); }, #endif // HILMockNAS - TRAJECTORY_SET, AirBrakesControllerConfig::ABK_CONFIG, - [](float position) { - Actuators::getInstance().setServo(ServosList::AIR_BRAKES_SERVO, - position); - }) -{ + TRAJECTORY_SET, AirBrakesControllerConfig::ABK_CONFIG, + [](float position) { + Actuators::getInstance().setServo(ServosList::AIR_BRAKES_SERVO, + position); + }); + EventBroker::getInstance().subscribe(this, TOPIC_ABK); EventBroker::getInstance().subscribe(this, TOPIC_FLIGHT); } diff --git a/src/boards/Main/StateMachines/AirBrakesController/AirBrakesController.h b/src/boards/Main/StateMachines/AirBrakesController/AirBrakesController.h index 0ad5f9a05cf8f02aba88bf932bf3a20c041c4841..6fca88c9b509c88c830567b7666a15d16e083d98 100644 --- a/src/boards/Main/StateMachines/AirBrakesController/AirBrakesController.h +++ b/src/boards/Main/StateMachines/AirBrakesController/AirBrakesController.h @@ -60,7 +60,7 @@ private: void wiggleServo(); - Boardcore::AirBrakes abk; + Boardcore::AirBrakes* abk; Boardcore::PrintLogger logger = Boardcore::Logging::getLogger("main.abk"); }; diff --git a/src/entrypoints/Groundstation/groundstation-entry.cpp b/src/entrypoints/Groundstation/groundstation-entry.cpp index bf2eeaba6cee1231117b7b75226cc6f8381d3d34..3d81da4809be5fd2f297227874a0920d9c24ddcb 100644 --- a/src/entrypoints/Groundstation/groundstation-entry.cpp +++ b/src/entrypoints/Groundstation/groundstation-entry.cpp @@ -74,9 +74,9 @@ void recvLoop() while (true) { - int len = sx1278->receive(msg, sizeof(msg)); + int len = sx1278->receive(msg, sizeof(msg)); stats.rssi = sx1278->getLastRxRssi(); - stats.fei = sx1278->getLastRxFei(); + stats.fei = sx1278->getLastRxFei(); stats.recv_count++; stats.cur_rx += len; @@ -96,7 +96,7 @@ void sendLoop() sx1278->send(msg, len); stats.sent_count++; stats.cur_tx += len; - ledOff(); + ledOff(); } } @@ -182,9 +182,12 @@ int main() stats.cur_rx = 0; stats.cur_tx = 0; - StatsScreen::Data data = {stats.txBitrate() * 8, stats.rxBitrate() * 8, - stats.sent_count, stats.recv_count, - stats.rssi, stats.fei}; + StatsScreen::Data data = {stats.txBitrate() * 8, + stats.rxBitrate() * 8, + stats.sent_count, + stats.recv_count, + stats.rssi, + stats.fei}; gui->stats_screen.updateStats(data); Thread::sleep(DELTA_T);