From 86c2d13e24241cf93625032584bf8c02a972ce16 Mon Sep 17 00:00:00 2001
From: su530201 <olivier.kaufmann@umons.ac.be>
Date: Tue, 20 Jun 2023 18:36:30 +0200
Subject: [PATCH] Changes EVENT logging level

---
 ohmpi/hardware_components/abstract_hardware_components.py | 1 +
 ohmpi/hardware_components/ohmpi_card_3_15.py              | 2 +-
 ohmpi/hardware_system.py                                  | 4 ++++
 3 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/ohmpi/hardware_components/abstract_hardware_components.py b/ohmpi/hardware_components/abstract_hardware_components.py
index db89f032..70bbfc1f 100644
--- a/ohmpi/hardware_components/abstract_hardware_components.py
+++ b/ohmpi/hardware_components/abstract_hardware_components.py
@@ -330,6 +330,7 @@ class RxAbstract(ABC):
         self.exec_logger.debug(f'{self.board_name} RX initialization')
         self._adc_gain = 1.
         self._max_sampling_rate = np.inf
+        self._bias = 0.
 
     @property
     def adc_gain(self):
diff --git a/ohmpi/hardware_components/ohmpi_card_3_15.py b/ohmpi/hardware_components/ohmpi_card_3_15.py
index fc480edf..8aebe656 100644
--- a/ohmpi/hardware_components/ohmpi_card_3_15.py
+++ b/ohmpi/hardware_components/ohmpi_card_3_15.py
@@ -254,6 +254,6 @@ class Rx(RxAbstract):
         """ Gets the voltage VMN in Volts
         """
         self.exec_logger.event(f'{self.board_name}\trx_voltage\tbegin\t{datetime.datetime.utcnow()}')
-        u = AnalogIn(self._ads_voltage, ads.P0, ads.P1).voltage * self._coef_p2 * 1000.  # TODO:  check if it should be negative
+        u = AnalogIn(self._ads_voltage, ads.P0, ads.P1).voltage * self._coef_p2 * 1000. - self._bias # TODO:  check if it should be negated
         self.exec_logger.event(f'{self.board_name}\trx_voltage\tend\t{datetime.datetime.utcnow()}')
         return u
diff --git a/ohmpi/hardware_system.py b/ohmpi/hardware_system.py
index e176f2c0..0171c509 100644
--- a/ohmpi/hardware_system.py
+++ b/ohmpi/hardware_system.py
@@ -318,6 +318,10 @@ class OhmPiHardware:
         fig.legend()
         plt.show()
 
+    def calibrate_rx_bias(self):
+        self.tx._bias = np.mean(self.readings[self.readings[:, 2] == 1, 4]) \
+                      + np.mean(self.readings[self.readings[:, 2] == -1, 4]) / 2.
+
     def vab_square_wave(self, vab, cycle_length, sampling_rate=None, cycles=3, polarity=1, append=False):
         self.exec_logger.event(f'OhmPiHardware\tvab_square_wave\tbegin\t{datetime.datetime.utcnow()}')
         self.tx.polarity = polarity
-- 
GitLab