diff --git a/src/Groundstation/Automated/test-actuators.cpp b/src/Groundstation/Automated/test-actuators.cpp deleted file mode 100644 index a92629b1535cecff7f8819344f433e9e6247de02..0000000000000000000000000000000000000000 --- a/src/Groundstation/Automated/test-actuators.cpp +++ /dev/null @@ -1,269 +0,0 @@ -/* Copyright (c) 2023 Skyward Experimental Rocketry - * Authors: Niccolò Betto - * - * 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. - */ - -#include <Groundstation/Automated/Actuators/Actuators.h> -#include <Groundstation/Automated/Hub.h> -#include <Groundstation/Automated/Sensors/Sensors.h> -#include <Groundstation/Common/Ports/Serial.h> -#include <Groundstation/LyraGS/Buses.h> -#include <diagnostic/PrintLogger.h> -#include <drivers/interrupt/external_interrupts.h> -#include <miosix.h> -#include <scheduler/TaskScheduler.h> -#include <utils/ButtonHandler/ButtonHandler.h> - -#define STEPPER_SPEED 0.25 -#define TEST_WAIT 5000 -#define NO_SD_LOGGING - -#define START_MODULE(name, lambda) \ - do \ - { \ - std::function<bool()> _fun = lambda; \ - if (!_fun()) \ - { \ - LOG_ERR(logger, "Failed to start module " name); \ - errorLoop(); \ - } \ - else \ - { \ - LOG_DEBUG(logger, "Successfully started module " name); \ - } \ - } while (0) - -using namespace Groundstation; -using namespace Antennas; -using namespace Boardcore; -using namespace miosix; - -void ledWaitLoop(int ms) -{ - int waited = 0; - while (waited < ms) - { - led2On(); - Thread::sleep(100); - led2Off(); - Thread::sleep(100); - waited += 200; - } -} - -void errorLoop() -{ - while (1) - { - userLed4::high(); - Thread::sleep(100); - userLed4::low(); - Thread::sleep(100); - } -} - -void test1(Actuators* actuators) -{ - PrintLogger logger = PrintLogger{Logging::getLogger("test-actuators")}; - LOG_INFO(logger, "Executing Test 1"); - - // theta1 : HORIZONTAL - // theta2 : VERTICAL - LOG_DEBUG(logger, "Setting speed to speed\n"); - actuators->setSpeed(StepperList::STEPPER_X, STEPPER_SPEED); - actuators->setSpeed(StepperList::STEPPER_Y, STEPPER_SPEED); - - LOG_DEBUG(logger, "Moving 90deg horizontally\n"); - actuators->moveDeg(StepperList::STEPPER_X, 90); - ledWaitLoop(TEST_WAIT); - - LOG_DEBUG(logger, "Moving back to the initial horizontal position\n"); - actuators->moveDeg(StepperList::STEPPER_X, -90); - ledWaitLoop(TEST_WAIT); - - LOG_DEBUG(logger, "Moving -90deg horizontally\n"); - actuators->moveDeg(StepperList::STEPPER_X, -90); - ledWaitLoop(TEST_WAIT); - - LOG_DEBUG(logger, "Moving back to the initial horizontal position\n"); - actuators->moveDeg(StepperList::STEPPER_X, 90); - ledWaitLoop(TEST_WAIT); - - LOG_INFO(logger, "Test 1 completed\n"); -} - -void test2(Actuators* actuators) -{ - PrintLogger logger = PrintLogger{Logging::getLogger("test-actuators")}; - LOG_INFO(logger, "Executing Test 2"); - - actuators->setSpeed(StepperList::STEPPER_X, STEPPER_SPEED); - actuators->setSpeed(StepperList::STEPPER_Y, STEPPER_SPEED); - actuators->moveDeg(StepperList::STEPPER_Y, 22.5); - ledWaitLoop(TEST_WAIT); - - actuators->moveDeg(StepperList::STEPPER_X, 90); - ledWaitLoop(TEST_WAIT); - - actuators->moveDeg(StepperList::STEPPER_X, -90); - ledWaitLoop(TEST_WAIT); - - actuators->moveDeg(StepperList::STEPPER_X, -90); - ledWaitLoop(TEST_WAIT); - - actuators->moveDeg(StepperList::STEPPER_X, 90); - ledWaitLoop(TEST_WAIT); - - // Return to (0,0) - actuators->moveDeg(StepperList::STEPPER_Y, -22.5); - ledWaitLoop(TEST_WAIT); - - LOG_INFO(logger, "Test 2 completed\n"); -} - -void test3(Actuators* actuators) -{ - actuators->setSpeed(StepperList::STEPPER_X, STEPPER_SPEED); - actuators->setSpeed(StepperList::STEPPER_Y, STEPPER_SPEED); - - actuators->moveDeg(StepperList::STEPPER_X, 180); - ledWaitLoop(TEST_WAIT + 4000); - actuators->moveDeg(StepperList::STEPPER_X, -180); - ledWaitLoop(TEST_WAIT + 4000); - - actuators->moveDeg(StepperList::STEPPER_Y, 90); - ledWaitLoop(TEST_WAIT); - actuators->moveDeg(StepperList::STEPPER_Y, -90); - ledWaitLoop(TEST_WAIT); -} - -void test6(Actuators* actuators) -{ - PrintLogger logger = PrintLogger{Logging::getLogger("test-actuators")}; - LOG_INFO(logger, "Executing Test 6"); - - actuators->setSpeed(StepperList::STEPPER_X, STEPPER_SPEED); - actuators->setSpeed(StepperList::STEPPER_Y, STEPPER_SPEED); - - actuators->moveDeg(StepperList::STEPPER_Y, 22.5); - ledWaitLoop(TEST_WAIT); - - actuators->moveDeg(StepperList::STEPPER_Y, -22.5); - ledWaitLoop(TEST_WAIT); - - actuators->moveDeg(StepperList::STEPPER_Y, 45); - ledWaitLoop(TEST_WAIT); - - actuators->moveDeg(StepperList::STEPPER_Y, -45); - ledWaitLoop(TEST_WAIT); - - actuators->moveDeg(StepperList::STEPPER_Y, 65.5); - ledWaitLoop(TEST_WAIT); - - actuators->moveDeg(StepperList::STEPPER_Y, -65.5); - ledWaitLoop(TEST_WAIT); - - actuators->moveDeg(StepperList::STEPPER_Y, 90); - ledWaitLoop(TEST_WAIT); - - actuators->moveDeg(StepperList::STEPPER_Y, -90); - ledWaitLoop(TEST_WAIT); - - LOG_INFO(logger, "Test 6 completed\n"); -} - -int main() -{ - ledOff(); - - Hub* hub = new Hub(); - LyraGS::Buses* buses = new LyraGS::Buses(); - Serial* serial = new Serial(); - Actuators* actuators = new Actuators(); - Sensors* sensors = new Sensors(); - - DependencyManager manager; - PrintLogger logger = PrintLogger{Logging::getLogger("test-actuators")}; - bool ok = true; - - LOG_INFO(logger, "test-actuators\n"); - - // Insert modules - { - ok &= manager.insert<HubBase>(hub); - ok &= manager.insert(buses); - ok &= manager.insert(serial); - ok &= manager.insert(actuators); - ok &= manager.insert(sensors); - - // If insertion failed, stop right here - if (!ok) - { - LOG_ERR(logger, "Failed to insert all modules!\n"); - errorLoop(); - } - else - { - LOG_DEBUG(logger, "All modules inserted successfully!\n"); - } - - if (!manager.inject()) - { - LOG_ERR(logger, "[error] Failed to inject the dependencies!\n"); - errorLoop(); - } - else - { - LOG_DEBUG(logger, "All modules injected successfully!\n"); - } - } - - // Start modules - { -#ifndef NO_SD_LOGGING - START_MODULE("Logger", [&] { return Logger::getInstance().start(); }); -#endif - START_MODULE("Serial", [&] { return serial->start(); }); - START_MODULE("Sensors", [&] { return sensors->start(); }); - - actuators->start(); - LOG_DEBUG(logger, "Actuators started successfully!\n"); - } - - // Setup success LED - led1On(); - LOG_INFO(logger, "Modules setup successful"); - - LOG_INFO(logger, "Starting tests\n"); - - actuators->arm(); - - test1(actuators); - test2(actuators); - test3(actuators); - test6(actuators); - - LOG_INFO(logger, "Tests completed\n"); - - led1Off(); - while (1) - Thread::sleep(1000); - return 0; -} diff --git a/src/Groundstation/Automated/test-automated-radio.cpp b/src/Groundstation/Automated/test-automated-radio.cpp deleted file mode 100644 index c33b71cdde30e8d197e6e4ca81e12f2c697e5838..0000000000000000000000000000000000000000 --- a/src/Groundstation/Automated/test-automated-radio.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* Copyright (c) 2023 Skyward Experimental Rocketry - * Authors: Davide Mor, Emilio Corigliano - * - * 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. - */ - -#include <Groundstation/Automated/Buses.h> -#include <Groundstation/Automated/Hub.h> -#include <Groundstation/Automated/Radio/Radio.h> -#include <Groundstation/Common/Ports/Serial.h> -#include <Groundstation/LyraGS/BoardStatus.h> -#include <miosix.h> - -using namespace Groundstation; -using namespace Antennas; -using namespace Boardcore; -using namespace miosix; - -void spinLoop() -{ - while (1) - Thread::sleep(1000); -} - -void errorLoop() -{ - while (1) - { - led1On(); - Thread::sleep(100); - led1Off(); - Thread::sleep(100); - } -} - -int main() -{ - ledOff(); - - Hub* hub = new Hub(); - Buses* buses = new Buses(); - Serial* serial = new Serial(); - RadioMain* radio_main = new RadioMain(); - BoardStatus* board_status = new BoardStatus(); - - ModuleManager& modules = ModuleManager::getInstance(); - - bool ok = true; - - ok &= modules.insert<HubBase>(hub); - ok &= modules.insert(buses); - ok &= modules.insert(serial); - ok &= modules.insert(radio_main); - ok &= modules.insert(board_status); - - // If insertion failed, stop right here - if (!ok) - { - printf("[error] Failed to insert all modules!\n"); - errorLoop(); - } - - // Ok now start them - - ok &= serial->start(); - if (!ok) - printf("[error] Failed to start serial!\n"); - - ok &= radio_main->start(); - if (!ok) - printf("[error] Failed to start main radio!\n"); - - ok &= board_status->start(); - if (!ok) - printf("[error] Failed to start radio status!\n"); - - if (board_status->isMainRadioPresent()) - led2On(); - - if (!ok) - errorLoop(); - - led1On(); - spinLoop(); - return 0; -} diff --git a/src/Groundstation/Automated/test-smcontroller.cpp b/src/Groundstation/Automated/test-smcontroller.cpp deleted file mode 100644 index a77712da36b4483cfa9ae33f823ea4fa89d41a0d..0000000000000000000000000000000000000000 --- a/src/Groundstation/Automated/test-smcontroller.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/* Copyright (c) 2024 Skyward Experimental Rocketry - * Author: Federico Lolli - * - * 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. - */ - -#include <Groundstation/Automated/SMA/SMA.h> -#include <common/Events.h> -#include <common/Topics.h> -#include <events/EventBroker.h> -#include <utils/Debug.h> - -#include <memory> -#include <unordered_set> - -#define ARP_EVENTS \ - {ARP_INIT_OK, ARP_INIT_ERROR, ARP_CAL_DONE, ARP_FIX_ANTENNAS, \ - ARP_FIX_ROCKET} - -#define TMTC_EVENTS \ - {TMTC_ARP_FORCE_INIT, \ - TMTC_ARP_RESET_ALGORITHM, \ - TMTC_ARP_FORCE_NO_FEEDBACK, \ - TMTC_ARP_ARM, \ - TMTC_ARP_DISARM, \ - TMTC_ARP_CALIBRATE, \ - TMTC_ARP_ENTER_TEST_MODE, \ - TMTC_ARP_EXIT_TEST_MODE} - -#define TEST_STATE(INITIAL_STATE, EVENT, TOPIC_SM, FINAL_STATE) \ - sm->forceState(&SMA::INITIAL_STATE); \ - EventBroker::getInstance().post(EVENT, TOPIC_SM); \ - Thread::sleep(20); \ - TRACE("Testing %-26s in " #INITIAL_STATE " -> " #FINAL_STATE " ... ", \ - getEventString(EVENT).c_str()); \ - correct = sm->testState(&SMA::FINAL_STATE); \ - printf(correct ? "OK\n" : "FAIL\n"); \ - ok &= correct; - -#define TEST_NO_TRANSITION(INITIAL_STATE, EVENT, TOPIC_SM) \ - sm->forceState(&SMA::INITIAL_STATE); \ - EventBroker::getInstance().post(EVENT, TOPIC_SM); \ - Thread::sleep(20); \ - TRACE("Testing %-26s in " #INITIAL_STATE " -X ... ", \ - getEventString(EVENT).c_str()); \ - correct = sm->testState(&SMA::INITIAL_STATE); \ - printf(correct ? "OK\n" : "FAIL\n"); \ - ok &= correct; - -#define TEST_ALL_OTHER(INITIAL_STATE, ...) \ - to_exclude = {__VA_ARGS__}; \ - for (Events ev : arp_events) \ - { \ - if (to_exclude.find(ev) == to_exclude.end()) \ - { \ - TEST_NO_TRANSITION(INITIAL_STATE, ev, TOPIC_ARP); \ - } \ - } \ - for (Events ev : tmtc_events) \ - { \ - if (to_exclude.find(ev) == to_exclude.end()) \ - { \ - TEST_NO_TRANSITION(INITIAL_STATE, ev, TOPIC_TMTC); \ - } \ - } - -// for (auto state : {__VA_ARGS__}) -// { - -using namespace Boardcore; -using namespace Common; -using namespace Antennas; - -SMA* sm = new SMA(); - -int main() -{ - bool correct, ok = true; - std::unordered_set<Events> to_exclude; - std::vector<Events> arp_events = ARP_EVENTS; - std::vector<Events> tmtc_events = TMTC_EVENTS; - - sm->start(); - TRACE("SMA started\n"); - - // TEST STATE: INIT - TEST_STATE(state_init, ARP_INIT_OK, TOPIC_ARP, state_init_done); - TEST_STATE(state_init, ARP_INIT_ERROR, TOPIC_ARP, state_init_error); - TEST_ALL_OTHER(state_init, ARP_INIT_OK, ARP_INIT_ERROR); - - // TEST STATE: INIT_DONE - TEST_STATE(state_init_done, TMTC_ARP_ARM, TOPIC_TMTC, state_armed); - TEST_STATE(state_init_done, TMTC_ARP_FORCE_NO_FEEDBACK, TOPIC_TMTC, - state_insert_info); - TEST_ALL_OTHER(state_init_done, TMTC_ARP_ARM, TMTC_ARP_FORCE_NO_FEEDBACK); - - // TEST STATE: INIT_ERROR - TEST_STATE(state_init_error, TMTC_ARP_FORCE_INIT, TOPIC_TMTC, - state_init_done); - TEST_STATE(state_init_error, TMTC_ARP_FORCE_NO_FEEDBACK, TOPIC_TMTC, - state_insert_info); - TEST_ALL_OTHER(state_init_error, TMTC_ARP_FORCE_INIT, - TMTC_ARP_FORCE_NO_FEEDBACK); - - // TEST STATE: INSERT_INFO - TEST_STATE(state_insert_info, ARP_FIX_ANTENNAS, TOPIC_ARP, state_arm_ready); - TEST_ALL_OTHER(state_insert_info, ARP_FIX_ANTENNAS); - - // TEST STATE: ARM READY - TEST_STATE(state_arm_ready, TMTC_ARP_ARM, TOPIC_TMTC, state_armed_nf); - TEST_ALL_OTHER(state_arm_ready, TMTC_ARP_ARM); - - // TEST STATE: ARMED - TEST_STATE(state_armed, TMTC_ARP_DISARM, TOPIC_TMTC, state_init_done); - TEST_STATE(state_armed, TMTC_ARP_CALIBRATE, TOPIC_TMTC, state_calibrate); - TEST_STATE(state_armed, TMTC_ARP_ENTER_TEST_MODE, TOPIC_TMTC, state_test); - TEST_ALL_OTHER(state_armed, TMTC_ARP_DISARM, TMTC_ARP_CALIBRATE, - TMTC_ARP_ENTER_TEST_MODE); - - // TEST STATE: TEST - TEST_STATE(state_test, TMTC_ARP_EXIT_TEST_MODE, TOPIC_TMTC, state_armed); - TEST_STATE(state_test, TMTC_ARP_DISARM, TOPIC_TMTC, state_init_done); - TEST_ALL_OTHER(state_test, TMTC_ARP_EXIT_TEST_MODE, TMTC_ARP_DISARM); - - // TEST STATE: CALIBRATE - TEST_STATE(state_calibrate, ARP_CAL_DONE, TOPIC_ARP, state_fix_antennas); - TEST_STATE(state_calibrate, TMTC_ARP_DISARM, TOPIC_TMTC, state_init_done); - TEST_STATE(state_calibrate, TMTC_ARP_RESET_ALGORITHM, TOPIC_TMTC, - state_armed); - TEST_ALL_OTHER(state_calibrate, ARP_CAL_DONE, TMTC_ARP_DISARM, - TMTC_ARP_RESET_ALGORITHM); - - // TEST STATE: FIX_ANTENNAS - TEST_STATE(state_fix_antennas, ARP_FIX_ANTENNAS, TOPIC_ARP, - state_fix_rocket); - TEST_STATE(state_fix_antennas, TMTC_ARP_DISARM, TOPIC_TMTC, - state_init_done); - TEST_STATE(state_fix_antennas, TMTC_ARP_RESET_ALGORITHM, TOPIC_TMTC, - state_armed); - TEST_ALL_OTHER(state_fix_antennas, ARP_FIX_ANTENNAS, TMTC_ARP_DISARM, - TMTC_ARP_RESET_ALGORITHM); - - // TEST STATE: FIX_ROCKET - TEST_STATE(state_fix_rocket, ARP_FIX_ROCKET, TOPIC_ARP, state_active); - TEST_STATE(state_fix_rocket, TMTC_ARP_DISARM, TOPIC_TMTC, state_init_done); - TEST_STATE(state_fix_rocket, TMTC_ARP_RESET_ALGORITHM, TOPIC_TMTC, - state_armed); - TEST_ALL_OTHER(state_fix_rocket, ARP_FIX_ROCKET, TMTC_ARP_DISARM, - TMTC_ARP_RESET_ALGORITHM); - - // TEST STATE: ACTIVE - TEST_STATE(state_active, TMTC_ARP_DISARM, TOPIC_TMTC, state_init_done); - TEST_STATE(state_active, TMTC_ARP_RESET_ALGORITHM, TOPIC_TMTC, state_armed); - TEST_ALL_OTHER(state_active, TMTC_ARP_DISARM, TMTC_ARP_RESET_ALGORITHM); - - // TEST STATE: ARMED_NO_FEEDBACK - TEST_STATE(state_armed_nf, TMTC_ARP_DISARM, TOPIC_TMTC, state_arm_ready); - TEST_STATE(state_armed_nf, TMTC_ARP_CALIBRATE, TOPIC_TMTC, - state_fix_rocket_nf); - TEST_STATE(state_armed_nf, TMTC_ARP_ENTER_TEST_MODE, TOPIC_TMTC, - state_test_nf); - TEST_ALL_OTHER(state_armed_nf, TMTC_ARP_DISARM, TMTC_ARP_CALIBRATE, - TMTC_ARP_ENTER_TEST_MODE); - - // TEST STATE: TEST_NO_FEEDBACK - TEST_STATE(state_test_nf, TMTC_ARP_EXIT_TEST_MODE, TOPIC_TMTC, - state_armed_nf); - TEST_STATE(state_test_nf, TMTC_ARP_DISARM, TOPIC_TMTC, state_arm_ready); - TEST_ALL_OTHER(state_test_nf, TMTC_ARP_EXIT_TEST_MODE, TMTC_ARP_DISARM); - - // TEST STATE: FIX_ROCKET_NO_FEEDBACK - TEST_STATE(state_fix_rocket_nf, ARP_FIX_ROCKET, TOPIC_ARP, state_active_nf); - TEST_STATE(state_fix_rocket_nf, TMTC_ARP_DISARM, TOPIC_TMTC, - state_arm_ready); - TEST_STATE(state_fix_rocket_nf, TMTC_ARP_RESET_ALGORITHM, TOPIC_TMTC, - state_armed_nf); - TEST_ALL_OTHER(state_fix_rocket_nf, ARP_FIX_ROCKET, TMTC_ARP_DISARM, - TMTC_ARP_RESET_ALGORITHM); - - // TEST STATE: ACTIVE_NO_FEEDBACK - TEST_STATE(state_active_nf, TMTC_ARP_DISARM, TOPIC_TMTC, state_arm_ready); - TEST_STATE(state_active_nf, TMTC_ARP_RESET_ALGORITHM, TOPIC_TMTC, - state_armed_nf); - TEST_ALL_OTHER(state_active_nf, TMTC_ARP_DISARM, TMTC_ARP_RESET_ALGORITHM); - - TRACE("Testing SMA ... "); - ok ? printf("OK\n") : printf("FAIL\n"); - return 0; -} diff --git a/src/Groundstation/Automated/test-steps.cpp b/src/Groundstation/Automated/test-steps.cpp deleted file mode 100644 index 7a69211c5b49a6e90d374849c7ae77f73840eb8e..0000000000000000000000000000000000000000 --- a/src/Groundstation/Automated/test-steps.cpp +++ /dev/null @@ -1,236 +0,0 @@ -/* Copyright (c) 2023 Skyward Experimental Rocketry - * Author: Emilio Corigliano - * - * 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. - */ - -#include <Groundstation/Automated/Actuators/Actuators.h> -#include <Groundstation/Automated/Buses.h> -#include <Groundstation/Automated/Sensors/Sensors.h> -#include <diagnostic/CpuMeter/CpuMeter.h> -#include <diagnostic/PrintLogger.h> -#include <diagnostic/StackLogger.h> -#include <drivers/interrupt/external_interrupts.h> -#include <drivers/timer/TimestampTimer.h> -#include <events/EventBroker.h> -#include <miosix.h> -#include <scheduler/TaskScheduler.h> -#include <utils/ButtonHandler/ButtonHandler.h> - -#include <iostream> -#include <utils/ModuleManager/ModuleManager.hpp> - -#include "actuators/stepper/StepperPWM.h" - -using namespace miosix; -using namespace Boardcore; -using namespace Antennas; - -/** - * Test used to characterize the automated antennas. - */ - -GpioPin button = GpioPin(GPIOC_BASE, 13); - -void __attribute__((used)) EXTI13_IRQHandlerImpl() -{ - ModuleManager::getInstance().get<Actuators>()->IRQemergencyStop(); -} - -int main() -{ - bool initResult = true; - PrintLogger logger = Logging::getLogger("automated_antennas"); - ModuleManager& modules = ModuleManager::getInstance(); - TaskScheduler* scheduler = new TaskScheduler(); - - button.mode(Mode::INPUT); - enableExternalInterrupt(button.getPort(), button.getNumber(), - InterruptTrigger::RISING_EDGE); - - // INSERTING MODULES - { - if (!modules.insert<Buses>(new Buses())) - { - initResult = false; - LOG_ERR(logger, "Error inserting the Buses module"); - } - else - { - LOG_INFO(logger, "Successfully inserted Buses module\n"); - } - - if (!modules.insert<Actuators>(new Actuators())) - { - initResult = false; - LOG_ERR(logger, "Error inserting the Actuators module"); - } - else - { - LOG_INFO(logger, "Successfully inserted Actuators module\n"); - } - - if (!modules.insert<Sensors>(new Sensors())) - { - initResult = false; - LOG_ERR(logger, "Error inserting the Sensors module"); - } - else - { - LOG_INFO(logger, "Successfully inserted Sensors module\n"); - } - - // Insert algorithm modules - } - - // ADDING TASKS - { - scheduler->addTask( - []() - { - Logger::getInstance().log(CpuMeter::getCpuStats()); - CpuMeter::resetCpuStats(); - Logger::getInstance().logStats(); - StackLogger::getInstance().log(); - }, - 100); - } - - // STARTING MODULES - { -#ifndef NO_SD_LOGGING - // Starting the Logger - if (!Logger::getInstance().start()) - { - initResult = false; - LOG_ERR(logger, "Error initializing the Logger\n"); - } - else - { - LOG_INFO(logger, "Logger started successfully\n"); - } -#endif - - // Starting scheduler - if (!scheduler->start()) - { - initResult = false; - LOG_ERR(logger, "Error initializing the Scheduler\n"); - } - else - { - LOG_INFO(logger, "Scheduler started successfully\n"); - } - - // Starting the Actuators - modules.get<Actuators>()->start(); - - // Starting the Sensors - if (!modules.get<Sensors>()->start()) - { - initResult = false; - LOG_ERR(logger, "Error initializing the Sensors\n"); - } - else - { - LOG_INFO(logger, "Sensors started successfully\n"); - } - } - - if (!initResult) - { - printf("Errors present during module insertion\n"); - return -1; - } - - // Periodically statistics - float speed0 = 0.5; - float speed = speed0; - - modules.get<Actuators>()->setSpeed(StepperList::STEPPER_X, speed); - - modules.get<Actuators>()->setSpeed(StepperList::STEPPER_Y, speed); - - // bool increasing = true; - // float speedMax = 1.0; - // float stepSpeed = 0.1; - // scheduler->addTask( - // [&]() - // { - // if (increasing) - // { - // if (speed < speedMax) - // { - // speed += stepSpeed; - // modules.get<Actuators>()->setSpeed( - // StepperList::STEPPER_X, speed); - // } - // else - // { - // increasing = false; - // } - // } - // else - // { - // if (speed > 0) - // { - // speed -= stepSpeed; - // modules.get<Actuators>()->setSpeed( - // StepperList::STEPPER_X, speed); - // } - // else - // { - // increasing = true; - // } - // } - // }, - // 100); - VN300Data data; - while (!ModuleManager::getInstance().get<Actuators>()->isEmergencyStopped()) - { - { - data = modules.get<Sensors>()->getVN300LastSample(); - printf("acc[%.3f,%.3f,%.3f] ypr[%.3f,%.3f,%.3f]\n", - data.accelerationX, data.accelerationY, data.accelerationZ, - data.yaw, data.pitch, data.roll); - modules.get<Actuators>()->moveDeg(StepperList::STEPPER_X, 90); - modules.get<Actuators>()->moveDeg(StepperList::STEPPER_Y, 90); - Thread::sleep(1500); - } - - { - data = modules.get<Sensors>()->getVN300LastSample(); - printf("acc[%.3f,%.3f,%.3f] ypr[%.3f,%.3f,%.3f]\n", - data.accelerationX, data.accelerationY, data.accelerationZ, - data.yaw, data.pitch, data.roll); - modules.get<Actuators>()->moveDeg(StepperList::STEPPER_X, -90); - modules.get<Actuators>()->moveDeg(StepperList::STEPPER_Y, -90); - Thread::sleep(1500); - } - } - - // Stopping threads - { - Logger::getInstance().stop(); - printf("Logger stopped! Board can be reset/shutdown9\n"); - } - - while (1) - ; -}