anki_vector.behavior

Behavior related classes and functions.

Behaviors represent a complex task which requires Vector’s internal logic to determine how long it will take. This may include combinations of animation, path planning or other functionality. Examples include drive_on_charger(), set_lift_height(), etc.

For commands such as go_to_pose(), drive_on_charger() and dock_with_cube(), Vector uses path planning, which refers to the problem of navigating the robot from point A to B without collisions. Vector loads known obstacles from his map, creates a path to navigate around those objects, then starts following the path. If a new obstacle is found while following the path, a new plan may be created.

The BehaviorComponent class in this module contains functions for all the behaviors.

Classes

BehaviorComponent(robot) Run behaviors on Vector
anki_vector.behavior.MAX_HEAD_ANGLE = <Angle Radians: 0.79 Degrees: 45.00>

The maximum angle the robot’s head can be set to

anki_vector.behavior.MIN_HEAD_ANGLE = <Angle Radians: -0.38 Degrees: -22.00>

The minimum angle the robot’s head can be set to.

anki_vector.behavior.MAX_LIFT_HEIGHT = <Distance 92.00 mm (3.62 inches)>

The largest height-above-ground that lift can be moved to

anki_vector.behavior.MIN_LIFT_HEIGHT = <Distance 32.00 mm (1.26 inches)>

The lowest height-above-ground that lift can be moved to

class anki_vector.behavior.BehaviorComponent(robot)

Run behaviors on Vector

dock_with_cube(target_object, approach_angle=None, alignment_type=2, distance_from_marker=None, num_retries=0)

Tells Vector to dock with a light cube, optionally using a given approach angle and distance.

While docking with the cube, Vector will use path planning.

Parameters:
  • target_object (LightCube) – The LightCube object to dock with.
  • approach_angle (Optional[Angle]) – Angle to approach the dock with.
  • alignment_type (<google.protobuf.internal.enum_type_wrapper.EnumTypeWrapper object at 0x107067f28>) – Which part of the robot to align with the object.
  • distance_from_marker (Optional[Distance]) – How far from the object to approach (0 to dock)
  • num_retries (int) – Number of times to re-attempt action in case of a failure.
Returns:

A response from the robot with status information sent when this request successfully completes or fails.

import anki_vector

with anki_vector.Robot() as robot:
    robot.world.connect_cube()

    if robot.world.connected_light_cube:
        dock_response = robot.behavior.dock_with_cube(robot.world.connected_light_cube)
        docking_result = dock_response.result
Return type:DockWithCubeResponse
drive_off_charger()

Drive Vector off the charger

If Vector is on the charger, drives him off the charger.

import anki_vector

with anki_vector.Robot() as robot:
    robot.behavior.drive_off_charger()
drive_on_charger()

Drive Vector onto the charger

Vector will attempt to find the charger and, if successful, he will back onto it and start charging.

Vector’s charger has a visual marker so that the robot can locate it for self-docking.

import anki_vector

with anki_vector.Robot() as robot:
    robot.behavior.drive_on_charger()
drive_straight(distance, speed, should_play_anim=True, num_retries=0)

Tells Vector to drive in a straight line.

Vector will drive for the specified distance (forwards or backwards)

Vector must be off of the charger for this movement action.

Parameters:
  • distance (Distance) – The distance to drive (>0 for forwards, <0 for backwards)
  • speed (Speed) – The speed to drive at (should always be >0, the abs(speed) is used internally)
  • should_play_anim (bool) – Whether to play idle animations whilst driving (tilt head, hum, animated eyes, etc.)
  • num_retries (int) – Number of times to re-attempt action in case of a failure.
Returns:

A response from the robot with status information sent when this request successfully completes or fails.

import anki_vector
from anki_vector.util import degrees, distance_mm, speed_mmps

with anki_vector.Robot() as robot:
    robot.behavior.drive_straight(distance_mm(200), speed_mmps(100))
Return type:DriveStraightResponse
go_to_pose(pose, relative_to_robot=False, num_retries=0)

Tells Vector to drive to the specified pose and orientation.

In navigating to the requested pose, Vector will use path planning.

If relative_to_robot is set to True, the given pose will assume the robot’s pose as its origin.

Since the robot understands position by monitoring its tread movement, it does not understand movement in the z axis. This means that the only applicable elements of pose in this situation are position.x position.y and rotation.angle_z.

Parameters:
  • pose (Pose) – The destination pose.
  • relative_to_robot (bool) – Whether the given pose is relative to the robot’s pose.
  • num_retries (int) – Number of times to re-attempt action in case of a failure.
Returns:

A response from the robot with status information sent when this request successfully completes or fails.

import anki_vector
from anki_vector.util import degrees, Pose

