From 5194a6c9868b1153522a5117b027c27d9af6d736 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nicol=C3=B2=20Caruso?= <niccolo.caruso@skywarder.eu>
Date: Wed, 2 Oct 2024 15:17:14 +0200
Subject: [PATCH] [ARP] Fixes, old codes remnances removed, SMA VN300 sample
 checking feedback

General fixes: Actuators removed led GPIO, removed emergency button related things, changed timers comments.
SMA VN300 sampled and update antennas coordinates in case of feedback states.
Pin files authors linter.
---
 .../Automated/Actuators/Actuators.cpp         | 55 ++-----------------
 .../Automated/Actuators/Actuators.h           | 18 ++----
 .../Automated/PinHandler/PinData.h            |  2 +-
 .../Automated/PinHandler/PinHandler.cpp       |  2 +-
 .../Automated/PinHandler/PinHandler.h         |  2 +-
 .../Groundstation/Automated/SMA/SMA.cpp       | 39 +++++++------
 6 files changed, 36 insertions(+), 82 deletions(-)

diff --git a/src/boards/Groundstation/Automated/Actuators/Actuators.cpp b/src/boards/Groundstation/Automated/Actuators/Actuators.cpp
index 79ce0fc55..b9463c541 100644
--- a/src/boards/Groundstation/Automated/Actuators/Actuators.cpp
+++ b/src/boards/Groundstation/Automated/Actuators/Actuators.cpp
@@ -1,5 +1,5 @@
 /* Copyright (c) 2023-2024 Skyward Experimental Rocketry
- * Author: Emilio Corigliano, Nicolò Caruso
+ * Authors: Emilio Corigliano, Nicolò Caruso
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -34,15 +34,13 @@ namespace Antennas
 
 using namespace Config;
 
-// TIM1_CH4 PA11 AF1
+// TIM1_CH1 PA8 AF1 Stepper H step
 //      |
-// TIM3_CH2 PC7  AF2
+// TIM3_CH2 PC7  AF2 Stepper H count
 
-// TIM4_CH1 PD12 AF2
+// TIM4_CH1 PD12 AF2 Stepper V step
 //      |
-// TIM8_CH4 PC9  AF3
-
-GpioPin ledRGB = GpioPin(GPIOG_BASE, 14);
+// TIM8_CH1 PC6  AF3 Stepper V count
 
 CountedPWM countedPwmX(StepperSettings::SERVO1_PULSE_TIM,
                        StepperSettings::SERVO1_PULSE_CH,
@@ -72,10 +70,6 @@ Actuators::Actuators()
 {
 }
 
-/**
- * @brief Dummy start for actuators
- * @note The real enable is done by the `arm()` method
- */
 void Actuators::start() {}
 
 void Actuators::arm()
@@ -145,12 +139,6 @@ ActuationStatus Actuators::move(StepperList axis, int16_t steps)
 {
     auto *stepper = getStepper(axis);
 
-    if (emergencyStop)
-    {
-        logStepperData(axis, stepper->getState(0));
-        return ActuationStatus::EMERGENCY_STOP;
-    }
-
     ActuationStatus actuationState =
         ActuationStatus::OK;  //< In case the move command is not limited
 
@@ -186,12 +174,6 @@ ActuationStatus Actuators::moveDeg(StepperList axis, float degrees)
 {
     auto *stepper = getStepper(axis);
 
-    if (emergencyStop)
-    {
-        logStepperData(axis, stepper->getState(0));
-        return ActuationStatus::EMERGENCY_STOP;
-    }
-
     ActuationStatus actuationState =
         ActuationStatus::OK;  //< In case the move command is not limited
 
@@ -236,31 +218,4 @@ void Actuators::setMultipliers(StepperList axis, float multiplier)
             break;
     }
 }
