Aula Jazmati
Published © MIT

Data Fusion with Hexabitz IMU module (H0BR40)

Build a tiny IMU data fusion logger by connecting Hexabitz IMU module to Hexabitz Micro SD card module.

AdvancedFull instructions provided6 hours658
Data Fusion with Hexabitz IMU module (H0BR40)

Things used in this project

Story

Read more

Schematics

The Design/2

Code

IMU Data fusion logger test2

C/C++
SD Module code
/**
  ******************************************************************************
  * File Name          : main.c
  * Description        : Main program body
  ******************************************************************************
  *
  * COPYRIGHT(c) 2015 STMicroelectronics
  *
  * Redistribution and use in source and binary forms, with or without modification,
  * are permitted provided that the following conditions are met:
  *   1. Redistributions of source code must retain the above copyright notice,
  *      this list of conditions and the following disclaimer.
  *   2. Redistributions in binary form must reproduce the above copyright notice,
  *      this list of conditions and the following disclaimer in the documentation
  *      and/or other materials provided with the distribution.
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
  *      may be used to endorse or promote products derived from this software
  *      without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  ******************************************************************************
  */
	
/*
		MODIFIED by Hexabitz for BitzOS (BOS) V0.2.1 - Copyright (C) 2017-2020 Hexabitz
    All rights reserved
*/

/* Includes ------------------------------------------------------------------*/
#include "BOS.h"


/* Private variables ---------------------------------------------------------*/

/* Private function prototypes -----------------------------------------------*/
volatile float acc;
volatile float gyro;
volatile float angle;

/* Main functions ------------------------------------------------------------*/

int main(void)
{


  /* MCU Configuration----------------------------------------------------------*/

  /* Reset all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all user peripherals */

	/* Initialize BitzOS */
	BOS_Init();

  /* Call init function for freertos objects (in freertos.c) */
  MX_FREERTOS_Init();

  /* Start scheduler */
  osKernelStart();
  
  /* We should never get here as control is now taken by the scheduler */

  /* Infinite loop */
  while (1)
  {


  }


}

/*-----------------------------------------------------------*/

/* User Task */
void UserTask(void * argument)
{
AddBOSvar(FMT_FLOAT , (uint32_t) &acc );
AddBOSvar(FMT_FLOAT , (uint32_t) &angle );
AddBOSvar(FMT_FLOAT , (uint32_t) &gyro );
Delay_ms(10);
CreateLog("k1" , RATE , 10 , FMT_SPACE ,FMT_SAMPLE,"#");
LogVar("k1" , MEMORY_DATA_FLOAT , (uint32_t) &acc, "acc");
LogVar("k1" , MEMORY_DATA_FLOAT , (uint32_t) &angle, "Kalman");
LogVar("k1" , MEMORY_DATA_FLOAT , (uint32_t) &gyro, "gyro");

//start logging
IND_ON();
StartLog("k1");
Delay_s(180);
StopLog("k1");

IND_OFF();				// Signal the end of the log
Delay_ms(100); IND_blink(200);		
Delay_ms(100); IND_blink(200);
 /* Infinite loop */
for(;;)
  {
		
	}
}

/*-----------------------------------------------------------*/

/************************ (C) COPYRIGHT HEXABITZ *****END OF FILE****/

IMU Data fusion logger test2

C/C++
IMU module
/**
  ******************************************************************************
  * File Name          : main.c
  * Description        : Main program body
  ******************************************************************************
  *
  * COPYRIGHT(c) 2015 STMicroelectronics
  *
  * Redistribution and use in source and binary forms, with or without modification,
  * are permitted provided that the following conditions are met:
  *   1. Redistributions of source code must retain the above copyright notice,
  *      this list of conditions and the following disclaimer.
  *   2. Redistributions in binary form must reproduce the above copyright notice,
  *      this list of conditions and the following disclaimer in the documentation
  *      and/or other materials provided with the distribution.
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
  *      may be used to endorse or promote products derived from this software
  *      without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  ******************************************************************************
  */
	
/*
		MODIFIED by Hexabitz for BitzOS (BOS) V0.2.1 - Copyright (C) 2017-2020 Hexabitz
    All rights reserved
*/

/* Includes ------------------------------------------------------------------*/
#include "BOS.h"
#include "math.h"
#include "KalmanIMU.h"
/* Private variables ---------------------------------------------------------*/
float a =0.0f;
float rr =0.0f;
float gx = 0.0f;
float gy = 0.0f;
float gz = 0.0f;
float ax =0.0f ;
float ay =0.0f;
float az =0.0f;
Kalman k[3];
int mx =0 ;
int my =0;
int mz =0;
float angles[] = { 0.0f, 0.0f, 0.0f };
/* Private function prototypes -----------------------------------------------*/

/* Main functions ------------------------------------------------------------*/

int main(void)
{


  /* MCU Configuration----------------------------------------------------------*/

  /* Reset all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all user peripherals */

	/* Initialize BitzOS */
	BOS_Init();

  /* Call init function for freertos objects (in freertos.c) */
  MX_FREERTOS_Init();

  /* Start scheduler */
  osKernelStart();
  
  /* We should never get here as control is now taken by the scheduler */

  /* Infinite loop */
  while (1)
  {


  }


}

/*-----------------------------------------------------------*/

