SmartWheels self-driving race car. Designed for NXP Cup. Uses FRDM-KL25Z, area-scan camera, and simple image processing to detect and navigate any NXP spec track.

Dependencies:   TSI USBDevice mbed-dev

Fork of SmartWheels by haofan Zheng

Hardwares/IMUManager.h

Committer:
hazheng
Date:
2017-04-09
Revision:
63:d9a81b3d69f5
Parent:
62:bc5caf59fe39
Child:
64:43ab429a37e0

File content as of revision 63:d9a81b3d69f5:

#pragma once
#ifndef IMU_MANAGER_H
#define IMU_MANAGER_H

#define ACCEL_MAG_SA0_0
//#define ACCEL_MAG_SA0_1
#define ACCEL_MAG_SA1_0
//#define ACCEL_MAG_SA1_1

#if   defined(ACCEL_MAG_SA1_0) && defined(ACCEL_MAG_SA0_0)
    #define ACCEL_MAG_SA1 0
    #define ACCEL_MAG_SA0 0
    #define FXOS8700CQ_SLAVE_ADDR 0x1E
#elif defined(ACCEL_MAG_SA1_0) && defined(ACCEL_MAG_SA0_1)
    #define ACCEL_MAG_SA1 0
    #define ACCEL_MAG_SA0 1
    #define FXOS8700CQ_SLAVE_ADDR 0x1D
#elif defined(ACCEL_MAG_SA1_1) && defined(ACCEL_MAG_SA0_0)
    #define ACCEL_MAG_SA1 1
    #define ACCEL_MAG_SA0 0
    #define FXOS8700CQ_SLAVE_ADDR 0x1C
#elif defined(ACCEL_MAG_SA1_1) && defined(ACCEL_MAG_SA0_1)
    #define ACCEL_MAG_SA1 1
    #define ACCEL_MAG_SA0 1
    #define FXOS8700CQ_SLAVE_ADDR 0x1F
#else
    #error Must choose a SA0 and SA1 value for Accel and Mag
#endif

#define FXOS8700CQ_STATUS       0x00

#define FXOS8700CQ_F_SETUP      0x09

#define FXOS8700CQ_SYSMOD       0x0B

#define FXOS8700CQ_WHOAMI       0x0D
#define FXOS8700CQ_WHOAMI_VAL  0xC7

#define FXOS8700CQ_XYZ_DATA_CFG 0x0E
#define FXOS8700CQ_XYZ_DATA_2G 0x00
#define FXOS8700CQ_XYZ_DATA_4G 0x01
#define FXOS8700CQ_XYZ_DATA_8G 0x02

#define FXOS8700CQ_XYZ_DATA_SC FXOS8700CQ_XYZ_DATA_2G

#if FXOS8700CQ_XYZ_DATA_SC == FXOS8700CQ_XYZ_DATA_2G
    #define ACCELER_SCALE_F_MG 0.244f
#elif FXOS8700CQ_XYZ_DATA_SC == FXOS8700CQ_XYZ_DATA_4G
    #define ACCELER_SCALE_F_MG 0.488f
#elif FXOS8700CQ_XYZ_DATA_SC == FXOS8700CQ_XYZ_DATA_8G
    #define ACCELER_SCALE_F_MG 0.976f
#else
    #error Must define a scale for accelerometer!
#endif

#define FXOS8700CQ_CTRL_REG1    0x2A
#define FXOS8700CQ_CTRL_REG1_v 0x05

#define FXOS8700CQ_CTRL_REG2    0x2B
#define FXOS8700CQ_RESET_MASK 0x40

#define FXOS8700CQ_OFF_X        0x2F

#define FXOS8700CQ_OFF_Y        0x30

#define FXOS8700CQ_OFF_Z        0x31
#define OFFSET_SCALE_F  2.0f

#define FXOS8700CQ_M_CTRL_REG1  0x5B

#define FXOS8700CQ_M_CTRL_REG2  0x5C

#define FXOS8700CQ_READ_LEN 13 // status plus 6 channels = 13 bytes

#define IMU_UPDATE_TICK_RATE 0.002f
#define IMU_DEFAULT_G 9.8f

#include <mbed.h>

#ifdef __cplusplus
extern "C" {
#endif

struct imu_vec3
{
    float x;
    float y;
    float z;
};

uint8_t imu_manager_init();

void imu_manager_calibrate();

void imu_manager_begin_tick();

void imu_manager_update();

const volatile struct imu_vec3* imu_manager_get_accl();

const volatile struct imu_vec3* imu_manager_get_velocity();

const volatile struct imu_vec3* imu_manager_get_position();

//const volatile struct imu_vec3* imu_manager_get_magt();

#ifdef __cplusplus
}
#endif

#endif //IMU_MANAGER_H