i2c¶
Classes:
|
A `Sparkfun 9DOF<https://www.sparkfun.com/products/13944>`_ combined accelerometer, magnetometer, and gyroscope. |
|
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)
This class uses code from the Adafruit Circuitfun library, modified to use pigpio
Attributes:
The accelerometer range.
The magnetometer gain.
The gyroscope scale.
The calibrated x, y, z acceleration in m/s^2
The magnetometer X, Y, Z axis values as a 3-tuple of gauss values.
The gyroscope X, Y, Z axis values as a 3-tuple of degrees/second values.
Returns: float: Temperature in Degrees C
-
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
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
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 readdtparam=i2c_arm_baudrate=400000
Attributes:
FPS must be one of these
(H, W) Output shape of this sensor is always the same.
Methods:
init_cam
()Set the camera object to use our
MLX90640.fps
Spawn a
_threaded_capture()
threadContinually capture frames into the
_frames
ring buffer_grab
()Await the
_grab_event
and then average over the frames stored in_frames
_timestamp
([frame])Just gets Python timestamps for now…
interpolate_frame
(frame)Interpolate frame according to
interpolate
usingscipy.interpolate.griddata()
release
()Stops the capture thread, cleans up the camera, and calls the superclass release method.
-
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 bufferStops 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
-
interpolate_frame
(frame)[source]¶ Interpolate frame according to
interpolate
usingscipy.interpolate.griddata()
- Parameters
frame (
numpy.ndarray
) – Frame to interpolate- Returns
Interpolated Frame
- Return type