/* User Task */
void UserTask(void * argument)
{
BOS.trace = TRACE_NONE;
AddBOSvar(FMT_FLOAT , (uint32_t) &*(angles + 2) );
AddBOSvar(FMT_FLOAT , (uint32_t) &angles[2] );
AddBOSvar(FMT_FLOAT , (uint32_t) &gz );
IND_blink(100);
Delay_ms(10);
int flag1 = 0;
		
  for(;;)
  {
		if (flag1 ==0)
{
for(int i=0; i<2000 ;i++)
   	{
SampleGyroDPS(&gz,&gx,&gy);
SampleMagMGauss(&mx,&my,&mz);
SampleAccG(&ax,&ay,&az);

calcEulerAngles(angles , ax, ay, az, mx, my, mz);
WriteRemote(2,(uint32_t) &*(angles + 2), 1, FMT_FLOAT,0);	
KalmanInit( k, *angles);
KalmanInit(k + 1, *(angles + 1));
KalmanInit(k + 2, *(angles + 2));
KalmanStep(k, *angles, gx);
KalmanStep(k+1,  *(angles + 1), gy);
KalmanStep(k+2,  *(angles + 2), gz);
WriteRemote(2,(uint32_t) &angles[2],2, FMT_FLOAT,0);	
WriteRemote(2,(uint32_t) &gz, 3, FMT_FLOAT,0);	
IND_blink(5);
flag1 =1;
IND_OFF();
			}
}
	}			
}


/*-----------------------------------------------------------*/

/************************ (C) COPYRIGHT HEXABITZ *****END OF FILE****/

Sensor Fusion

C/C++
IMU module
/**
  ******************************************************************************
  * File Name          : main.c
  * Description        : Main program body
  ******************************************************************************
  *
  * COPYRIGHT(c) 2015 STMicroelectronics
  *
  * Redistribution and use in source and binary forms, with or without modification,
  * are permitted provided that the following conditions are met:
  *   1. Redistributions of source code must retain the above copyright notice,
  *      this list of conditions and the following disclaimer.
  *   2. Redistributions in binary form must reproduce the above copyright notice,
  *      this list of conditions and the following disclaimer in the documentation
  *      and/or other materials provided with the distribution.
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
  *      may be used to endorse or promote products derived from this software
  *      without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  ******************************************************************************
  */
	
/*
		MODIFIED by Hexabitz for BitzOS (BOS) V0.2.1 - Copyright (C) 2017-2020 Hexabitz
    All rights reserved
*/

/* Includes ------------------------------------------------------------------*/
#include "BOS.h"
#include "math.h"
#include "KalmanIMU.h"
/* Private variables ---------------------------------------------------------*/
float a =0.0f;
float rr =0.0f;
float gx = 0.0f;
float gy = 0.0f;
float gz = 0.0f;
float ax =0.0f ;
float ay =0.0f;
float az =0.0f;
Kalman k[3];
int mx =0 ;
int my =0;
int mz =0;
float angles[] = { 0.0f, 0.0f, 0.0f };
/* Private function prototypes -----------------------------------------------*/

/* Main functions ------------------------------------------------------------*/

int main(void)
{


  /* MCU Configuration----------------------------------------------------------*/

  /* Reset all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all user peripherals */

	/* Initialize BitzOS */
	BOS_Init();

  /* Call init function for freertos objects (in freertos.c) */
  MX_FREERTOS_Init();

  /* Start scheduler */
  osKernelStart();
  
  /* We should never get here as control is now taken by the scheduler */

  /* Infinite loop */
  while (1)
  {


  }


}

/*-----------------------------------------------------------*/

/* User Task */
void UserTask(void * argument)
{
BOS.trace = TRACE_NONE;
AddBOSvar(FMT_FLOAT , (uint32_t) &*(angles + 2) );
AddBOSvar(FMT_FLOAT , (uint32_t) &angles[2] );
AddBOSvar(FMT_FLOAT , (uint32_t) &gz );
IND_blink(100);
Delay_ms(10);
int flag1 = 0;
		
  for(;;)
  {
		if (flag1 ==0)
{
for(int i=0; i<2000 ;i++)
   	{
SampleGyroDPS(&gz,&gx,&gy);
SampleMagMGauss(&mx,&my,&mz);
SampleAccG(&ax,&ay,&az);

calcEulerAngles(angles , ax, ay, az, mx, my, mz);
WriteRemote(2,(uint32_t) &*(angles + 2), 1, FMT_FLOAT,0);	
KalmanInit( k, *angles);
KalmanInit(k + 1, *(angles + 1));
KalmanInit(k + 2, *(angles + 2));
KalmanStep(k, *angles, gx);
KalmanStep(k+1,  *(angles + 1), gy);
KalmanStep(k+2,  *(angles + 2), gz);
WriteRemote(2,(uint32_t) &angles[2],2, FMT_FLOAT,0);	
WriteRemote(2,(uint32_t) &gz, 3, FMT_FLOAT,0);	
IND_blink(5);
flag1 =1;
IND_OFF();
			}
}
	}			
}


/*-----------------------------------------------------------*/

/************************ (C) COPYRIGHT HEXABITZ *****END OF FILE****/

Credits

Aula Jazmati

Aula Jazmati

49 projects • 192 followers
(PhD) in Electronic Engineering 2023 💡🕊️

Comments