資源簡介
最近在使用MPU9250來學(xué)習(xí)姿態(tài)解算,查詢了非常多的網(wǎng)上關(guān)于MPU6050和MPU9250的資料,發(fā)現(xiàn)內(nèi)置的DMP可以計(jì)算出姿態(tài)角,可原代碼是用在MSP430和STM407上的,手上有塊F429的野火板子,移植過程越到非常多的巨坑,現(xiàn)在想記錄下來給各位初學(xué)者提供一些便利,這里是源代碼,包含教程PPT
代碼片段和文件信息
//系統(tǒng)頭文件
#include?“arch.h“
#include?“stdio.h“
//外設(shè)頭文件
#include?“usart.h“
#include?“i2c.h“
#include?“gpio.h“
#include?“main.h“
#include?“board_resource.h“
//DMP_Lib頭文件
#include?“inv_mpu.h“
#include?“inv_mpu_dmp_motion_driver.h“
#include?“invensense.h“
#include?“invensense_adv.h“
#include?“eMPL_outputs.h“
#include?“mltypes.h“
#include?“mpu.h“
#include?“l(fā)og.h“
#include?“packet.h“
/*?Private?typedef?-----------------------------------------------------------*/
/*?Data?read?from?MPL.?*/
#define?PRINT_ACCEL?????(0x01)
#define?PRINT_GYRO??????(0x02)
#define?PRINT_QUAT??????(0x04)
#define?PRINT_COMPASS???(0x08)
#define?PRINT_EULER?????(0x10)
#define?PRINT_ROT_MAT???(0x20)
#define?PRINT_HEADING???(0x40)
#define?PRINT_PEDO??????(0x80)
#define?PRINT_LINEAR_ACCEL?(0x100)
#define?PRINT_GRAVITY_VECTOR?(0x200)
volatile?uint32_t?hal_timestamp?=?0;
#define?ACCEL_ON????????(0x01)
#define?GYRO_ON?????????(0x02)
#define?COMPASS_ON??????(0x04)
#define?MOTION??????????(0)
#define?NO_MOTION???????(1)
/*?Starting?sampling?rate.?*/
#define?DEFAULT_MPU_HZ??(20)
#define?FLASH_SIZE??????(512)
#define?FLASH_MEM_START?((void*)0x1800)
#define?PEDO_READ_MS????(1000)
#define?TEMP_READ_MS????(500)
#define?COMPASS_READ_MS?(100)
struct?rx_s?{
????unsigned?char?header[3];
????unsigned?char?cmd;
};
struct?hal_s?{
????unsigned?char?lp_accel_mode;
????unsigned?char?sensors;
????unsigned?char?dmp_on;
????unsigned?char?wait_for_tap;
????volatile?unsigned?char?new_gyro;
????unsigned?char?motion_int_mode;
????unsigned?long?no_dmp_hz;
????unsigned?long?next_pedo_ms;
????unsigned?long?next_temp_ms;
????unsigned?long?next_compass_ms;
????unsigned?int?report;
????unsigned?short?dmp_features;
????struct?rx_s?rx;
};
static?struct?hal_s?hal?=?{0};
/*?USB?RX?binary?semaphore.?Actually?it‘s?just?a?flag.?Not?included?in?struct
?*?because?it‘s?declared?extern?elsewhere.
?*/
volatile?unsigned?char?rx_new;
unsigned?char?*mpl_key?=?(unsigned?char*)“eMPL?5.1“;
/*?Platform-specific?information.?Kinda?like?a?boardfile.?*/
struct?platform_data_s?{
????signed?char?orientation[9];
};
/*?The?sensors?can?be?mounted?onto?the?board?in?any?orientation.?The?mounting
?*?matrix?seen?below?tells?the?MPL?how?to?rotate?the?raw?data?from?the
?*?driver(s).
?*?TODO:?The?following?matrices?refer?to?the?configuration?on?internal?test
?*?boards?at?Invensense.?If?needed?please?modify?the?matrices?to?match?the
?*?chip-to-body?matrix?for?your?particular?set?up.
?*/
static?struct?platform_data_s?gyro_pdata?=?{
????.orientation?=?{
????????1?0?0
????????0?1?0
????????0?0?1
????}
};
#if?defined?MPU9150?||?defined?MPU9250
static?struct?platform_data_s?compass_pdata?=?{
????.orientation?=?{
????????0?1?0
????????1?0?0
????????0?0?-1
????}
};
#define?COMPASS_ENABLED?1
#elif?defined?AK8975_SECONDARY
static?struct?platform_data_s?compass_pdata?=?{
????.orientation?=?{
????????-1?0?0
????????0
評(píng)論
共有 條評(píng)論