diff --git a/src/boards/MockupMain/Configs/SensorsConfig.h b/src/boards/MockupMain/Configs/SensorsConfig.h index bfedffad7e15287d2887486ee5753d4cc893da04..3c06ffb808a0a96be1ff416415405192366b741e 100644 --- a/src/boards/MockupMain/Configs/SensorsConfig.h +++ b/src/boards/MockupMain/Configs/SensorsConfig.h @@ -43,7 +43,7 @@ namespace SensorsConfig using namespace std::chrono_literals; // clang-format on -constexpr unsigned int NUMBER_OF_SENSORS = 7; +constexpr unsigned int NUMBER_OF_SENSORS = 6; constexpr uint32_t MAG_CALIBRATION_PERIOD = 100; // [ms] // BMX160 @@ -52,14 +52,14 @@ constexpr Boardcore::BMX160Config::AccelerometerRange BMX160_ACC_FSR_ENUM = Boardcore::BMX160Config::AccelerometerRange::G_16; constexpr Boardcore::BMX160Config::GyroscopeRange BMX160_GYRO_FSR_ENUM = Boardcore::BMX160Config::GyroscopeRange::DEG_1000; -constexpr unsigned int BMX160_ACC_GYRO_ODR = 100; +constexpr unsigned int BMX160_ACC_GYRO_ODR = 50; constexpr Boardcore::BMX160Config::OutputDataRate BMX160_ACC_GYRO_ODR_ENUM = - Boardcore::BMX160Config::OutputDataRate::HZ_100; + Boardcore::BMX160Config::OutputDataRate::HZ_50; constexpr unsigned int BMX160_MAG_ODR = 100; constexpr Boardcore::BMX160Config::OutputDataRate BMX160_MAG_ODR_ENUM = Boardcore::BMX160Config::OutputDataRate::HZ_100; -constexpr unsigned int BMX160_TEMP_DIVIDER = 1000; +constexpr unsigned int BMX160_TEMP_DIVIDER = 0; constexpr unsigned int BMX160_FIFO_WATERMARK = 40; @@ -87,12 +87,12 @@ constexpr auto LPS22DF_PERIOD = 20_hz; constexpr auto UBXGPS_SAMPLE_RATE = 5; // The +5 is needed because GPS data must be read faster than it is produced (to // not cause delays) -constexpr auto UBXGPS_PERIOD = 10_hz; +constexpr auto UBXGPS_PERIOD = 6_hz; // ADS constexpr Boardcore::ADS131M08Defs::OversamplingRatio ADS131M08_OVERSAMPLING_RATIO = - Boardcore::ADS131M08Defs::OversamplingRatio::OSR_4096; + Boardcore::ADS131M08Defs::OversamplingRatio::OSR_1024; constexpr bool ADS131M08_GLOBAL_CHOP_MODE = true; constexpr auto ADS131M08_PERIOD = 1000_hz; @@ -111,7 +111,7 @@ static const Boardcore::AxisOrthoOrientation BMX160_AXIS_ROTATION = { Boardcore::Direction::NEGATIVE_Y, Boardcore::Direction::NEGATIVE_Z}; // LIS magnetometer -constexpr Boardcore::LIS3MDL::ODR MAG_LIS_ODR = Boardcore::LIS3MDL::ODR_80_HZ; +constexpr Boardcore::LIS3MDL::ODR MAG_LIS_ODR = Boardcore::LIS3MDL::ODR_155_HZ; constexpr Boardcore::LIS3MDL::FullScale MAG_LIS_FULLSCALE = Boardcore::LIS3MDL::FS_4_GAUSS; @@ -126,9 +126,9 @@ constexpr float BATTERY_VOLTAGE_COEFF = (150 + 40.2) / 40.2; // imprecision, avoid clearing the fifo before the interrupt constexpr auto BMX160_SAMPLE_PERIOD = std::chrono::milliseconds( BMX160_FIFO_FILL_TIME * (BMX160_FIFO_WATERMARK + 30) * 4 / 1024); // [ms] -constexpr auto LIS3MDL_SAMPLE_PERIOD = 6_hz; +constexpr auto LIS3MDL_SAMPLE_PERIOD = 100_hz; constexpr auto INTERNAL_ADC_SAMPLE_PERIOD = 1_hz; -constexpr auto INTERNAL_TEMP_SAMPLE_PERIOD = 2_hz; +constexpr auto INTERNAL_TEMP_SAMPLE_PERIOD = 1_hz; // LoadCell constexpr auto LOAD_CELL_SAMPLE_PERIOD = 1000_hz; diff --git a/src/boards/MockupMain/Sensors/Sensors.cpp b/src/boards/MockupMain/Sensors/Sensors.cpp index 66ceccf797c080befc86903b1026d8cba62806fa..781e98bcafa2fe6ab490bc4084462853b1caa78b 100644 --- a/src/boards/MockupMain/Sensors/Sensors.cpp +++ b/src/boards/MockupMain/Sensors/Sensors.cpp @@ -113,7 +113,7 @@ bool Sensors::start() // Read the magnetometer calibration from predefined file // Init all the sensors - bmx160Init(); + // bmx160Init(); // bmx160WithCorrectionInit(); lis3mdlInit(); h3lisInit(); @@ -124,40 +124,41 @@ bool Sensors::start() // batteryVoltageInit(); loadCellInit(); - // Add the magnetometer calibration to the scheduler - size_t result = scheduler->addTask( - [&]() - { - // Gather the last sample data - MagnetometerData lastSample = getBMX160LastSample(); - - // Feed the data to the calibrator inside a protected area. - // Contention is not high and the use of a mutex is suitable to - // avoid pausing the kernel for this calibration operation + /* + // Add the magnetometer calibration to the scheduler + size_t result = scheduler->addTask( + [&]() { - miosix::Lock<FastMutex> l(calibrationMutex); - magCalibrator.feed(lastSample); - - // Compute the correction - SixParametersCorrector cal = magCalibrator.computeResult(); + // Gather the last sample data + MagnetometerData lastSample = getBMX160LastSample(); - // Check result validity and save it - if (!isnan(cal.getb()[0]) && !isnan(cal.getb()[1]) && - !isnan(cal.getb()[2]) && !isnan(cal.getA()[0]) && - !isnan(cal.getA()[1]) && !isnan(cal.getA()[2])) + // Feed the data to the calibrator inside a protected area. + // Contention is not high and the use of a mutex is suitable to + // avoid pausing the kernel for this calibration operation { - magCalibration = cal; + miosix::Lock<FastMutex> l(calibrationMutex); + magCalibrator.feed(lastSample); + + // Compute the correction + SixParametersCorrector cal = magCalibrator.computeResult(); + + // Check result validity and save it + if (!isnan(cal.getb()[0]) && !isnan(cal.getb()[1]) && + !isnan(cal.getb()[2]) && !isnan(cal.getA()[0]) && + !isnan(cal.getA()[1]) && !isnan(cal.getA()[2])) + { + magCalibration = cal; + } } - } - }, - MAG_CALIBRATION_PERIOD); - + }, + MAG_CALIBRATION_PERIOD); + */ // Create sensor manager with populated map and configured scheduler - manager = new SensorManager(sensorMap, scheduler); - miosix::GpioPin interruptPin = miosix::sensors::bmx160::intr::getPin(); + manager = new SensorManager(sensorMap, scheduler); + /*miosix::GpioPin interruptPin = miosix::sensors::bmx160::intr::getPin(); enableExternalInterrupt(interruptPin.getPort(), interruptPin.getNumber(), - InterruptTrigger::FALLING_EDGE, 0); - return manager->start() && result != 0; + InterruptTrigger::FALLING_EDGE, 0);*/ + return manager->start(); } void Sensors::stop() { manager->stop(); } @@ -277,7 +278,7 @@ void Sensors::h3lisInit() // Get the correct SPI configuration SPIBusConfig config = H3LIS331DL::getDefaultSPIConfig(); - config.clockDivider = SPI::ClockDivider::DIV_16; + config.clockDivider = SPI::ClockDivider::DIV_4; // Create sensor instance with configured parameters h3lis331dl = new H3LIS331DL( @@ -301,7 +302,7 @@ void Sensors::lps22Init() // Get the correct SPI configuration SPIBusConfig config = LPS22DF::getDefaultSPIConfig(); - config.clockDivider = SPI::ClockDivider::DIV_16; + config.clockDivider = SPI::ClockDivider::DIV_4; // Configure the device LPS22DF::Config sensorConfig; @@ -330,7 +331,7 @@ void Sensors::ubxGpsInit() // Get the correct SPI configuration SPIBusConfig config = UBXGPSSpi::getDefaultSPIConfig(); - config.clockDivider = SPI::ClockDivider::DIV_64; + config.clockDivider = SPI::ClockDivider::DIV_16; // Create sensor instance with configured parameters ubxGps = new UBXGPSSpi(modules.get<Buses>()->spi1, @@ -353,7 +354,7 @@ void Sensors::ads131Init() // Configure the SPI SPIBusConfig config; - config.clockDivider = SPI::ClockDivider::DIV_16; + config.clockDivider = SPI::ClockDivider::DIV_4; // Configure the device ADS131M08::Config sensorConfig;