From a889edad257f1cbddd62d4da021ac1fbe9af8cc3 Mon Sep 17 00:00:00 2001
From: Alberto Nidasio <alberto.nidasio@skywarder.eu>
Date: Fri, 2 Sep 2022 14:57:01 +0200
Subject: [PATCH] [HIL] Few corrections of comments

---
 .vscode/c_cpp_properties.json                 | 35 +++++++++-----
 .vscode/settings.json                         |  4 +-
 CMakeLists.txt                                |  2 +-
 skyward-boardcore                             |  2 +-
 .../simulator_communication/HILTransceiver.h  |  2 +-
 src/boards/Main/TMRepository/TMRepository.cpp |  2 +-
 .../HIL/HILTransceiver.cpp                    | 48 ++++++++-----------
 src/hardware_in_the_loop/HIL/HILTransceiver.h |  2 +-
 src/hardware_in_the_loop/HILConfig.h          |  2 +-
 .../HILSimulationConfig.h                     |  0
 .../test-hil/test-hil.cpp                     |  4 +-
 11 files changed, 54 insertions(+), 49 deletions(-)
 rename src/{tests/hardware_in_the_loop/test-hil => hardware_in_the_loop}/HILSimulationConfig.h (100%)

diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
index ebcde8afd..4312763b0 100755
--- a/.vscode/c_cpp_properties.json
+++ b/.vscode/c_cpp_properties.json
@@ -21,6 +21,7 @@
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/cortexM4_stm32f4/common",
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/common",
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix",
+                "${workspaceFolder}/skyward-boardcore/libs/Catch2/single_include",
                 "${workspaceFolder}/skyward-boardcore/libs/mavlink-skyward-lib",
                 "${workspaceFolder}/skyward-boardcore/libs/fmt/include",
                 "${workspaceFolder}/skyward-boardcore/libs/eigen",
@@ -53,7 +54,7 @@
                     "${workspaceFolder}/skyward-boardcore/libs/fmt",
                     "${workspaceFolder}/skyward-boardcore/src/shared",
                     "${workspaceFolder}/skyward-boardcore/src/tests",
-                "${workspaceFolder}/src/hardware_in_the_loop",
+                    "${workspaceFolder}/src/hardware_in_the_loop",
                     "${workspaceFolder}/src/boards",
                     "${workspaceFolder}/src/tests"
                 ],
@@ -81,6 +82,7 @@
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/cortexM4_stm32f4/common",
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/common",
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix",
+                "${workspaceFolder}/skyward-boardcore/libs/Catch2/single_include",
                 "${workspaceFolder}/skyward-boardcore/libs/mavlink-skyward-lib",
                 "${workspaceFolder}/skyward-boardcore/libs/fmt/include",
                 "${workspaceFolder}/skyward-boardcore/libs/eigen",
@@ -113,7 +115,7 @@
                     "${workspaceFolder}/skyward-boardcore/libs/fmt",
                     "${workspaceFolder}/skyward-boardcore/src/shared",
                     "${workspaceFolder}/skyward-boardcore/src/tests",
-                "${workspaceFolder}/src/hardware_in_the_loop",
+                    "${workspaceFolder}/src/hardware_in_the_loop",
                     "${workspaceFolder}/src/boards",
                     "${workspaceFolder}/src/tests"
                 ],
@@ -140,8 +142,8 @@
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/cortexM4_stm32f4/stm32f429zi_skyward_death_stack_x",
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/cortexM4_stm32f4/common",
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/common",
-                "${workspaceFolder}/skyward-boardcore/libs/Catch2/single_include",
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix",
+                "${workspaceFolder}/skyward-boardcore/libs/Catch2/single_include",
                 "${workspaceFolder}/skyward-boardcore/libs/mavlink-skyward-lib",
                 "${workspaceFolder}/skyward-boardcore/libs/fmt/include",
                 "${workspaceFolder}/skyward-boardcore/libs/eigen",
@@ -175,7 +177,7 @@
                     "${workspaceFolder}/skyward-boardcore/libs/fmt",
                     "${workspaceFolder}/skyward-boardcore/src/shared",
                     "${workspaceFolder}/skyward-boardcore/src/tests",
-                "${workspaceFolder}/src/hardware_in_the_loop",
+                    "${workspaceFolder}/src/hardware_in_the_loop",
                     "${workspaceFolder}/src/boards",
                     "${workspaceFolder}/src/tests"
                 ],
