|
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.
|
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. | |
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.
| src.mlx_cam.MLX_Cam.__init__ | ( | self, | |
| i2c, | |||
| address = 0x33, | |||
| pattern = ChessPattern, | |||
| width = NUM_COLS, | |||
| height = NUM_ROWS ) |
Set up an MLX90640 camera.
| i2c | An I2C bus which has been set up to talk to the camera; this must be a bus object which has already been set up |
| address | The address of the camera on the I2C bus (default 0x33) |
| pattern | The way frames are interleaved, as we read only half the pixels at a time (default ChessPattern) |
| width | The width of the image in pixels; leave it at default |
| height | The height of the image in pixels; leave it at default |
| 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.
| array | The array to be shown, probably image.v_ir |
| 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.
| array | An array of (self._width * self._height) pixel values |
| pixel | Text which is shown for each pixel, default being a pair of extended-ASCII blocks (code 219) |
| textcolor | The 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 |
| 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.
| array | The array of data to be presented |
| limits | A 2-iterable containing the maximum and minimum values to which the data should be scaled, or None for no scaling |
| 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.
| 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.