mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-24 16:55:36 +03:00
added driver for MMA8452QT accelerometer
added mag_declination set option to cli - oops status in cli now prints which ACC hardware is used. work in proress to show difference between hardware with MPU6050 and MPU3050 git-svn-id: https://afrodevices.googlecode.com/svn/trunk/baseflight@157 7c89a4a9-59b9-e629-4cfe-3a2d53b20e61
This commit is contained in:
parent
b929f79b54
commit
59ccf93dd3
8 changed files with 2746 additions and 2704 deletions
|
@ -123,6 +123,7 @@ typedef struct sensor_t
|
|||
#include "drv_hmc5883l.h"
|
||||
#include "drv_i2c.h"
|
||||
#include "drv_ledring.h"
|
||||
#include "drv_mma845x.h"
|
||||
#include "drv_mpu3050.h"
|
||||
#include "drv_mpu6050.h"
|
||||
#include "drv_pwm.h"
|
||||
|
|
11
src/cli.c
11
src/cli.c
|
@ -16,6 +16,7 @@ static void cliVersion(char *cmdline);
|
|||
|
||||
// from sensors.c
|
||||
extern uint8_t batteryCellCount;
|
||||
extern uint8_t accHardware;
|
||||
|
||||
// from config.c RC Channel mapping
|
||||
extern const char rcChannelLetters[];
|
||||
|
@ -45,6 +46,11 @@ const char *sensorNames[] = {
|
|||
"ACC", "BARO", "MAG", "SONAR", "GPS", NULL
|
||||
};
|
||||
|
||||
//
|
||||
const char *accNames[] = {
|
||||
"ADXL345", "MPU6050", "MMA845x", NULL
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
char *param;
|
||||
|
@ -117,6 +123,7 @@ const clivalue_t valueTable[] = {
|
|||
{ "gimbal_roll_mid", VAR_UINT16, &cfg.gimbal_roll_mid, 100, 3000 },
|
||||
{ "acc_lpf_factor", VAR_UINT8, &cfg.acc_lpf_factor, 0, 250 },
|
||||
{ "gyro_lpf", VAR_UINT16, &cfg.gyro_lpf, 0, 256 },
|
||||
{ "mag_declination", VAR_INT16, &cfg.mag_declination, -18000, 18000 },
|
||||
{ "gps_baudrate", VAR_UINT32, &cfg.gps_baudrate, 1200, 115200 },
|
||||
{ "serial_baudrate", VAR_UINT32, &cfg.serial_baudrate, 1200, 115200 },
|
||||
{ "p_pitch", VAR_UINT8, &cfg.P8[PITCH], 0, 200},
|
||||
|
@ -476,6 +483,10 @@ static void cliStatus(char *cmdline)
|
|||
uartPrint((char *)sensorNames[i]);
|
||||
uartWrite(' ');
|
||||
}
|
||||
if (sensors(SENSOR_ACC)) {
|
||||
uartPrint("ACCHW: ");
|
||||
uartPrint((char *)accNames[accHardware]);
|
||||
}
|
||||
uartPrint("\r\n");
|
||||
|
||||
uartPrint("Cycle Time: ");
|
||||
|
|
|
@ -13,7 +13,7 @@ config_t cfg;
|
|||
const char rcChannelLetters[] = "AERT1234";
|
||||
|
||||
static uint32_t enabledSensors = 0;
|
||||
uint8_t checkNewConf = 16;
|
||||
uint8_t checkNewConf = 17;
|
||||
|
||||
void parseRcChannels(const char *input)
|
||||
{
|
||||
|
@ -127,7 +127,7 @@ void checkFirstTime(bool reset)
|
|||
cfg.accZero[0] = 0;
|
||||
cfg.accZero[1] = 0;
|
||||
cfg.accZero[2] = 0;
|
||||
cfg.magDeclination = 0; // For example, -6deg 37min, = -637 Japan, format is [sign]dddmm (degreesminutes) default is zero.
|
||||
cfg.mag_declination = 0; // For example, -6deg 37min, = -637 Japan, format is [sign]dddmm (degreesminutes) default is zero.
|
||||
cfg.acc_lpf_factor = 100;
|
||||
cfg.gyro_lpf = 42;
|
||||
cfg.gyro_smoothing_factor = 0x00141403; // default factors of 20, 20, 3 for R/P/Y
|
||||
|
|
9
src/mw.h
9
src/mw.h
|
@ -53,6 +53,13 @@ typedef enum GimbalFlags {
|
|||
GIMBAL_DISABLEAUX34 = 1 << 2,
|
||||
} GimbalFlags;
|
||||
|
||||
// Type of accelerometer used
|
||||
typedef enum AccelSensors {
|
||||
ADXL345,
|
||||
MPU6050,
|
||||
MMA845x
|
||||
} AccelSensors;
|
||||
|
||||
/*********** RC alias *****************/
|
||||
#define ROLL 0
|
||||
#define PITCH 1
|
||||
|
@ -109,7 +116,7 @@ typedef struct config_t {
|
|||
uint8_t dynThrPID;
|
||||
int16_t accZero[3];
|
||||
int16_t magZero[3];
|
||||
int16_t magDeclination; // Get your magnetic decliniation from here : http://magnetic-declination.com/
|
||||
int16_t mag_declination; // Get your magnetic decliniation from here : http://magnetic-declination.com/
|
||||
int16_t accTrim[2];
|
||||
|
||||
// sensor-related stuff
|
||||
|
|
|
@ -19,6 +19,7 @@ extern float magneticDeclination;
|
|||
|
||||
sensor_t acc; // acc access functions
|
||||
sensor_t gyro; // gyro access functions
|
||||
uint8_t accHardware = 0; // which accel chip is used.
|
||||
|
||||
#ifdef FY90Q
|
||||
// FY90Q analog gyro/acc
|
||||
|
@ -47,8 +48,10 @@ void sensorsAutodetect(void)
|
|||
sensorsClear(SENSOR_MAG);
|
||||
|
||||
// Init sensors
|
||||
if (sensors(SENSOR_ACC))
|
||||
if (sensors(SENSOR_ACC)) {
|
||||
acc.init();
|
||||
accHardware = ADXL345;
|
||||
}
|
||||
if (sensors(SENSOR_BARO))
|
||||
bmp085Init();
|
||||
|
||||
|
@ -56,18 +59,27 @@ void sensorsAutodetect(void)
|
|||
if (mpu6050Detect(&acc, &gyro)) { // first, try MPU6050, and re-enable acc (if ADXL345 is missing) since this chip has it built in
|
||||
sensorsSet(SENSOR_ACC);
|
||||
acc.init();
|
||||
accHardware = MPU6050;
|
||||
} else if (!mpu3050Detect(&gyro)) {
|
||||
// if this fails, we get a beep + blink pattern. we're doomed, no gyro or i2c error.
|
||||
failureMode(3);
|
||||
}
|
||||
|
||||
// Try to init MMA8452
|
||||
if (mma8452Detect(&acc)) {
|
||||
sensorsSet(SENSOR_ACC);
|
||||
acc.init();
|
||||
accHardware = MMA845x;
|
||||
}
|
||||
|
||||
// this is safe because either mpu6050 or mpu3050 sets it, and in case of fail, none do.
|
||||
gyro.init();
|
||||
// todo: this is driver specific :(
|
||||
mpu3050Config(cfg.gyro_lpf);
|
||||
|
||||
// calculate magnetic declination
|
||||
deg = cfg.magDeclination / 100;
|
||||
min = cfg.magDeclination % 100;
|
||||
deg = cfg.mag_declination / 100;
|
||||
min = cfg.mag_declination % 100;
|
||||
magneticDeclination = deg + ((float)min * (1.0f / 60.0f));
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue