ME 405 Term Project: Thermal Imaging Nerf Turret 1.0
A library that contains software used to control and fire an automated Nerf turret. The turret uses a MLX90640 Thermal Imaging camera to determine opponent's position and fire.
src.mlx_cam.MLX_Cam Class Reference

Class which wraps an MLX90640 thermal infrared camera driver to make it easier to grab and use an image. More...

Public Member Functions

 __init__ (self, i2c, address=0x33, pattern=ChessPattern, width=NUM_COLS, height=NUM_ROWS)
 Set up an MLX90640 camera.
 
 ascii_image (self, array, pixel="██", textcolor="0;180;0")
 Show low-resolution camera data as shaded pixels on a text screen.
 
 ascii_art (self, array)
 Show a data array from the IR image as ASCII art.
 
 get_csv (self, array, data, limits=None)
 Generate a string containing image data in CSV format.
 
 get_image (self)
 Get one image from a MLX90640 camera, blocking other tasks from running until the image has been received.
 
 get_image_nonblocking (self)
 Get an image from an MLX90640 camera in a non-blocking way.
 

Static Public Attributes

str asc = " -.:=+*#%@"
 A "standard" set of characters of different densities to make ASCII art.
 

Protected Attributes

 _i2c
 The I2C bus to which the camera is attached.
 
 _addr
 The address of the camera on the I2C bus.
 
 _pattern
 The pattern for reading the camera, usually ChessPattern.
 
 _width
 The width of the image in pixels, which should be 32.
 
 _height
 The height of the image in pixels, which should be 24.
 
 _getting_image
 Tracks whether an image is currently being retrieved.
 
 _subpage
 Which subpage (checkerboard half) of the image is being retrieved.
 
 _camera
 
 _image
 A local reference to the image object within the camera driver.
 

Detailed Description

Class which wraps an MLX90640 thermal infrared camera driver to make it easier to grab and use an image.

This image is in "raw" mode, meaning it has not been calibrated (which takes lots of time and memory) and only gives relative IR emission seen by pixels, not estimates of the temperatures.

Constructor & Destructor Documentation

◆ __init__()

src.mlx_cam.MLX_Cam.__init__ ( self,
i2c,
address = 0x33,
pattern = ChessPattern,
width = NUM_COLS,
height = NUM_ROWS )

Set up an MLX90640 camera.

Parameters
i2cAn I2C bus which has been set up to talk to the camera; this must be a bus object which has already been set up
addressThe address of the camera on the I2C bus (default 0x33)
patternThe way frames are interleaved, as we read only half the pixels at a time (default ChessPattern)
widthThe width of the image in pixels; leave it at default
heightThe height of the image in pixels; leave it at default

Member Function Documentation

◆ ascii_art()

src.mlx_cam.MLX_Cam.ascii_art ( self,
array )

Show a data array from the IR image as ASCII art.

Each character is repeated twice so the image isn't squished laterally. A code of "><" indicates an error, probably caused by a bad pixel in the camera.

Parameters
arrayThe array to be shown, probably image.v_ir

◆ ascii_image()

src.mlx_cam.MLX_Cam.ascii_image ( self,
array,
pixel = "██",
textcolor = "0;180;0" )

Show low-resolution camera data as shaded pixels on a text screen.

The data is printed as a set of characters in columns for the number of rows in the camera's image size. This function is intended for testing an MLX90640 thermal infrared sensor.

A pair of extended ACSII filled rectangles is used by default to show each pixel so that the aspect ratio of the display on screens isn't too smushed. Each pixel is colored using ANSI terminal escape codes which work in only some programs such as PuTTY. If shown in simpler terminal programs such as the one used in Thonny, the display just shows a bunch of pixel symbols with no difference in shading (boring).

A simple auto-brightness scaling is done, setting the lowest brightness of a filled block to 0 and the highest to 255. If there are bad pixels, this can reduce contrast in the rest of the image.

After the printing is done, character color is reset to a default of medium-brightness green, or something else if chosen.

Parameters
arrayAn array of (self._width * self._height) pixel values
pixelText which is shown for each pixel, default being a pair of extended-ASCII blocks (code 219)
textcolorThe color to which printed text is reset when the image has been finished, as a string "<r>;<g>;<b>" with each letter representing the intensity of red, green, and blue from 0 to 255

◆ get_csv()

src.mlx_cam.MLX_Cam.get_csv ( self,
array,
data,
limits = None )

Generate a string containing image data in CSV format.

This function generates a set of lines, each having one row of image data in Comma Separated Variable format. The lines can be printed or saved to a file using a for loop.

Parameters
arrayThe array of data to be presented
limitsA 2-iterable containing the maximum and minimum values to which the data should be scaled, or None for no scaling

◆ get_image()

src.mlx_cam.MLX_Cam.get_image ( self)

Get one image from a MLX90640 camera, blocking other tasks from running until the image has been received.

Grab one image from the given camera and return it. Both subframes (the odd checkerboard portions of the image) are grabbed and combined (maybe; this is the raw version, so the combination is sketchy and not fully tested). It is assumed that the camera is in the ChessPattern (default) mode as it probably should be.

Returns
A reference to the image object we've just filled with data

◆ get_image_nonblocking()

src.mlx_cam.MLX_Cam.get_image_nonblocking ( self)

Get an image from an MLX90640 camera in a non-blocking way.

This function is to be called repeatedly; it will return None until a complete image has been retrieved (this takes around a quarter to half second) and will then return the image.

Example: This code would be inside a task function which yields repeatedly as long as there isn't a complete image available.

image = None
while not image:
image = camera.get_image_nonblocking()
yield(state)

The documentation for this class was generated from the following file: