ahrs

package module
v0.0.0-...-9c724eb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2023 License: GPL-3.0 Imports: 5 Imported by: 0

README

ahrs

Estimation algorithm based off xioTechnologies Fusion library for Go.

package main

import (
	"fmt"
	"time"

	"github.com/soypat/ahrs"
)

func main() {
    imu := YourIMUInterface()
    estimator := ahrs.NewXioARS(1, imu)
    dt := time.Second
    tick := time.NewTicker(dt)
    for range tick.C {
        estimator.Update(dt.Seconds())
        attitude := estimator.GetQuaternion()
        rot := ahrs.RotationMatrixFromQuat(attitude)

        eulerAngles := rot.TaitBryan(ahrs.OrderXYZ)
        fmt.Printf("IMU attitude: %+v", eulerAngles)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeQuaternion

func NormalizeQuaternion(q quat.Number) (normalized quat.Number)

Types

type EulerAngles

type EulerAngles struct {
	Q     float64
	R     float64
	S     float64
	Order RotationOrder
}

type IMU

type IMU interface {
	// Acceleration returns sensor accelerations in micro gravities
	Acceleration() (ax, ay, az int32)
	// AngularVelocity returns sensor angular velocity in micro radians
	AngularVelocity() (gx, gy, gz int32)
}

IMU represents an IMU or INS sensor such as the MPU6050 or MPU6250

type IMUHeading

type IMUHeading interface {
	IMU
	// North returns the direction of the measured magnetic field
	// in nanoteslas.
	North() (mx, my, mz int32)
}

IMUHeading represents a group of sensors such as the MPU9250 which have accelerometer, gyroscope and magnetometer. These sensors are ideal for sensor fusion techniques such as Madgwick and Mahony algorithms.

type MadgwickFilter

type MadgwickFilter struct {
	Quaternion [4]float64
	Beta       float64
}

func NewMadgwickFilter

func NewMadgwickFilter(beta float64) *MadgwickFilter

func (*MadgwickFilter) GetQuaternion

func (mf *MadgwickFilter) GetQuaternion() quat.Number

func (*MadgwickFilter) UpdateARS

func (mf *MadgwickFilter) UpdateARS(ax, ay, az, gx, gy, gz, samplePeriod float64)

type RotationMatrix

type RotationMatrix struct {
	// contains filtered or unexported fields
}

func RotationMatrixFromQuat

func RotationMatrixFromQuat(q quat.Number) (r RotationMatrix)

func (*RotationMatrix) Mul

func (A *RotationMatrix) Mul(B *RotationMatrix) (result RotationMatrix)

Mul Calculates A*B and returns the result.

func (*RotationMatrix) MulVec

func (r *RotationMatrix) MulVec(v r3.Vec) (result r3.Vec)

func (*RotationMatrix) TaitBryan

func (r *RotationMatrix) TaitBryan(order RotationOrder) (taitBryanAngles EulerAngles)

TaitBryan returns intrinsic angles of a TaitBryan rotation. Assumes the upper 3x3 of r is a pure rotation matrix (i.e, unscaled)

type RotationOrder

type RotationOrder int

RotationOrder represents a convention for rotating a frame. This package implements intrinsic Tait-Bryan rotations at the time of writing this.

const (

	// Tait-Bryan XYZ intrinsic rotation
	OrderXYZ RotationOrder
	// Tait-Bryan YXZ intrinsic rotation
	OrderYXZ
	// Tait-Bryan ZXY intrinsic rotation
	OrderZXY
	// Tait-Bryan ZYX intrinsic rotation
	OrderZYX
	// Tait-Bryan YZX intrinsic rotation
	OrderYZX
	// Tait-Bryan XZY intrinsic rotation
	OrderXZY
)

func (RotationOrder) String

func (r RotationOrder) String() (order string)

type XioAHRS

type XioAHRS struct {
	// contains filtered or unexported fields
}

Taken shamelessly from xioTechnologies/Fusion on github.

func NewXioAHRS

func NewXioAHRS(gain float64, imuWithMagnetometer IMUHeading) *XioAHRS

NewXioAHRS instances a AHRS system with a IMU+heading sensor. Subsequent calls to Update read from IMU.

func NewXioARS

func NewXioARS(gain float64, imu IMU) *XioAHRS

NewFusionAHRS instances a AHRS system with only IMU sensor readings. Calls to Update read from IMU.

func (*XioAHRS) GetLinearAcceleration

func (f *XioAHRS) GetLinearAcceleration() r3.Vec

func (*XioAHRS) GetQuaternion

func (f *XioAHRS) GetQuaternion() quat.Number

func (*XioAHRS) SetGain

func (f *XioAHRS) SetGain(gain float64)

func (*XioAHRS) SetMagneticField

func (f *XioAHRS) SetMagneticField(min, max float64)

func (*XioAHRS) Update

func (f *XioAHRS) Update(samplePeriod float64)

Update updates the internal quaternion

type XioAHRS32

type XioAHRS32 struct {
	// contains filtered or unexported fields
}

Taken shamelessly from xioTechnologies/Fusion on github.

func NewXioAHRS32

func NewXioAHRS32(gain float64, imuWithMagnetometer IMUHeading) *XioAHRS32

NewXioAHRS instances a AHRS system with a IMU+heading sensor. Subsequent calls to Update read from IMU.

func NewXioARS32

func NewXioARS32(gain float64, imu IMU) *XioAHRS32

NewFusionAHRS instances a AHRS system with only IMU sensor readings. Calls to Update read from IMU.

func (*XioAHRS32) GetLinearAcceleration

func (f *XioAHRS32) GetLinearAcceleration() mgl32.Vec3

func (*XioAHRS32) GetQuaternion

func (f *XioAHRS32) GetQuaternion() mgl32.Quat

func (*XioAHRS32) SetGain

func (f *XioAHRS32) SetGain(gain float32)

func (*XioAHRS32) SetMagneticField

func (f *XioAHRS32) SetMagneticField(min, max float32)

func (*XioAHRS32) Update

func (f *XioAHRS32) Update(samplePeriod float32)

Update updates the internal quaternion

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL