Git Product home page Git Product logo

sensor-imu's Introduction

sensor-imu

Lint Test

C library to interact with various IMUs (MPU6000, MPU6050, MPU6500, ICM20600, ICM20601, ICM2062). It was written for the raspberry-imu-viewer project, an orientation viewer in 3D for the Raspberry Pi, where you can also find a working example on how to use this library.

Features:

  • works with Raspberry Pi / Linux and probably with almost every single-board computer equipped with I2C
  • IMU model and address are autodetected during initialization
  • sampling rate can reach 1khz (when I2C speed is 400khz)
  • orientation estimation algorithms are available in folder /orientation

Installation

  1. On the Raspberry Pi, enable I2C and set speed to 400khz: edit /boot/config.txt and add:

    dtparam=i2c_arm=on
    dtparam=i2c_arm_baudrate=400000
    

    then edit /etc/modules and add

    i2c-dev
    

    then reboot the system.

  2. Install the dependencies:

    sudo apt install -y git make gcc libc6-dev libi2c-dev
    
  3. Clone this repository:

    git clone https://github.com/aler9/sensor-imu
    
  4. Create a sample source file named main.c:

    #include <stdio.h>
    #include <stdlib.h>
    
    #include "sensor-imu/imu.h"
    
    int main() {
        imut *imu;
        error *err = imu_init(&imu, "/dev/i2c-1", IMU_ACC_RANGE_2G, IMU_GYRO_RANGE_250DPS);
        if(err != NULL) {
            printf("ERR: %s\n", err);
            return -1;
        }
    
        imu_output io;
        err = imu_read(imu, &io);
        if(err != NULL) {
            printf("ERR: %s\n", err);
            return -1;
        }
    
        printf("gyro x,y,z: %f, %f, %f\n", io.gyro.x, io.gyro.y, io.gyro.z);
        printf("acc x,y,z: %f, %f, %f\n", io.acc.x, io.acc.y, io.acc.z);
        return 0;
    }
  5. Build:

    gcc -o main sensor-imu/*.c main.c
    
  6. Launch:

    ./main
    

API Documentation

error *imu_init(imut **pobj, const char *path, imu_acc_range acc_range, imu_gyro_range gyro_range)

Creates an IMU reader. Arguments a pointer to an empty imut* object, the path to the I2C device, the accelerometer range and the gyroscope range. It returns NULL in case of success, otherwise returns an error.

void imu_destroy(imut *obj)

Destroys an IMU reader.

error *imu_read(imut *obj, imu_output *out)

Performs a measurement. Returns an imu_output that contains the measurements.

Accelerometer measurements are expressed in [g], while gyroscope measurements are expressed in [deg/s]

Links

sensor-imu's People

Contributors

aler9 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sensor-imu's Issues

uninitialize problem

When calculate acc align matrix and gyro bias, temp var should be initialized, or it lead to get "nan" value

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.