Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions MIDAS/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ build_flags =
build_unflags =
-std=gnu++11
lib_deps =
adafruit/Adafruit LIS3MDL@^1.2.1 ; Magnetometer driver
adafruit/Adafruit LIS3MDL@^1.2.1 ; Old magnetometer driver, Adafruit_BNO08x fails or else
sparkfun/SparkFun MMC5983MA Magnetometer Arduino Library@^1.1.4 ; Magnetometer driver
sparkfun/SparkFun u-blox GNSS v3@^3.1.8 ; GPS
Comment on lines -16 to 18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK for now, maybe let's clean it up later.

Context (@MuhammadAli8209 ): Adafruit sensor libraries bring in a bunch of adafruit helper libraries that are needed for the BNO sensor. Since we're removing the BNO, we'll remove this dependency when we merge the LSM changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm 👍


build_src_filter = +<*> -<silsim/> +<hardware/> -<hilsim>
Expand All @@ -33,7 +34,8 @@ build_flags =
build_unflags =
-std=gnu++11
lib_deps =
adafruit/Adafruit LIS3MDL@^1.2.1 ; Magnetometer driver
adafruit/Adafruit LIS3MDL@^1.2.1 ; Old magnetometer driver, Adafruit_BNO08x fails or else
sparkfun/SparkFun MMC5983MA Magnetometer Arduino Library@^1.1.4 ; Magnetometer driver
sparkfun/SparkFun u-blox GNSS v3@^3.1.8 ; GPS

build_src_filter = +<*> -<silsim/> +<hardware/> -<hilsim>
Expand Down
24 changes: 13 additions & 11 deletions MIDAS/src/hardware/Magnetometer.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
#include <Adafruit_LIS3MDL.h>
#include <SparkFun_MMC5983MA_Arduino_Library.h>

#include "sensors.h"
#include "hal.h"

Adafruit_LIS3MDL LIS3MDL; // global static instance of the sensor
SFE_MMC5983MA MMC5983; // global static instance of the sensor

ErrorCode MagnetometerSensor::init() {
if (!LIS3MDL.begin_SPI(LIS3MDL_CS)) { // Checks if sensor is connected
if (MMC5983.begin(MMC5983_CS) == false) { // Checks if sensor is connected
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for this change? (Specifically the == false part)

return ErrorCode::MagnetometerCouldNotBeInitialized;
}
LIS3MDL.setOperationMode(LIS3MDL_CONTINUOUSMODE); // Reading continuously, instead of single-shot or off
LIS3MDL.setDataRate(LIS3MDL_DATARATE_155_HZ);
LIS3MDL.setRange(LIS3MDL_RANGE_4_GAUSS); // Earth's magnetic field is 1/2 gauss, can detect high current
return ErrorCode::NoError;
}

Magnetometer MagnetometerSensor::read() {
// read from aforementioned global instance of sensor
LIS3MDL.read();
uint32_t cx, cy, cz;
double X, Y, Z;

float mx = LIS3MDL.x_gauss;
float my = LIS3MDL.y_gauss;
float mz = LIS3MDL.z_gauss;
Magnetometer reading{mx, my, mz};
MMC5983.getMeasurementXYZ(&cx, &cy, &cz);

double sf = (double)(1 << 17);
X = ((double)cx - sf)/sf;
Y = ((double)cy - sf)/sf;
Z = ((double)cz - sf)/sf;

Magnetometer reading{X, Y, Z};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to assume for this review that this is from the datasheet, but it does look like "magic math" to me... Could you add a doc comment?

return reading;
}
4 changes: 2 additions & 2 deletions MIDAS/src/hardware/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void setup()
pinMode(LSM6DS3_CS, OUTPUT);
pinMode(KX134_CS, OUTPUT);
pinMode(ADXL355_CS, OUTPUT);
pinMode(LIS3MDL_CS, OUTPUT);
pinMode(MMC5983_CS, OUTPUT);
pinMode(BNO086_CS, OUTPUT);
pinMode(BNO086_RESET, OUTPUT);
pinMode(CAN_CS, OUTPUT);
Expand All @@ -89,7 +89,7 @@ void setup()
digitalWrite(LSM6DS3_CS, HIGH);
digitalWrite(KX134_CS, HIGH);
digitalWrite(ADXL355_CS, HIGH);
digitalWrite(LIS3MDL_CS, HIGH);
digitalWrite(MMC5983_CS, HIGH);
digitalWrite(BNO086_CS, HIGH);
digitalWrite(CAN_CS, HIGH);
digitalWrite(E22_CS, HIGH);
Expand Down
5 changes: 3 additions & 2 deletions MIDAS/src/hardware/pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#define ADXL355_CS 44

// magnetometer chip select
#define LIS3MDL_CS 35
#define MMC5983_CS 4
#define MMC5983_INT 7

// orientation chip select, interrupt
#define BNO086_CS 48
Expand Down Expand Up @@ -92,4 +93,4 @@
#define FLASH_DAT2 15
#define FLASH_DAT3 16

#define GPIO_RESET 47
#define GPIO_RESET 47
8 changes: 4 additions & 4 deletions MIDAS/src/sensor_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ struct GPS {
* @brief data from the magnetometer
*/
struct Magnetometer {
float mx;
float my;
float mz;
double mx;
double my;
double mz;
Comment on lines +169 to +171
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed this, I think its OK. I want a second opinion though @MuhammadAli8209 @tjmcmanamen38

Mag isn't buffered to my knowledge, so worst case this just doubles the mag log size from 12 --> 24, which isnt world ending.

};

struct Quaternion {
Expand Down Expand Up @@ -275,4 +275,4 @@ struct PyroState {
struct CameraData {
uint8_t camera_state = 255;
float camera_voltage = 0;
};
};