Display#

rc.display

Copyright MIT MIT License

BWSI Autonomous RACECAR Course Racecar Neo LTS

File Name: display.py File Description: Defines the interface of the Display module of the racecar_core library.

class display.Display(isHeadless: bool)#

Allows the user to print images to the screen.

abstract create_window() None#

Creates an empty window into which images will be displayed.

Note

It is not necessary to call create_window before any of the other display methods (show_color_image, show_depth_image, etc.). These methods will automatically create a new window if one was not already created.

Example:

# Creates a window
rc.camera.create_window()

# Display an image in this window
image = rc.camera.get_color_image()
rc.display.show_color_image(image)
abstract get_matrix() NDArray[8, 24, UInt]#

Returns the current configuration of the dot matrix display module.

Returns:

np.uint8) representing the current configuration of the dot matrix display module.

Return type:

An 8x24 NumPy array (data type

Note

A 1 in the matrix indicates an LED that is on, while a 0 in the matrix indicates an LED that is off.

Example:

# Gets current configuration values of the dot matrix module
dot_matrix = rc.display.get_matrix()
new_matrix() NDArray[8, 24, UInt]#

Returns a new matrix of all zeroes for the dot matrix display module.

Returns:

np.uint8) of all zeroes.

Return type:

An 8x24 NumPy array (data type

Example:

# Create a new matrix of all zeroes.
my_matrix = rc.display.new_matrix()

# Set the top left pixel to on, then display the matrix on the dot matrix.
my_matrix[0, 0] = 1
rc.display.set_matrix(my_matrix)
abstract set_matrix(matrix: NDArray[8, 24, UInt]) None#

Sets the dot matrix display module to the pattern in the argument (2D matrix).

Parameters:

matrix – The 8x24 NumPy array with the pattern to be displayed on the dot matrix display module.

Note

A 1 in the matrix indicates an LED that is on, while a 0 in the matrix indicates an LED that is off.

Example:

dot_matrix = np.ones((8, 24), dtype=np.uint8)

# Turn all the LEDs on the dot matrix module on
rc.display.set_matrix(dot_matrix)
abstract set_matrix_intensity(intensity: float) None#

Sets the intensity of the dot matrix display module.

Parameters:

intensity – The LED intensity (between 0.0 and 1.0) to set.

Note

Due to the way the racecar’s LED driver works, an intensity of 0.0 does not correspond to turning the LEDs completely off, and therefore set_matrix_intensity cannot be used to make a fade-in or fade-out animation.

Example:

# Pulse the dot matrix display using a sin wave profile.
def update():
    global time
    time += rc.get_delta_time()

    intensity = rc_utils.remap_range(math.sin(time), -1.0, 1.0, 0.0, 1.0)
    rc.display.set_matrix_intensity(intensity)
abstract show_color_image(image: NDArray) None#

Displays a color image in a window.

Parameters:

image – The color image to display to the screen.

Example:

image = rc.camera.get_color_image()

# Show the image captured by the camera
rc.display.show_color_image(image)
show_depth_image(image: NDArray[Any, Any, Float], max_depth: int = 1000, points: list[tuple[int, int]] = []) None#

Displays a depth image in grayscale in a window.

Parameters:
  • image – The depth image to display to the screen.

  • max_depth – The farthest depth to show in the image in cm. Anything past this depth is shown as black.

  • points – A list of points in (pixel row, pixel column) format to show on the image as colored dots.

Example:

depth_image = rc.camera.get_depth_image()

# Show the depth_image captured by the camera.
rc.display.show_depth_image(depth_image)

# Show anything that is at most 500 cm away, and show a black cross at
# row 3, column 5
rc.display.show_depth_image(depth_image, 500, [(3, 5)])
show_lidar(samples: NDArray[Any, Float], radius: int = 128, max_range: int = 1000, highlighted_samples: list[tuple[float, float]] = []) None#

Displays a set of LIDAR samples.

Parameters:
  • samples – A complete LIDAR scan.

  • radius – Half of the width or height (in pixels) of the generated image.

  • max_range – The farthest depth to show in the image in cm. Anything past this depth is shown as black.

  • highlighted_samples – A list of samples in (angle, distance) format to show as light blue dots. Angle must be in degrees from straight ahead (clockwise), and distance must be in cm.

Note

Each sample in samples is shown as a red pixel. Each sample in highlighted_samples is shown as a blue pixel. The car is shown as a green dot at the center of the visualization.

Warning

samples must be a complete LIDAR scan. This function assumes that each sample is equal angle apart, and that samples spans the entire 360 degrees. If this is not the case, the visualization will be inaccurate.

Example:

lidar_scan = rc.lidar.get_samples()

# Show the lidar scan
rc.display.show_lidar(lidar_scan)

# Show the lidar scan out to 500 cm with the closest point highlighted
closest_point = rc_utils.get_lidar_closest_point(lidar_scan)
rc.display.show_lidar(lidar_scan, 500, [closest_point])