Display#
rc.display
Copyright MIT GNU General Public License v3.0
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)#
Shows images in a window on the computer running the program, and controls the 8x24 dot matrix display on the car.
- abstractmethod 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.display.create_window() # Display an image in this window image = rc.camera.get_color_image() rc.display.show_color_image(image)
- abstractmethod get_matrix() NDArray#
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
Returns the matrix last passed to set_matrix; a nonzero value is an LED that is on. Text shown with show_text is not included.
Example:
# Gets current configuration values of the dot matrix module dot_matrix = rc.display.get_matrix()
- new_matrix() NDArray#
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)
- abstractmethod set_matrix(matrix: NDArray) 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 nonzero value in the matrix indicates an LED that is on, while a 0 indicates an LED that is off. Row 0 is the top row and column 0 the left column.
— In the Simulator — The pattern stays until the program replaces it or exits. The matrix appears in a panel on screen when “Show dot matrix” is on in Settings.
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)
- abstractmethod 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
On the physical RACECAR and in RacecarSim this function has no effect: the matrix contrast is fixed by the car’s dot matrix driver. The first call prints a warning.
Example:
rc.display.set_matrix_intensity(0.5)
- abstractmethod 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, 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 green dot at # row 3, column 5 rc.display.show_depth_image(depth_image, 500, [(3, 5)])
- show_lidar(samples: NDArray, 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])
- abstractmethod show_text(text: str, scroll_speed: float = 2.0) None#
Displays text on the 8x24 matrix. If the text is too long, it scrolls.
- Parameters:
text – The string to display.
scroll_speed – The scrolling speed in characters per second.
Note
On the physical RACECAR and in RacecarSim, scroll_speed is not used: text wider than the display scrolls across it once every 4 seconds.
Example:
# Display a message on the LED matrix rc.display.show_text("Hello!") # Display a long message that will scroll rc.display.show_text("This message is too long to fit and will scroll")