From 702853d67ccfd79e4202f9957c6117eadcdb786c Mon Sep 17 00:00:00 2001 From: Jonas Holmberg Date: Mon, 5 Dec 2016 09:59:14 +0100 Subject: [PATCH] Added compass calibration variables to EEPROM and CLI --- UAV-ControlSystem/inc/config/eeprom.h | 4 ++++ UAV-ControlSystem/inc/drivers/compass.h | 3 ++- UAV-ControlSystem/src/config/cli.c | 3 ++- UAV-ControlSystem/src/config/eeprom.c | 14 ++++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/UAV-ControlSystem/inc/config/eeprom.h b/UAV-ControlSystem/inc/config/eeprom.h index 9cd0e7f..8ba1a2c 100644 --- a/UAV-ControlSystem/inc/config/eeprom.h +++ b/UAV-ControlSystem/inc/config/eeprom.h @@ -201,6 +201,10 @@ typedef enum { EEPROM_FLAG_ACCELTUNE_FINE_ROLL, EEPROM_FLAG_ACCELTUNE_FINE_PITCH, + /* Compass calibration */ + EEPROM_FLAG_COMPASSTUNE_MAGNET_MAX, + EEPROM_FLAG_COMPASSTUNE_MAGNET_MIN, + /* Counts the amount of system settings */ EEPROM_SYS_COUNT } EEPROM_SYS_ID_t; diff --git a/UAV-ControlSystem/inc/drivers/compass.h b/UAV-ControlSystem/inc/drivers/compass.h index 4201866..ef8b327 100644 --- a/UAV-ControlSystem/inc/drivers/compass.h +++ b/UAV-ControlSystem/inc/drivers/compass.h @@ -9,6 +9,7 @@ void calibrate_compass(); void calculate_heading(); - +extern int MagnetMax[3]; +extern int MagnetMin[3]; #endif //DRIVERS_COMPASS_H diff --git a/UAV-ControlSystem/src/config/cli.c b/UAV-ControlSystem/src/config/cli.c index e731d12..c77b8e2 100644 --- a/UAV-ControlSystem/src/config/cli.c +++ b/UAV-ControlSystem/src/config/cli.c @@ -26,6 +26,7 @@ #include "drivers/motors.h" #include "drivers/accel_gyro.h" #include "Flight/pid.h" +#include "drivers/compass.h" #define cliActivateCharacter 35 #define commandValueError 0xFFFFFFFFFFFFFFFF @@ -1554,7 +1555,7 @@ void cliRun() if (ReceiveBinaryDecision(121,110)) { TransmitBack("Starting calibration! \n\n\r"); - TransmitBack("NOT IMPLEMENTED! \n\n\r"); + calibrate_compass(); TransmitBack("Calibration complete! \n\n\r"); } else diff --git a/UAV-ControlSystem/src/config/eeprom.c b/UAV-ControlSystem/src/config/eeprom.c index 2569742..93aff53 100644 --- a/UAV-ControlSystem/src/config/eeprom.c +++ b/UAV-ControlSystem/src/config/eeprom.c @@ -25,6 +25,7 @@ #include "drivers/motormix.h" #include "drivers/motors.h" #include "Flight/pid.h" +#include "drivers/compass.h" /* Reads the EEPROM version from EEPROM - Is compared to EEPROM_SYS_VERSION */ uint8_t stored_eeprom_identifier; @@ -282,6 +283,19 @@ EEPROM_DATA_t eeprom_sys_Arr[EEPROM_SYS_COUNT] = { .size = sizeof(float), .dataPtr = &(accPitchFineTune), }, + + /* Compass calibration */ + [EEPROM_FLAG_COMPASSTUNE_MAGNET_MAX] = + { + .size = sizeof(MagnetMax), + .dataPtr = &(MagnetMax), + }, + [EEPROM_FLAG_COMPASSTUNE_MAGNET_MIN] = + { + .size = sizeof(MagnetMin), + .dataPtr = &(MagnetMin), + }, + }; /* Data pointers and sizes for profile content */