with anki_vector.Robot() as robot:
    pose = Pose(x=50, y=0, z=0, angle_z=anki_vector.util.Angle(degrees=0))
    robot.behavior.go_to_pose(pose)
Return type:GoToPoseResponse
motion_profile_map

Tells Vector how to drive when receiving navigation and movement actions such as go_to_pose and dock_with_cube.

motion_prof_map values are as follows:
speed_mmps (float)
accel_mmps2 (float)
decel_mmps2 (float)
point_turn_speed_rad_per_sec (float)
point_turn_accel_rad_per_sec2 (float)
point_turn_decel_rad_per_sec2 (float)
dock_speed_mmps (float)
dock_accel_mmps2 (float)
dock_decel_mmps2 (float)
reverse_speed_mmps (float)
is_custom (bool)
Getter:Returns the motion profile map
Setter:Sets the motion profile map
Parameters:motion_prof_map – Provide custom speed, acceleration and deceleration values with which the robot goes to the given pose.
Return type:dict
set_eye_color(hue, saturation)

Set Vector’s eye color.

import anki_vector
import time

with anki_vector.Robot() as robot:
    print("Set Vector's eye color to purple...")
    robot.behavior.set_eye_color(0.83, 0.76)
    time.sleep(5)
Parameters:
  • hue (float) – The hue to use for Vector’s eyes.
  • saturation (float) – The saturation to use for Vector’s eyes.
Return type:

SetEyeColorResponse

set_head_angle(angle, accel=10.0, max_speed=10.0, duration=0.0, num_retries=0)

Tell Vector’s head to move to a given angle.

Parameters:
  • angle (Angle) – Desired angle for Vector’s head. (MIN_HEAD_ANGLE to MAX_HEAD_ANGLE). (we clamp it to this range internally).
  • accel (float) – Acceleration of Vector’s head in radians per second squared.
  • max_speed (float) – Maximum speed of Vector’s head in radians per second.
  • duration (float) – Time for Vector’s head to move in seconds. A value of zero will make Vector try to do it as quickly as possible.
  • num_retries (int) – Number of times to re-attempt the action in case of a failure.
Returns:

A response from the robot with status information sent when this request successfully completes or fails.

import anki_vector
from anki_vector.util import degrees
from anki_vector.behavior import MIN_HEAD_ANGLE, MAX_HEAD_ANGLE

with anki_vector.Robot() as robot:
    # move head from minimum to maximum angle
    robot.behavior.set_head_angle(MIN_HEAD_ANGLE)
    robot.behavior.set_head_angle(MAX_HEAD_ANGLE)
    # move head to middle
    robot.behavior.set_head_angle(degrees(35.0))
Return type:SetHeadAngleResponse
set_lift_height(height, accel=10.0, max_speed=10.0, duration=0.0, num_retries=0)

Tell Vector’s lift to move to a given height.

Parameters:
  • height (float) – desired height for Vector’s lift 0.0 (bottom) to 1.0 (top) (we clamp it to this range internally).
  • accel (float) – Acceleration of Vector’s lift in radians per second squared.
  • max_speed (float) – Maximum speed of Vector’s lift in radians per second.
  • duration (float) – Time for Vector’s lift to move in seconds. A value of zero will make Vector try to do it as quickly as possible.
  • num_retries (int) – Number of times to re-attempt the action in case of a failure.
Returns:

A response from the robot with status information sent when this request successfully completes or fails.

import anki_vector

with anki_vector.Robot() as robot:
    robot.behavior.set_lift_height(1.0)
Return type:SetLiftHeightResponse
turn_in_place(angle, speed=<Angle Radians: 0.00 Degrees: 0.00>, accel=<Angle Radians: 0.00 Degrees: 0.00>, angle_tolerance=<Angle Radians: 0.00 Degrees: 0.00>, is_absolute=0, num_retries=0)

Turn the robot around its current position.

Vector must be off of the charger for this movement action.

Parameters:
  • angle (Angle) – The angle to turn. Positive values turn to the left, negative values to the right.
  • speed (Angle) – Angular turn speed (per second).
  • accel (Angle) – Acceleration of angular turn (per second squared).
  • angle_tolerance (Angle) – angular tolerance to consider the action complete (this is clamped to a minimum of 2 degrees internally).
  • is_absolute (bool) – True to turn to a specific angle, False to turn relative to the current pose.
  • num_retries (int) – Number of times to re-attempt the turn in case of a failure.
Returns:

A response from the robot with status information sent when this request successfully completes or fails.

import anki_vector
from anki_vector.util import degrees

with anki_vector.Robot() as robot:
    robot.behavior.turn_in_place(degrees(90))
Return type:TurnInPlaceResponse