def update():
    '\n    After start() is run, this function is run every frame until the back button\n    is pressed\n    '
    if rc.controller.was_pressed(rc.controller.Button.A):
        image = rc.camera.get_color_image()
        cropped = rc_utils.crop(image, (0, 0), ((rc.camera.get_height() // 2), (rc.camera.get_width() // 2)))
        rc.display.show_color_image(cropped)
    if rc.controller.was_pressed(rc.controller.Button.B):
        image = rc.camera.get_color_image()
        contours = rc_utils.find_contours(image, RED[0], RED[1])
        largest_contour = rc_utils.get_largest_contour(contours)
        if (largest_contour is not None):
            center = rc_utils.get_contour_center(largest_contour)
            area = rc_utils.get_contour_area(largest_contour)
            print('Largest red contour: center={}, area={:.2f}'.format(center, area))
            rc_utils.draw_contour(image, largest_contour, rc_utils.ColorBGR.green.value)
            rc_utils.draw_circle(image, center, rc_utils.ColorBGR.yellow.value)
            rc.display.show_color_image(image)
        else:
            print('No red contours found')
    if rc.controller.was_pressed(rc.controller.Button.X):
        depth_image = rc.camera.get_depth_image()
        left_distance = rc_utils.get_pixel_average_distance(depth_image, ((rc.camera.get_height() // 2), (rc.camera.get_width() // 4)))
        center_distance = rc_utils.get_depth_image_center_distance(depth_image)
        center_distance_raw = rc_utils.get_depth_image_center_distance(depth_image, 1)
        right_distance = rc_utils.get_pixel_average_distance(depth_image, ((rc.camera.get_height() // 2), ((3 * rc.camera.get_width()) // 4)))
        print(f'Depth image left distance: {left_distance:.2f} cm')
        print(f'Depth image center distance: {center_distance:.2f} cm')
        print(f'Depth image raw center distance: {center_distance_raw:.2f} cm')
        print(f'Depth image right distance: {right_distance:.2f} cm')
        upper_left_distance = rc_utils.get_pixel_average_distance(depth_image, (2, 1), 11)
        lower_right_distance = rc_utils.get_pixel_average_distance(depth_image, ((rc.camera.get_height() - 2), (rc.camera.get_width() - 5)), 13)
        print(f'Depth image upper left distance: {upper_left_distance:.2f} cm')
        print(f'Depth image lower right distance: {lower_right_distance:.2f} cm')
        cropped = rc_utils.crop(depth_image, (0, 0), (((rc.camera.get_height() * 2) // 3), rc.camera.get_width()))
        closest_point = rc_utils.get_closest_pixel(cropped)
        closest_distance = cropped[closest_point[0]][closest_point[1]]
        print(f'Depth image closest point (upper half): (row={closest_point[0]}, col={closest_point[1]}), distance={closest_distance:.2f} cm')
        rc.display.show_depth_image(cropped, points=[closest_point])
    if rc.controller.was_pressed(rc.controller.Button.Y):
        lidar = rc.lidar.get_samples()
        front_distance = rc_utils.get_lidar_average_distance(lidar, 0)
        right_distance = rc_utils.get_lidar_average_distance(lidar, 90)
        back_distance = rc_utils.get_lidar_average_distance(lidar, 180)
        left_distance = rc_utils.get_lidar_average_distance(lidar, 270)
        print(f'Front LIDAR distance: {front_distance:.2f} cm')
        print(f'Right LIDAR distance: {right_distance:.2f} cm')
        print(f'Back LIDAR distance: {back_distance:.2f} cm')
        print(f'Left LIDAR distance: {left_distance:.2f} cm')
        closest_sample = rc_utils.get_lidar_closest_point(lidar)
        print(f'Closest LIDAR point: {closest_sample[0]:.2f} degrees, {closest_sample[1]:.2f} cm')
        rc.display.show_lidar(lidar, highlighted_samples=[closest_sample])
    (rjoy_x, rjoy_y) = rc.controller.get_joystick(rc.controller.Joystick.RIGHT)
    if ((abs(rjoy_x) > 0) or (abs(rjoy_y) > 0)):
        lidar = rc.lidar.get_samples()
        angle = (((math.atan2(rjoy_x, rjoy_y) * 180) / math.pi) % 360)
        distance = rc_utils.get_lidar_average_distance(lidar, angle)
        print(f'LIDAR distance at angle {angle:.2f} = {distance:.2f} cm')
    left_trigger = rc.controller.get_trigger(rc.controller.Trigger.LEFT)
    right_trigger = rc.controller.get_trigger(rc.controller.Trigger.RIGHT)
    left_joystick = rc.controller.get_joystick(rc.controller.Joystick.LEFT)
    rc.drive.set_speed_angle((right_trigger - left_trigger), left_joystick[0])
After start() is run, this function is run every frame until the back button
is pressed
def update():
    '\n    After start() is run, this function is run every frame until the back button\n    is pressed\n    '
    if rc.controller.was_pressed(rc.controller.Button.A):
        image = rc.camera.get_color_image()
        cropped = rc_utils.crop(image, (0, 0), ((rc.camera.get_height() // 2), (rc.camera.get_width() // 2)))
        rc.display.show_color_image(cropped)
    if rc.controller.was_pressed(rc.controller.Button.B):
        image = rc.camera.get_color_image()
        contours = rc_utils.find_contours(image, RED[0], RED[1])
        largest_contour = rc_utils.get_largest_contour(contours)
        if (largest_contour is not None):
            center = rc_utils.get_contour_center(largest_contour)
            area = rc_utils.get_contour_area(largest_contour)
            print('Largest red contour: center={}, area={:.2f}'.format(center, area))
            rc_utils.draw_contour(image, largest_contour, rc_utils.ColorBGR.green.value)
            rc_utils.draw_circle(image, center, rc_utils.ColorBGR.yellow.value)
            rc.display.show_color_image(image)
        else:
            print('No red contours found')
    if rc.controller.was_pressed(rc.controller.Button.X):
        depth_image = rc.camera.get_depth_image()
        left_distance = rc_utils.get_pixel_average_distance(depth_image, ((rc.camera.get_height() // 2), (rc.camera.get_width() // 4)))
        center_distance = rc_utils.get_depth_image_center_distance(depth_image)
        center_distance_raw = rc_utils.get_depth_image_center_distance(depth_image, 1)
        right_distance = rc_utils.get_pixel_average_distance(depth_image, ((rc.camera.get_height() // 2), ((3 * rc.camera.get_width()) // 4)))
        print(f'Depth image left distance: {left_distance:.2f} cm')
        print(f'Depth image center distance: {center_distance:.2f} cm')
        print(f'Depth image raw center distance: {center_distance_raw:.2f} cm')
        print(f'Depth image right distance: {right_distance:.2f} cm')
        upper_left_distance = rc_utils.get_pixel_average_distance(depth_image, (2, 1), 11)
        lower_right_distance = rc_utils.get_pixel_average_distance(depth_image, ((rc.camera.get_height() - 2), (rc.camera.get_width() - 5)), 13)
        print(f'Depth image upper left distance: {upper_left_distance:.2f} cm')
        print(f'Depth image lower right distance: {lower_right_distance:.2f} cm')
        cropped = rc_utils.crop(depth_image, (0, 0), (((rc.camera.get_height() * 2) // 3), rc.camera.get_width()))
        closest_point = rc_utils.get_closest_pixel(cropped)
        closest_distance = cropped[closest_point[0]][closest_point[1]]
        print(f'Depth image closest point (upper half): (row={closest_point[0]}, col={closest_point[1]}), distance={closest_distance:.2f} cm')
        rc.display.show_depth_image(cropped, points=[closest_point])
    if rc.controller.was_pressed(rc.controller.Button.Y):
        lidar = rc.lidar.get_samples()
        front_distance = rc_utils.get_lidar_average_distance(lidar, 0)
        right_distance = rc_utils.get_lidar_average_distance(lidar, 90)
        back_distance = rc_utils.get_lidar_average_distance(lidar, 180)
        left_distance = rc_utils.get_lidar_average_distance(lidar, 270)
        print(f'Front LIDAR distance: {front_distance:.2f} cm')
        print(f'Right LIDAR distance: {right_distance:.2f} cm')
        print(f'Back LIDAR distance: {back_distance:.2f} cm')
        print(f'Left LIDAR distance: {left_distance:.2f} cm')
        closest_sample = rc_utils.get_lidar_closest_point(lidar)
        print(f'Closest LIDAR point: {closest_sample[0]:.2f} degrees, {closest_sample[1]:.2f} cm')
        rc.display.show_lidar(lidar, highlighted_samples=[closest_sample])
    (rjoy_x, rjoy_y) = rc.controller.get_joystick(rc.controller.Joystick.RIGHT)
    if ((abs(rjoy_x) > 0) or (abs(rjoy_y) > 0)):
        lidar = rc.lidar.get_samples()
        angle = (((math.atan2(rjoy_x, rjoy_y) * 180) / math.pi) % 360)
        distance = rc_utils.get_lidar_average_distance(lidar, angle)
        print(f'LIDAR distance at angle {angle:.2f} = {distance:.2f} cm')
    left_trigger = rc.controller.get_trigger(rc.controller.Trigger.LEFT)
    right_trigger = rc.controller.get_trigger(rc.controller.Trigger.RIGHT)
    left_joystick = rc.controller.get_joystick(rc.controller.Joystick.LEFT)
    rc.drive.set_speed_angle((right_trigger - left_trigger), left_joystick[0])