-
-void Actuators::IRQemergencyStop()
-{
-    // Do not preempt during this method
-    emergencyStop = true;
-    countedPwmX.stop();  // Terminate current stepper actuation
-    countedPwmY.stop();  // Terminate current stepper actuation
-    stepperX.disable();  // Disable the horizontal movement
-    stepperY.enable();   // Don't make the antenna fall
-
-    ledOn();
-
-    // Set LED to RED
-}
-
-void Actuators::IRQemergencyStopRecovery()
-{
-    // Do not preempt during this method
-    emergencyStop = false;
-    stepperX.enable();  // Re-enable horizontal movement
-    stepperY.enable();  // Re-enable vertical movement
-
-    ledOff();
-
-    // Set LED to GREEN
-}
-
 }  // namespace Antennas
diff --git a/src/boards/Groundstation/Automated/Actuators/Actuators.h b/src/boards/Groundstation/Automated/Actuators/Actuators.h
index 317bd33ca..b388f3155 100644
--- a/src/boards/Groundstation/Automated/Actuators/Actuators.h
+++ b/src/boards/Groundstation/Automated/Actuators/Actuators.h
@@ -1,5 +1,5 @@
 /* Copyright (c) 2023-2024 Skyward Experimental Rocketry
- * Author: Emilio Corigliano, Nicolò Caruso
+ * Authors: Emilio Corigliano, Nicolò Caruso
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -29,13 +29,13 @@
 #include "ActuatorsData.h"
 #include "actuators/stepper/StepperPWM.h"
 
-// TIM1_CH4 PA11 AF1
+// TIM1_CH1 PA8 AF1 Stepper H step
 //      |
-// TIM3_CH2 PC7  AF2
+// TIM3_CH2 PC7  AF2 Stepper H count
 
-// TIM4_CH1 PD12 AF2
+// TIM4_CH1 PD12 AF2 Stepper V step
 //      |
-// TIM8_CH4 PC9  AF3
+// TIM8_CH1 PC6  AF3 Stepper V count
 
 namespace Antennas
 {
@@ -75,9 +75,6 @@ public:
      */
     void disarm();
 
-    void IRQemergencyStop();
-    void IRQemergencyStopRecovery();
-
     ActuationStatus setSpeed(StepperList axis, float speed);
     ActuationStatus move(StepperList axis, int16_t steps);
     ActuationStatus moveDeg(StepperList axis, float degrees);
@@ -92,8 +89,6 @@ public:
     int16_t getCurrentPosition(StepperList axis);
     float getCurrentDegPosition(StepperList axis);
 
