Browse Source

update Calibrate method

Juraj Ďuďák 2 years ago
parent
commit
75bac61226
2 changed files with 15 additions and 10 deletions
  1. 14 7
      src/icm20948.cpp
  2. 1 3
      src/icm20948.h

+ 14 - 7
src/icm20948.cpp

@@ -237,14 +237,11 @@ void Icm20948::Read(void)
 	}
 }
 
-/**
- * @brief Interrupt status regiter - INT_STATUS_1
- * @return 1 – Sensor Register Raw Data, from all sensors, is updated and ready to be read.
- */
+
 uint8_t Icm20948::GetDataStatus(void)
 {
-	uint8_t new_val = _spi->read_single_reg(_activeDevice, ub_0, B0_INT_STATUS_1);
-	return new_val & 0x01;
+	// same register for ACC and GYRO sensor
+	return this->accSensor->GetDataStatus();
 }
 
 /// ---------------------- MAGNETOEMTER -----------------------------------
@@ -310,6 +307,15 @@ Sensor::Sensor(SpiManager *spi, int8_t activeDevice){
 	_scaleFactor = 1.0f;
 }
 
+/**
+ * @brief Interrupt status regiter - INT_STATUS_1
+ * @return 1 – Sensor Register Raw Data, from all sensors, is updated and ready to be read.
+ */
+uint8_t Sensor::GetDataStatus(void)
+{
+	uint8_t new_val = _spi->read_single_reg(_activeDevice, ub_0, B0_INT_STATUS_1);
+	return new_val & 0x01;
+}
 
 SensorGyro::SensorGyro(SpiManager *spi, int8_t activeDevice):Sensor(spi, activeDevice){
 
@@ -665,7 +671,7 @@ void SensorGyro::Calibrate(void)
 
 	for(int i = 0; i < 100; i++)
 	{
-//		this->gyroSensor->Read(&temp);
+		while(this->GetDataStatus() == 0);
 		this->Read(&temp);
 		gyro_bias[0] += temp.x;
 		gyro_bias[1] += temp.y;
@@ -703,6 +709,7 @@ void SensorAccel::Calibrate()
 
 	for(int i = 0; i < 100; i++)
 	{
+		while(this->GetDataStatus() == 0);
 		this->Read(&temp);
 		accel_bias[0] += temp.x;
 		accel_bias[1] += temp.y;

+ 1 - 3
src/icm20948.h

@@ -35,6 +35,7 @@ public:
 	uint8_t GetRange(void);
 	uint8_t CheckLowPassInputValue(uint8_t);
 	void Calibrate(void);
+	uint8_t GetDataStatus(void);
 
 
 	virtual axises *GetData(void) = 0;
@@ -89,9 +90,6 @@ public:
 };
 
 
-
-
-
 class Icm20948{
 private:
 	uint8_t _numDevices;