i2c

Classes

I2C_9DOF(*args, **kwargs)

A `Sparkfun 9DOF<https://www.sparkfun.com/products/13944>`_ combined accelerometer, magnetometer, and gyroscope.

MLX90640([fps, integrate_frames, interpolate])

A MLX90640 Temperature sensor.

class I2C_9DOF(*args, **kwargs)[source]

Bases: autopilot.hardware.Hardware

A `Sparkfun 9DOF<https://www.sparkfun.com/products/13944>`_ combined accelerometer, magnetometer, and gyroscope.

This device uses I2C, so must be connected accordingly:

  • VCC: 3.3V (pin 2)

  • Ground: (any ground pin

  • SDA: I2C.1 SDA (pin 3)

  • SCL: I2C.1 SCL (pin 5)

Attributes

ACCELRANGE_16G

int([x]) -> integer

ACCELRANGE_2G

int([x]) -> integer

ACCELRANGE_4G

int([x]) -> integer

ACCELRANGE_8G

int([x]) -> integer

GYROSCALE_2000DPS

int([x]) -> integer

GYROSCALE_245DPS

int([x]) -> integer

GYROSCALE_500DPS

int([x]) -> integer

MAGGAIN_12GAUSS

int([x]) -> integer

MAGGAIN_16GAUSS

int([x]) -> integer

MAGGAIN_4GAUSS

int([x]) -> integer

MAGGAIN_8GAUSS

int([x]) -> integer

accel_range

The accelerometer range.

acceleration

The calibrated x, y, z acceleration in m/s^2

gyro

The gyroscope X, Y, Z axis values as a 3-tuple of degrees/second values.

gyro_scale

The gyroscope scale.

mag_gain

The magnetometer gain.

magnetic

The magnetometer X, Y, Z axis values as a 3-tuple of gauss values.

temperature

Returns:

This class uses code from the Adafruit Circuitfun library, modified to use pigpio

ACCELRANGE_2G = 0
ACCELRANGE_16G = 8
ACCELRANGE_4G = 16
ACCELRANGE_8G = 24
MAGGAIN_4GAUSS = 0
MAGGAIN_8GAUSS = 32
MAGGAIN_12GAUSS = 64
MAGGAIN_16GAUSS = 96
GYROSCALE_245DPS = 0
GYROSCALE_500DPS = 8
GYROSCALE_2000DPS = 24
property accel_range

The accelerometer range. Must be one of: - I2C_9DOF.ACCELRANGE_2G - I2C_9DOF.ACCELRANGE_4G - I2C_9DOF.ACCELRANGE_8G - I2C_9DOF.ACCELRANGE_16G

property mag_gain

The magnetometer gain. Must be a value of: - I2C_9DOF.MAGGAIN_4GAUSS - I2C_9DOF.MAGGAIN_8GAUSS - I2C_9DOF.MAGGAIN_12GAUSS - I2C_9DOF.MAGGAIN_16GAUSS

property gyro_scale

The gyroscope scale. Must be a value of: - I2C_9DOF.GYROSCALE_245DPS - I2C_9DOF.GYROSCALE_500DPS - I2C_9DOF.GYROSCALE_2000DPS

property acceleration

The calibrated x, y, z acceleration in m/s^2

Returns

x, y, z acceleration

Return type

accel (tuple)

property magnetic

The magnetometer X, Y, Z axis values as a 3-tuple of gauss values.

Returns

x, y, z gauss values

Return type

(tuple)

property gyro

The gyroscope X, Y, Z axis values as a 3-tuple of degrees/second values.

property temperature

Returns: float: Temperature in Degrees C

class MLX90640(fps=64, integrate_frames=64, interpolate=3, **kwargs)[source]

Bases: autopilot.hardware.cameras.Camera

A MLX90640 Temperature sensor.

Parameters
  • fps (int) – Acquisition framerate, must be one of MLX90640.ALLOWED_FPS

  • integrate_frames (int) – Number of frames to average over

  • interpolate (int) – Interpolation multiplier – 3 “increases the resolution” 3x

  • **kwargs – passed to Camera

Variables
  • shape (tuple) – :attr:`~MLX90640.SHAPE_SENSOR

  • integrate_frames (int) – Number of frames to average over

  • interpolate (int) – Interpolation multiplier – 3 “increases the resolution” 3x

  • _grab_event (threading.Event) – capture thread sets every time it gets a frame, _grab waits every time, keeps us from returning same frame twice

Attributes

ALLOWED_FPS

FPS must be one of these

SHAPE_SENSOR

(H, W) Output shape of this sensor is always the same. May differ from MLX90640.shape if interpolate >1

fps

integrate_frames

interpolate

type

str(object=’‘) -> str

Methods

_grab()

Await the _grab_event and then average over the frames stored in

_threaded_capture()

Continually capture frames into the _frames ring buffer

_timestamp([frame])

Just gets Python timestamps for now…

capture_init()

Spawn a _threaded_capture() thread

init_cam()

Set the camera object to use our MLX90640.fps

interpolate_frame(frame)

Interpolate frame according to interpolate using scipy.interpolate.griddata()

release()

Stops the capture thread, cleans up the camera, and calls the superclass release method.

This device uses I2C, so must be connected accordingly:

  • VCC: 3.3V (pin 2)

  • Ground: (any ground pin

  • SDA: I2C.1 SDA (pin 3)

  • SCL: I2C.1 SCL (pin 5)

Uses a modified version of the MLX90640 Library that is capable of outputting 64fps. You must install the library separately, see the setup_mlx90640.sh script.

Capture works a bit differently from other Cameras – the capture_init() method spawns a _threaded_capture() thread, which continually puts frames in the _frames array which serves as a ring buffer. The _grab() method then awaits the _grab_event to be set by the capture thread, and when it is set returns the mean across frames of the ring buffer.

Note

The setup script modifies the systemwide i2c baudrate to 1MHz, which may interfere with other I2C devices. It can be returned to 400kHz (default) by editing /config/boot.txt to read dtparam=i2c_arm_baudrate=400000

type = 'MLX90640'
ALLOWED_FPS = (1, 2, 4, 8, 16, 32, 64)

FPS must be one of these

SHAPE_SENSOR = (32, 24)

(H, W) Output shape of this sensor is always the same. May differ from MLX90640.shape if interpolate >1

property fps
property integrate_frames
property interpolate
init_cam()[source]

Set the camera object to use our MLX90640.fps

capture_init()[source]

Spawn a _threaded_capture() thread

_threaded_capture()[source]

Continually capture frames into the _frames ring buffer

Stops when stopping is set.

_grab()[source]

Await the _grab_event and then average over the frames stored in _frames

Returns

(ndarray) Averaged and interpolated frame

_timestamp(frame=None)[source]

Just gets Python timestamps for now…

Returns

Isoformatted timestamp from datetime

Return type

str

interpolate_frame(frame)[source]

Interpolate frame according to interpolate using scipy.interpolate.griddata()

Parameters

frame (numpy.ndarray) – Frame to interpolate

Returns

Interpolated Frame

Return type

(numpy.ndarray)

release()[source]

Stops the capture thread, cleans up the camera, and calls the superclass release method.