-    bool isEmergencyStopped() const { return emergencyStop; }
-
     /**
      * @brief Getter for the last actuation of the wanted stepper.
      * @param axis The stepper from which we want this information.
@@ -206,8 +201,5 @@ private:
         Config::stepperXConfig.MAX_SPEED;  // Speed of the stepper [rps]
     float speedY =
         Config::stepperYConfig.MAX_SPEED;  // Speed of the stepper [rps]
-
-    bool emergencyStop =
-        false;  // Whether the system performed an emergency stop
 };
 }  // namespace Antennas
diff --git a/src/boards/Groundstation/Automated/PinHandler/PinData.h b/src/boards/Groundstation/Automated/PinHandler/PinData.h
index 10be191d6..b22b80f75 100644
--- a/src/boards/Groundstation/Automated/PinHandler/PinData.h
+++ b/src/boards/Groundstation/Automated/PinHandler/PinData.h
@@ -1,5 +1,5 @@
 /* Copyright (c) 2019-2024 Skyward Experimental Rocketry
- * Author: Matteo Pignataro, Nicolò Caruso
+ * Authors: Matteo Pignataro, Nicolò Caruso
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
diff --git a/src/boards/Groundstation/Automated/PinHandler/PinHandler.cpp b/src/boards/Groundstation/Automated/PinHandler/PinHandler.cpp
index 71ea2be21..d27517762 100644
--- a/src/boards/Groundstation/Automated/PinHandler/PinHandler.cpp
+++ b/src/boards/Groundstation/Automated/PinHandler/PinHandler.cpp
@@ -1,5 +1,5 @@
 /* Copyright (c) 2024 Skyward Experimental Rocketry
- * Authors: Nicolò Caruso
+ * Author: Nicolò Caruso
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
diff --git a/src/boards/Groundstation/Automated/PinHandler/PinHandler.h b/src/boards/Groundstation/Automated/PinHandler/PinHandler.h
index 3bb5ef27d..07448cdd1 100644
--- a/src/boards/Groundstation/Automated/PinHandler/PinHandler.h
+++ b/src/boards/Groundstation/Automated/PinHandler/PinHandler.h
@@ -1,5 +1,5 @@
 /* Copyright (c) 2024 Skyward Experimental Rocketry
- * Authors: Nicolò Caruso
+ * Author: Nicolò Caruso
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
diff --git a/src/boards/Groundstation/Automated/SMA/SMA.cpp b/src/boards/Groundstation/Automated/SMA/SMA.cpp
index 31d0b1bab..9afec5cf2 100644
--- a/src/boards/Groundstation/Automated/SMA/SMA.cpp
+++ b/src/boards/Groundstation/Automated/SMA/SMA.cpp
@@ -144,23 +144,31 @@ void SMA::update()
     auto* sensors     = getModule<Sensors>();
     rocketCoordinates = hub->getRocketOrigin();
 
-    // update antenna coordinates
-    vn300Data = sensors->getVN300LastSample();
-    if (vn300Data.fix_gps == 3)
+    // Update the antenna position except in case of no feedback
+    if (status.state != SMAState::FIX_ROCKET_NF &&
+        status.state != SMAState::INIT_ERROR &&
+        status.state != SMAState::ACTIVE_NF &&
+        status.state != SMAState::ARM_READY &&
+        status.state != SMAState::ACTIVE_NF)
     {
-        // build the GPSData struct with the VN300 data
-        antennaCoordinates.gpsTimestamp  = vn300Data.insTimestamp;
-        antennaCoordinates.latitude      = vn300Data.latitude;
-        antennaCoordinates.longitude     = vn300Data.longitude;
-        antennaCoordinates.height        = vn300Data.altitude;
-        antennaCoordinates.velocityNorth = vn300Data.nedVelX;
-        antennaCoordinates.velocityEast  = vn300Data.nedVelY;
-        antennaCoordinates.velocityDown  = vn300Data.nedVelZ;
-        antennaCoordinates.satellites    = vn300Data.fix_gps;
-        antennaCoordinates.fix           = vn300Data.fix_gps;
+        // update antenna coordinates
+        vn300Data = sensors->getVN300LastSample();
+        if (vn300Data.fix_gps == 3)
+        {
+            // build the GPSData struct with the VN300 data
+            antennaCoordinates.gpsTimestamp  = vn300Data.insTimestamp;
+            antennaCoordinates.latitude      = vn300Data.latitude;
+            antennaCoordinates.longitude     = vn300Data.longitude;
+            antennaCoordinates.height        = vn300Data.altitude;
+            antennaCoordinates.velocityNorth = vn300Data.nedVelX;
+            antennaCoordinates.velocityEast  = vn300Data.nedVelY;
+            antennaCoordinates.velocityDown  = vn300Data.nedVelZ;
+            antennaCoordinates.satellites    = vn300Data.fix_gps;
+            antennaCoordinates.fix           = vn300Data.fix_gps;
 
-        // update follower with coordinates
-        follower.setAntennaCoordinates(antennaCoordinates);
+            // update follower with coordinates
+            follower.setAntennaCoordinates(antennaCoordinates);
+        }
     }
 
     // update follower with the rocket GPS data
@@ -222,7 +230,6 @@ void SMA::update()
 
             // update the follower with the propagated state
             follower.setLastRocketNasState(predicted.getNasState());
-            VN300Data vn300Data = getModule<Sensors>()->getVN300LastSample();
             follower.setLastAntennaAttitude(vn300Data);
             follower.update();  // step the follower
             FollowerState follow = follower.getState();
-- 
GitLab