anki_vector.viewer

Displays camera feed from Vector’s camera.

Classes

Viewer3DComponent(robot) This component opens a window and renders the a 3D view obtained from Vector’s navigation map.
ViewerComponent(robot) This component opens a window and renders the images obtained from Vector’s camera.
class anki_vector.viewer.ViewerComponent(robot)

This component opens a window and renders the images obtained from Vector’s camera. This viewer window is run in a separate process spawned by show_video(). Being on a separate process means the rendering of the camera does not block the main thread of the calling code, and allows the viewer to have its own ui thread which it can operate on. stop_video() will stop the viewer process.

import anki_vector

import time

with anki_vector.Robot(enable_camera_feed=True, show_viewer=True) as robot:
    time.sleep(5)
Parameters:robot – A reference to the owner Robot object. (May be None)
enqueue_frame(image)

Sends a frame to the viewer’s rendering process. Sending None to the viewer will cause it to gracefully shutdown.

Note

This function will be called automatically from the camera feed when the Robot object is created with enable_camera_feed=True.

import anki_vector
from PIL.Image import Image

image = Image()
with anki_vector.Robot(show_viewer=True) as robot:
    robot.viewer.enqueue_frame(image)
Parameters:image (Image) – A frame from Vector’s camera.
show_video(timeout=10.0)

Render a video stream using the images obtained from Vector’s camera feed.

Be sure to create your Robot object with the camera feed enabled by using “show_viewer=True” and “enable_camera_feed=True”.

import anki_vector
import time

with anki_vector.Robot(enable_camera_feed=True) as robot:
    robot.viewer.show_video()
    time.sleep(10)
Parameters:timeout (float) – Render video for the given time. (Renders forever, if timeout not given)
Return type:None
stop_video()

Stop rendering video of Vector’s camera feed and close the viewer process.

import anki_vector
import time

with anki_vector.Robot(show_viewer=True) as robot:
    time.sleep(10)
    robot.viewer.stop_video()
Return type:None
class anki_vector.viewer.Viewer3DComponent(robot)

This component opens a window and renders the a 3D view obtained from Vector’s navigation map. This viewer window is run in a separate process spawned by show(). Being on a separate process means the rendering of the 3D view does not block the main thread of the calling code, and allows the viewer to have its own ui thread with which it can render OpenGL. close() will stop the viewer process.

import anki_vector

import time

with anki_vector.Robot(enable_nav_map_feed=True, show_3d_viewer=True) as robot:
    time.sleep(5)
Parameters:robot – A reference to the owner Robot object. (May be None)
add_render_call(render_function, *args)

Allows external functions to be injected into the viewer process which will be called at the appropriate time in the rendering pipeline.

Example usage to draw a dot at the world origin:

import time

import anki_vector

def my_render_function(user_data_queue):
    glBegin(GL_POINTS)
    glVertex3f(0, 0, 0)
    glEnd()

with anki_vector.Robot(enable_nav_map_feed=True, show_3d_viewer=True) as robot:
    robot.viewer_3d.add_render_call(my_render_function)
    time.sleep(10)
Parameters:
  • render_function (<built-in function callable>) – The delegated function to be invoked in the pipeline.
  • args – An optional list of arguments to send to the render_function the arguments list must match the parameters accepted by the supplied function.
close()

Closes the background process showing the 3D view.

import anki_vector

import time

with anki_vector.Robot(enable_nav_map_feed=True) as robot:
    robot.viewer_3d.show()
    time.sleep(5)
    robot.viewer_3d.close()
show()

Spawns a background process that shows the navigation map in a 3D view.

import anki_vector

import time

with anki_vector.Robot(enable_nav_map_feed=True) as robot:
    robot.viewer_3d.show()
    time.sleep(5)
    robot.viewer_3d.close()
user_data_queue

A queue to send custom data to the 3D viewer process.

Best used in conjunction with add_render_call() to place a process on the 3D viewer process then obtain data from this queue.