adxl345

package
v0.2.45 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package adxl345 implements the MovementSensor interface for the ADXL345 accelerometer attached to an I2C bus on the robot (the chip supports communicating over SPI as well, but this package does not support that interface). The datasheet for this chip is available at: https://www.analog.com/media/en/technical-documentation/data-sheets/adxl345.pdf

We support reading the accelerometer data off of the chip. We do not yet support using the digital interrupt pins to notify on events (freefall, collision, etc.).

Because we only support I2C interaction, the CS pin must be wired to hot (which tells the chip which communication interface to use). The chip has two possible I2C addresses, which can be selected by wiring the SDO pin to either hot or ground:

  • if SDO is wired to ground, it uses the default I2C address of 0x53
  • if SDO is wired to hot, it uses the alternate I2C address of 0x1D

If you use the alternate address, your config file for this component must set its "use_alternate_i2c_address" boolean to true.

Index

Constants

View Source
const (
	// an unsigned time value representing the maximum time that an event must be above the
	// THRESH_TAP threshold to qualify as a tap event [625 µs/LSB].
	DurAddr byte = 0x21
	// info on which interrupts have been enabled.
	IntEnableAddr byte = 0x2E
	// info on which interrupt pin to send each interrupt.
	IntMapAddr byte = 0x2F
	// info on which interrupt has gone off since the last time this address has been read from.
	IntSourceAddr byte = 0x30
	// an unsigned time value representing the wait time from the detection of a tap event to the
	// start of the time window [1.25 ms/LSB].
	LatentAddr byte = 0x22
	// info on which axes have been turned on for taps (X, Y, Z are bits 2, 1, 0 respectively).
	TapAxesAddr byte = 0x2A
	// an unsigned threshold value for tap interrupts [62.5 mg/LSB ].
	ThreshTapAddr byte = 0x1D
	// che threshold value, in unsigned format, for free-fall detection.
	ThreshFfAddr byte = 0x28
	// the  minimum time that the value of all axes must be less than THRESH_FF to generate a free-fall interrupt.
	TimeFfAddr byte = 0x29
)

addresses relevant to interrupts.

View Source
const (
	// ThreshTapScaleFactor is the scale factor for THRESH_TAP register.
	ThreshTapScaleFactor float32 = 62.5
	// DurScaleFactor is the scale factor for DUR register.
	DurScaleFactor float32 = 625
	// TimeFfScaleFactor is the scale factor for TIME_FF register.
	TimeFfScaleFactor float32 = .5
	// ThreshFfScaleFactor is the scale factor for THRESH_FF register.
	ThreshFfScaleFactor float32 = 62.5
)

Variables

This section is empty.

Functions

func NewAdxl345

NewAdxl345 is a constructor to create a new object representing an ADXL345 accelerometer.

Types

type Config added in v0.2.36

type Config struct {
	BoardName              string          `json:"board"`
	I2cBus                 string          `json:"i2c_bus"`
	UseAlternateI2CAddress bool            `json:"use_alternate_i2c_address,omitempty"`
	SingleTap              *TapConfig      `json:"tap,omitempty"`
	FreeFall               *FreeFallConfig `json:"free_fall,omitempty"`
}

Config is a description of how to find an ADXL345 accelerometer on the robot.

func (*Config) Validate added in v0.2.36

func (cfg *Config) Validate(path string) ([]string, error)

Validate ensures all parts of the config are valid, and then returns the list of things we depend on.

type FreeFallConfig added in v0.2.36

type FreeFallConfig struct {
	AccelerometerPin int     `json:"accelerometer_pin"`
	InterruptPin     string  `json:"interrupt_pin"`
	Threshold        float32 `json:"threshold,omitempty"`
	Time             float32 `json:"time_ms,omitempty"`
}

FreeFallConfig is a description of the configs for free fall registers.

func (*FreeFallConfig) ValidateFreeFallConfigs added in v0.2.36

func (freefallCfg *FreeFallConfig) ValidateFreeFallConfigs(path string) error

ValidateFreeFallConfigs validates the freefall piece of the configs.

type InterruptID added in v0.2.26

type InterruptID = uint8

InterruptID is a type of interrupts available on ADXL345.

const (
	// SingleTap is a key value used to find various needs associated with this interrupt.
	SingleTap InterruptID = iota
	// FreeFall is a key value used to find various needs associated with this interrupt.
	FreeFall InterruptID = iota
)

type TapConfig added in v0.2.36

type TapConfig struct {
	AccelerometerPin int     `json:"accelerometer_pin"`
	InterruptPin     string  `json:"interrupt_pin"`
	ExcludeX         bool    `json:"exclude_x,omitempty"`
	ExcludeY         bool    `json:"exclude_y,omitempty"`
	ExcludeZ         bool    `json:"exclude_z,omitempty"`
	Threshold        float32 `json:"threshold,omitempty"`
	Dur              float32 `json:"dur_us,omitempty"`
}

TapConfig is a description of the configs for tap registers.

func (*TapConfig) ValidateTapConfigs added in v0.2.36

func (tapCfg *TapConfig) ValidateTapConfigs(path string) error

ValidateTapConfigs validates the tap piece of the configs.

Jump to

Keyboard shortcuts

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