@@ -204,6 +206,7 @@
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/cortexM4_stm32f4/common",
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/common",
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix",
+                "${workspaceFolder}/skyward-boardcore/libs/Catch2/single_include",
                 "${workspaceFolder}/skyward-boardcore/libs/mavlink-skyward-lib",
                 "${workspaceFolder}/skyward-boardcore/libs/fmt/include",
                 "${workspaceFolder}/skyward-boardcore/libs/eigen",
@@ -214,7 +217,7 @@
                 "${workspaceFolder}/src/hardware_in_the_loop",
                 "${workspaceFolder}/src/boards",
                 "${workspaceFolder}/src/tests",
-                "${workspaceFolder}/src"
+                "${workspaceFolder}/src",
             ],
             "browse": {
                 "path": [
@@ -236,7 +239,7 @@
                     "${workspaceFolder}/skyward-boardcore/libs/fmt",
                     "${workspaceFolder}/skyward-boardcore/src/shared",
                     "${workspaceFolder}/skyward-boardcore/src/tests",
-                "${workspaceFolder}/src/hardware_in_the_loop",
+                    "${workspaceFolder}/src/hardware_in_the_loop",
                     "${workspaceFolder}/src/boards",
                     "${workspaceFolder}/src/tests"
                 ],
@@ -266,6 +269,7 @@
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/cortexM4_stm32f4/common",
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/common",
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix",
+                "${workspaceFolder}/skyward-boardcore/libs/Catch2/single_include",
                 "${workspaceFolder}/skyward-boardcore/libs/mavlink-skyward-lib",
                 "${workspaceFolder}/skyward-boardcore/libs/fmt/include",
                 "${workspaceFolder}/skyward-boardcore/libs/eigen",
@@ -298,7 +302,7 @@
                     "${workspaceFolder}/skyward-boardcore/libs/fmt",
                     "${workspaceFolder}/skyward-boardcore/src/shared",
                     "${workspaceFolder}/skyward-boardcore/src/tests",
-                "${workspaceFolder}/src/hardware_in_the_loop",
+                    "${workspaceFolder}/src/hardware_in_the_loop",
                     "${workspaceFolder}/src/boards",
                     "${workspaceFolder}/src/tests"
                 ],
@@ -326,6 +330,7 @@
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/cortexM4_stm32f4/common",
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/common",
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix",
+                "${workspaceFolder}/skyward-boardcore/libs/Catch2/single_include",
                 "${workspaceFolder}/skyward-boardcore/libs/mavlink-skyward-lib",
                 "${workspaceFolder}/skyward-boardcore/libs/fmt/include",
                 "${workspaceFolder}/skyward-boardcore/libs/eigen",
@@ -358,7 +363,7 @@
                     "${workspaceFolder}/skyward-boardcore/libs/fmt",
                     "${workspaceFolder}/skyward-boardcore/src/shared",
                     "${workspaceFolder}/skyward-boardcore/src/tests",
-                "${workspaceFolder}/src/hardware_in_the_loop",
+                    "${workspaceFolder}/src/hardware_in_the_loop",
                     "${workspaceFolder}/src/boards",
                     "${workspaceFolder}/src/tests"
                 ],
@@ -386,6 +391,7 @@
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/cortexM3_stm32f2/common",
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/common",
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix",
+                "${workspaceFolder}/skyward-boardcore/libs/Catch2/single_include",
                 "${workspaceFolder}/skyward-boardcore/libs/mavlink-skyward-lib",
                 "${workspaceFolder}/skyward-boardcore/libs/fmt/include",
                 "${workspaceFolder}/skyward-boardcore/libs/eigen",
@@ -418,7 +424,7 @@
                     "${workspaceFolder}/skyward-boardcore/libs/fmt",
                     "${workspaceFolder}/skyward-boardcore/src/shared",
                     "${workspaceFolder}/skyward-boardcore/src/tests",
-                "${workspaceFolder}/src/hardware_in_the_loop",
+                    "${workspaceFolder}/src/hardware_in_the_loop",
                     "${workspaceFolder}/src/boards",
                     "${workspaceFolder}/src/tests"
                 ],
