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(). 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. close() will stop the viewer process.

import anki_vector

import time

with anki_vector.Robot(show_viewer=True) as robot:
    time.sleep(5)
Parameters

robot – A reference to the owner Robot object. (May be None)

close()

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.close()
Return type

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 or AsyncRobot object is created with show_viewer=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(timeout=10.0, force_on_top=True)

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

import anki_vector
import time

with anki_vector.Robot() as robot:
    robot.viewer.show()
    time.sleep(10)
Parameters
  • timeout (float) – Render video for the given time. (Renders forever, if timeout not given.)

  • force_on_top (bool) – Specifies whether the window should be forced on top of all others.

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 (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()
connect_to_cube()

Connect to light cube

show(show_viewer_controls=True)

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()
Parameters

show_viewer_controls (bool) – Specifies whether to draw controls on the view.

property 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.