i2c¶
Classes:
|
A Sparkfun 9DOF combined accelerometer, magnetometer, and gyroscope. |
|
A MLX90640 Temperature sensor. |
- class I2C_9DOF(accel: bool = True, gyro: bool = True, mag: bool = True, gyro_hpf: float = 0.2, accel_range=16, kalman_mode: str = 'both', invert_gyro=False, *args, **kwargs)[source]¶
Bases:
autopilot.hardware.Hardware
A Sparkfun 9DOF combined accelerometer, magnetometer, and gyroscope.
Sensor Datasheet: https://cdn.sparkfun.com/assets/learn_tutorials/3/7/3/LSM9DS1_Datasheet.pdf
Hardware Datasheet: https://github.com/sparkfun/9DOF_Sensor_Stick
Documentation on calculating position values: https://arxiv.org/pdf/1704.06053.pdf
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
Note
use this for processing?? https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6111698/
- Parameters
accel (bool) – Whether the accelerometer should be made active (default: True)
gyro (bool) – Whether the gyroscope should be made active (default: True) – accel must be true if gyro is true
mag (bool) – Whether the magnetomete should be made active (default: True)
gyro_hpf (int, float) – Highpass filter cutoff for onboard gyroscope filter. One of
GYRO_HPF_CUTOFF
(default: 4), orFalse
to disablekalman_mode (‘both’, ‘accel’, None) – Whether to use a kalman filter that integrates accelerometer and gyro readings (‘both’, default), a kalman filter with just the accelerometer values (‘accel’), or just return the raw calculated orientation values from
rotation
invert_gyro (list, tuple) – if not False (default), a list/tuple of the numerical axis index to invert on the gyroscope. eg. passing (1, 2) will invert the y and z axes.
Attributes:
Highpass-filter cutoff frequencies (keys, in Hz) mapped to binary flag.
The accelerometer range.
The magnetometer gain.
The gyroscope scale.
Set the high-pass filter for the gyroscope.
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.
Return roll (rotation around x axis) and pitch (rotation around y axis) computed from the accelerometer
Returns: float: Temperature in Degrees C
Methods:
calibrate
([what, samples, sample_dur])Calibrate sensor readings to correct for bias and scale errors
- 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¶
- GYRO_HPF_CUTOFF = {0.1: 9, 0.2: 8, 0.5: 7, 1: 6, 2: 5, 4: 4, 8: 3, 15: 2, 30: 1, 57: 0}¶
Highpass-filter cutoff frequencies (keys, in Hz) mapped to binary flag.
Note
the frequency of a given binary flag is dependent on the output frequency (952Hz by default, changing frequency is not currently exposed in this object). See Table 52 of the sensor datasheet for more.
- 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 gyro_filter: Union[int, float, bool]¶
Set the high-pass filter for the gyroscope.
Note
the frequency of a given binary flag is dependent on the output frequency (952Hz by default, changing frequency is not currently exposed in this object). See Table 52 of the sensor datasheet for more.
- Parameters
gyro_filter (int, float, False) – Filter frequency (in
GYRO_HPF_CUTOFF
) or False to disable- Returns
current HPF cutoff or
False
if disabled- Return type
- property gyro_polarity¶
- 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 rotation¶
Return roll (rotation around x axis) and pitch (rotation around y axis) computed from the accelerometer
Uses
transform.geometry.IMU_Orientation
to fuse accelerometer and gyroscope with Kalman filter- Returns
np.ndarray - [roll, pitch]
- property temperature¶
Returns: float: Temperature in Degrees C
- calibrate(what: str = 'accelerometer', samples: int = 10000, sample_dur: Optional[float] = None) dict [source]¶
Calibrate sensor readings to correct for bias and scale errors
Note
Currently only calibrating the accelerometer is implemented.
The accelerometer is calibrated by rotating the sensor slowly in all three rotational dimensions in such a way that minimizes linear acceleration (not due to gravity). A perfect sensor would output a sphere of points centered at 0
- Parameters
what (str) – which sensor is to be calibrated (currentlty only “accelerometer” implemented)
samples (int) – number of samples that should be used to compute the calibration
sample_dur (float) – number of seconds to sample for, overrides
samples
if not None (default)
- Returns
calibration dictionary (also saved to disk using
Hardware.calibration
)- Return type
- 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:
what are we anyway?
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.
- 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