@@ -446,6 +452,7 @@
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/cortexM4_stm32f4/common",
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/common",
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix",
+                "${workspaceFolder}/skyward-boardcore/libs/Catch2/single_include",
                 "${workspaceFolder}/skyward-boardcore/libs/mavlink-skyward-lib",
                 "${workspaceFolder}/skyward-boardcore/libs/fmt/include",
                 "${workspaceFolder}/skyward-boardcore/libs/eigen",
@@ -480,7 +487,7 @@
                     "${workspaceFolder}/skyward-boardcore/libs/fmt",
                     "${workspaceFolder}/skyward-boardcore/src/shared",
                     "${workspaceFolder}/skyward-boardcore/src/tests",
-                "${workspaceFolder}/src/hardware_in_the_loop",
+                    "${workspaceFolder}/src/hardware_in_the_loop",
                     "${workspaceFolder}/src/boards",
                     "${workspaceFolder}/src/tests",
                     "${workspaceFolder}/src"
@@ -510,6 +517,7 @@
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/cortexM4_stm32f4/common",
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/common",
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix",
+                "${workspaceFolder}/skyward-boardcore/libs/Catch2/single_include",
                 "${workspaceFolder}/skyward-boardcore/libs/mavlink-skyward-lib",
                 "${workspaceFolder}/skyward-boardcore/libs/fmt/include",
                 "${workspaceFolder}/skyward-boardcore/libs/eigen",
@@ -542,7 +550,7 @@
                     "${workspaceFolder}/skyward-boardcore/libs/fmt",
                     "${workspaceFolder}/skyward-boardcore/src/shared",
                     "${workspaceFolder}/skyward-boardcore/src/tests",
-                "${workspaceFolder}/src/hardware_in_the_loop",
+                    "${workspaceFolder}/src/hardware_in_the_loop",
                     "${workspaceFolder}/src/boards",
                     "${workspaceFolder}/src/tests"
                 ],
@@ -570,6 +578,7 @@
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/cortexM4_stm32f4/common",
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix/arch/common",
                 "${workspaceFolder}/skyward-boardcore/libs/miosix-kernel/miosix",
+                "${workspaceFolder}/skyward-boardcore/libs/Catch2/single_include",
                 "${workspaceFolder}/skyward-boardcore/libs/mavlink-skyward-lib",
                 "${workspaceFolder}/skyward-boardcore/libs/fmt/include",
                 "${workspaceFolder}/skyward-boardcore/libs/eigen",
@@ -602,7 +611,7 @@
                     "${workspaceFolder}/skyward-boardcore/libs/fmt",
                     "${workspaceFolder}/skyward-boardcore/src/shared",
                     "${workspaceFolder}/skyward-boardcore/src/tests",
-                "${workspaceFolder}/src/hardware_in_the_loop",
+                    "${workspaceFolder}/src/hardware_in_the_loop",
                     "${workspaceFolder}/src/boards",
                     "${workspaceFolder}/src/tests"
                 ],
@@ -611,4 +620,4 @@
         }
     ],
     "version": 4
-}
+}
\ No newline at end of file
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 94e2159e5..ad21fcf0f 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -95,6 +95,7 @@
         "tensorsymmetry": "cpp"
     },
     "cSpell.words": [
+        "Aeroutils",
         "AIRBRAKES",
         "Baro",
         "Boardcore",
@@ -126,6 +127,7 @@
         "miosix",
         "Nidasio",
         "pitot",
+        "stateinitializer",
         "telecommands",
         "UBXGPS",
         "usart",
@@ -133,4 +135,4 @@
         "Xbee"
     ],
     "C_Cpp.errorSquiggles": "Enabled"
-}
+}
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index dd4d4ff47..95ec5cb56 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -61,7 +61,7 @@ sbs_target(groundstation-entry stm32f429zi_skyward_groundstation)
 add_executable(test-hil src/tests/hardware_in_the_loop/test-hil/test-hil.cpp ${MAIN_COMPUTER} ${HIL})
 target_include_directories(test-hil PRIVATE ${OBSW_INCLUDE_DIRS})
 target_compile_definitions(test-hil PRIVATE HILSimulation HILUseADA HILUseRadio EUROC)
-# ssbs_target(test-hil stm32f407vg_stm32f4discovery)
+# sbs_target(test-hil stm32f407vg_stm32f4discovery)
 sbs_target(test-hil stm32f429zi_skyward_death_stack_v3)
 
 add_executable(ciuti-entry src/entrypoints/Ciuti/ciuti-entry.cpp ${CIUTI_COMPUTER})
diff --git a/skyward-boardcore b/skyward-boardcore
index 407af0d28..5219ea9bd 160000
--- a/skyward-boardcore
+++ b/skyward-boardcore
@@ -1 +1 @@
-Subproject commit 407af0d28040093f8600034fb5ffd083341a9529
+Subproject commit 5219ea9bd286bfa551f7c9ec2dd281759f6e1f70
diff --git a/src Lynx/hardware_in_the_loop/simulator_communication/HILTransceiver.h b/src Lynx/hardware_in_the_loop/simulator_communication/HILTransceiver.h
index f69513774..14380ae8d 100644
--- a/src Lynx/hardware_in_the_loop/simulator_communication/HILTransceiver.h	
+++ b/src Lynx/hardware_in_the_loop/simulator_communication/HILTransceiver.h	
@@ -33,7 +33,7 @@
 #include "math/Vec3.h"
 
 /**
- * @brief HILTranceiver is a Singleton and provides an easy interface for the
+ * @brief HILTransceiver is a Singleton and provides an easy interface for the
  * control algorithms to send and receive data during a simulation
  */
 class HILTransceiver : public ActiveObject
diff --git a/src/boards/Main/TMRepository/TMRepository.cpp b/src/boards/Main/TMRepository/TMRepository.cpp
index 8bc49eb75..890be5d42 100644
--- a/src/boards/Main/TMRepository/TMRepository.cpp
+++ b/src/boards/Main/TMRepository/TMRepository.cpp
@@ -256,7 +256,7 @@ mavlink_message_t TMRepository::packSystemTm(SystemTMList tmId, uint8_t msgId,
             tm.airspeed_pitot  = 0;  // TODO: Implement
 
             // ADA estimation
-            tm.altitude_agl   = -adaState.aglAltitude;
+            tm.altitude_agl   = adaState.aglAltitude;
             tm.ada_vert_speed = adaState.verticalSpeed;
 
             // IMU
diff --git a/src/hardware_in_the_loop/HIL/HILTransceiver.cpp b/src/hardware_in_the_loop/HIL/HILTransceiver.cpp
index 0197201e5..c59c16dc9 100644
--- a/src/hardware_in_the_loop/HIL/HILTransceiver.cpp
+++ b/src/hardware_in_the_loop/HIL/HILTransceiver.cpp
@@ -79,16 +79,17 @@ void HILTransceiver::addResetSampleCounter(HILTimestampManagement *t)
 }*/
 
 /**
- * @brief the thread deals with the communication between the simulator and
- * the mock sensors
+ * @brief The thread deals with the communication between the simulator and the
+ * board.
  *
- * The first read is done in the init() function;
+ * TODO: Check:
+ * The first read is done in the init() function
  *
- * After the first time the data is received the loop of this thread is:
- * - reads the simulated data and copies them in the SensorData structure
- * - notifies every sensor that new data arrived,
- * - waits for the control algorithms to update the actuator data
- * - sends back the value to the simulator
+ * After the first time the data is received, the loop of this thread:
+ * - Reads the simulated data and copies them in the SensorData structure;
+ * - Notifies every sensor that new data arrived;
+ * - Waits for the control algorithms to update the actuator data;
+ * - Sends back the value to the simulator.
  */
 void HILTransceiver::run()
 {
@@ -99,20 +100,23 @@ void HILTransceiver::run()
 
     while (true)
     {
-        /* Scope of the temporary data read from serial and pausing the
-         * kernel in order to copy the data in the shared structure */
+        // Pausing the kernel in order to copy the data in the shared structure
         {
             SimulatorData tempData;
             hilSerial.read(&tempData, sizeof(SimulatorData));
+
             miosix::PauseKernelLock kLock;
             sensorData = tempData;
+
             if (updated)
             {
                 lostUpdate = true;
-                updated    = false;  // we want the last computation
+                updated    = false;  // We want the last computation
             }
         }
 
+        // If this is the first packet to be received, then update the flight
+        // phase manager
         if (!receivedFirstPacket)
         {
             receivedFirstPacket = true;
@@ -120,40 +124,30 @@ void HILTransceiver::run()
                 FlightPhases::SIMULATION_STARTED, true);
         }
 
-        /*
-         * notify all sensors that a new set of data is arrived
-         * [REVIEW] Could be moved in HILFlightPhasesManager
-         */
+        // Notify all sensors that a new set of data is arrived
+        //[REVIEW] Could be moved in HILFlightPhasesManager
         for (auto st : sensorsTimestamp)
-        {
             st->resetSampleCounter();
-        }
 
-        // trigger events relative to the flight phases
-        // TRACE("flags: %f %f %f %f %f %f\n", sensorData.flags.flag_flight,
-        //       sensorData.flags.flag_ascent, sensorData.flags.flag_burning,
-        //       sensorData.flags.flag_airbrakes, sensorData.flags.flag_para1,
-        //       sensorData.flags.flag_para2);
+        // Trigger events relative to the flight phases
         flightPhasesManager->processFlags(sensorData.flags);
 
         if (lostUpdate)
         {
-            // this means also that the number of samples used for the mean sent
+            // This means also that the number of samples used for the mean sent
             // to the HIL simulator is made up of more than the number of
-            // samples we thougt
+            // samples we though
             TRACE("[HILT] lost updates!\n");
             lostUpdate = false;
         }
 
-        // sensorData.print();
         waitActuatorData();
         hilSerial.write(&actuatorData, sizeof(ActuatorData));
-        // actuatorData.print();
     }
 }
 
 /**
- * @brief Waits for the control algorithm(s) to update actuatorData.
+ * @brief Waits for the control algorithms to update actuatorData.
  */
 void HILTransceiver::waitActuatorData()
 {
diff --git a/src/hardware_in_the_loop/HIL/HILTransceiver.h b/src/hardware_in_the_loop/HIL/HILTransceiver.h
index 971581ef4..c1aabfc51 100644
--- a/src/hardware_in_the_loop/HIL/HILTransceiver.h
+++ b/src/hardware_in_the_loop/HIL/HILTransceiver.h
@@ -34,7 +34,7 @@
 class HILFlightPhasesManager;
 
 /**
- * @brief HILTranceiver is a Singleton and provides an easy interface for
+ * @brief HILTransceiver is a Singleton and provides an easy interface for
  * the control algorithms to send and receive data during a simulation
  */
 class HILTransceiver : public Boardcore::ActiveObject
diff --git a/src/hardware_in_the_loop/HILConfig.h b/src/hardware_in_the_loop/HILConfig.h
index 939afcd64..b3f70973e 100644
--- a/src/hardware_in_the_loop/HILConfig.h
+++ b/src/hardware_in_the_loop/HILConfig.h
@@ -44,7 +44,7 @@
 #include "entrypoints/hardware_in_the_loop/HILSimulationConfig.h"
 /* serial simulation with sample manager */
 #elif defined(HILSimulation)
-#include "test-hil/HILSimulationConfig.h"
+#include <HILSimulationConfig.h>
 #elif defined(HIL_ADA)
 #include "test-HIL+ADA/HILSimulationConfig.h"
 #elif defined(HIL_AEROBRAKE)
diff --git a/src/tests/hardware_in_the_loop/test-hil/HILSimulationConfig.h b/src/hardware_in_the_loop/HILSimulationConfig.h
similarity index 100%
rename from src/tests/hardware_in_the_loop/test-hil/HILSimulationConfig.h
rename to src/hardware_in_the_loop/HILSimulationConfig.h
diff --git a/src/tests/hardware_in_the_loop/test-hil/test-hil.cpp b/src/tests/hardware_in_the_loop/test-hil/test-hil.cpp
index ead37287c..fba8fb710 100644
--- a/src/tests/hardware_in_the_loop/test-hil/test-hil.cpp
+++ b/src/tests/hardware_in_the_loop/test-hil/test-hil.cpp
@@ -345,8 +345,8 @@ int main()
                                       .getX());
 
 #ifndef HILMockNAS
-            Boardcore::NASState nasState =
-                Main::NASController::getInstance().getNasState();
+            D(Boardcore::NASState nasState =
+                  Main::NASController::getInstance().getNasState());
             TRACE("nas -> n:%+.3f, e:%+.3f  d:%+.3f\n", nasState.n, nasState.e,
                   nasState.d);
             TRACE("nas -> vn:%+.3f, ve:%+.3f  vd:%+.3f\n", nasState.vn,
-- 
GitLab