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
|
Run behaviors on Vector |
|
A ReserveBehaviorControl object can be used to suppress the ordinary idle behaviors of the Robot and keep Vector still between SDK control instances. |
-
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
-
app_intent
(intent, param=None)¶ Send Vector an intention to do something.
import anki_vector with anki_vector.Robot(behavior_control_level=None) as robot: robot.behavior.app_intent(intent='intent_system_sleep')
-
change_locale
(locale)¶ Change Vectors voice locale
import anki_vector with anki_vector.Robot() as robot: robot.behavior.change_locale(locale='de_DE')
- Parameters
locale (
str
) – The locale ISO code- Return type
UpdateSettingsResponse
- Returns
object that provides the status
-
dock_with_cube
(target_object, approach_angle=None, alignment_type=2, distance_from_marker=None, num_retries=0, _behavior_id=None)¶ 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.
Note that actions that use the wheels cannot be performed at the same time, otherwise you may see a TRACKS_LOCKED error. Methods that use the wheels include
go_to_pose()
,dock_with_cube()
,turn_in_place()
,drive_straight()
, andpickup_object()
.- Parameters
target_object (
LightCube
) – The LightCube object to dock with.approach_angle (
Optional
[Angle
]) – Angle to approach the dock with.alignment_type (
EnumTypeWrapper
) – 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 reattempt 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: robot.behavior.dock_with_cube(robot.world.connected_light_cube)
Example of cancelling the
dock_with_cube()
behavior:import anki_vector from anki_vector.util import degrees import time with anki_vector.AsyncRobot() as robot: # If necessary, move Vector's Head and Lift down robot.behavior.set_head_angle(degrees(-5.0)) robot.behavior.set_lift_height(0.0) robot.world.connect_cube() time.sleep(10.0) dock_future = robot.behavior.dock_with_cube( robot.world.connected_light_cube, num_retries=3) time.sleep(3.0) dock_future.cancel() robot.world.disconnect_cube()
- 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()
- Return type
DriveOffChargerResponse
-
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()
- Return type
DriveOnChargerResponse
-
drive_straight
(distance, speed, should_play_anim=True, num_retries=0, _behavior_id=None)¶ 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.
Note that actions that use the wheels cannot be performed at the same time, otherwise you may see a TRACKS_LOCKED error. Methods that use the wheels include
go_to_pose()
,dock_with_cube()
,turn_in_place()
,drive_straight()
, andpickup_object()
.- 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 reattempt 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 distance_mm, speed_mmps with anki_vector.Robot() as robot: robot.behavior.drive_straight(distance_mm(200), speed_mmps(100))
Example of cancelling the
drive_straight()
behavior:import anki_vector from anki_vector.util import distance_mm, speed_mmps import time with anki_vector.AsyncRobot() as robot: drive_future = robot.behavior.drive_straight(distance_mm(300), speed_mmps(50)) time.sleep(2.0) drive_future.cancel()
- Return type
DriveStraightResponse
-
find_faces
()¶ Look around for faces
Turn in place and move head to look for faces
import anki_vector with anki_vector.Robot() as robot: robot.behavior.find_faces()
- Return type
FindFacesResponse
-
go_to_object
(target_object, distance_from_object, num_retries=0, _behavior_id=None)¶ Tells Vector to drive to his Cube.
- Parameters
target_object (
LightCube
) – The destination object. CustomObject instances are not supported.distance_from_object – The distance from the object to stop. This is the distance between the origins. For instance, the distance from the robot’s origin (between Vector’s two front wheels) to the cube’s origin (at the center of the cube) is ~40mm.
num_retries (
int
) – Number of times to reattempt action in case of a failure.
- Returns
A response from the robot with status information sent when this request successfully completes or fails.
with anki_vector.Robot() as robot: robot.world.connect_cube() if robot.world.connected_light_cube: robot.behavior.go_to_object(robot.world.connected_light_cube, distance_mm(70.0))
- Return type
GoToObjectResponse
-
go_to_pose
(pose, relative_to_robot=False, num_retries=0, _behavior_id=None)¶ 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.
Note that actions that use the wheels cannot be performed at the same time, otherwise you may see a TRACKS_LOCKED error. Methods that use the wheels include
go_to_pose()
,dock_with_cube()
,turn_in_place()
,drive_straight()
, andpickup_object()
.- Parameters
- 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, Angle, Pose with anki_vector.Robot() as robot: pose = Pose(x=50, y=0, z=0, angle_z=Angle(degrees=0)) robot.behavior.go_to_pose(pose)
Example of cancelling the
go_to_pose()
behavior:import anki_vector from anki_vector.util import degrees, Angle, Pose import time with anki_vector.AsyncRobot() as robot: pose = Pose(x=50, y=0, z=0, angle_z=Angle(degrees=0)) pose_future = robot.behavior.go_to_pose(pose) time.sleep(3.0) pose_future.cancel()
- Return type
GoToPoseResponse
-
look_around_in_place
()¶ Look around in place
Turn in place and move head to see what’s around Vector
import anki_vector with anki_vector.Robot() as robot: robot.behavior.look_around_in_place()
- Return type
LookAroundInPlaceResponse
-
pickup_object
(target_object, use_pre_dock_pose=True, num_retries=0, _behavior_id=None)¶ Instruct the robot to pick up his LightCube.
While picking up the cube, Vector will use path planning.
Note that actions that use the wheels cannot be performed at the same time, otherwise you may see a TRACKS_LOCKED error. Methods that use the wheels include
go_to_pose()
,dock_with_cube()
,turn_in_place()
,drive_straight()
, andpickup_object()
.- Parameters
- 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: robot.behavior.pickup_object(robot.world.connected_light_cube)
- Return type
PickupObjectResponse
-
place_object_on_ground_here
(num_retries=0, _behavior_id=None)¶ Ask Vector to place the object he is carrying on the ground at the current location.
- Parameters
num_retries (
int
) – Number of times to reattempt 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: robot.behavior.pickup_object(robot.world.connected_light_cube) robot.behavior.place_object_on_ground_here()
- Return type
PlaceObjectOnGroundHereResponse
-
pop_a_wheelie
(target_object, approach_angle=None, num_retries=0, _behavior_id=None)¶ Tells Vector to “pop a wheelie” using his light cube.
- Parameters
target_object (
LightCube
) – The cube to push down on with Vector’s lift, to start the wheelie.approach_angle (
Optional
[Angle
]) – The angle to approach the cube from. For example, 180 degrees will cause Vector to drive past the cube and approach it from behind.num_retries (
int
) – Number of times to reattempt 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 distance_mm with anki_vector.Robot() as robot: robot.world.connect_cube() if robot.world.connected_light_cube: robot.behavior.pop_a_wheelie(robot.world.connected_light_cube)
- Return type
PopAWheelieResponse
-
roll_cube
(target_object, approach_angle=None, num_retries=0, _behavior_id=None)¶ Tells Vector to roll a specified cube object.
- Parameters
- 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 distance_mm with anki_vector.Robot() as robot: robot.world.connect_cube() if robot.world.connected_light_cube: robot.behavior.roll_cube(robot.world.connected_light_cube)
- Return type
RollObjectResponse
-
roll_visible_cube
()¶ Roll a cube that is currently known to the robot
This behavior will move into position as necessary based on relative distance and orientation.
Vector needs to see the block for this to succeed.
import anki_vector with anki_vector.Robot() as robot: robot.behavior.roll_visible_cube()
- Return type
RollBlockResponse
-
say_localized_text
(text, use_vector_voice=True, duration_scalar=1.0, language='en')¶ Make Vector speak text with a different localized voice.
import anki_vector with anki_vector.Robot() as robot: robot.behavior.say_localized_text("Hello World",language="de")
- Parameters
text (
str
) – The words for Vector to say.use_vector_voice (
bool
) – Whether to use Vector’s robot voice (otherwise, he uses a generic human male voice).duration_scalar (
float
) – Adjust the relative duration of the generated text to speech audio.language (
str
) –Adjust the language spoken for this text
- possible values:
de: German
en: English
ja or jp: Japanese
fr: French
- Return type
SayTextResponse
- Returns
object that provides the status and utterance state
-
say_text
(text, use_vector_voice=True, duration_scalar=1.0)¶ Make Vector speak text.
import anki_vector with anki_vector.Robot() as robot: robot.behavior.say_text("Hello World")
- Parameters
- Return type
SayTextResponse
- Returns
object that provides the status and utterance state
-
set_eye_color
(hue, saturation)¶ Set Vector’s eye color.
- Eye color settings examples:
- Teal: Set hue to 0.42 and saturation to 1.00.Orange: Set hue to 0.05 and saturation to 0.95.Yellow: Set hue to 0.11 and saturation to 1.00.Lime: Set hue to 0.21 and saturation to 1.00.Sapphire: Set hue to 0.57 and saturation to 1.00.Purple: Set hue to 0.83 and saturation to 0.76.
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)
-
set_head_angle
(angle, accel=10.0, max_speed=10.0, duration=0.0, num_retries=0, _behavior_id=None)¶ Tell Vector’s head to move to a given angle.
- Parameters
angle (
Angle
) – Desired angle for Vector’s head. (MIN_HEAD_ANGLE
toMAX_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 reattempt 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))
Example of cancelling the
set_head_angle()
behavior:import anki_vector from anki_vector.behavior import MIN_HEAD_ANGLE, MAX_HEAD_ANGLE import time with anki_vector.AsyncRobot() as robot: # move head from minimum to maximum angle robot.behavior.set_head_angle(MIN_HEAD_ANGLE) time.sleep(1.0) robot.behavior.set_head_angle(MAX_HEAD_ANGLE) time.sleep(1.0) # move head to middle head_future = robot.behavior.set_head_angle(MIN_HEAD_ANGLE) head_future.cancel()
- Return type
SetHeadAngleResponse
-
set_lift_height
(height, accel=10.0, max_speed=10.0, duration=0.0, num_retries=0, _behavior_id=None)¶ 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 reattempt 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) robot.behavior.set_lift_height(0.0)
Example of cancelling the
set_lift_height()
behavior:import anki_vector from anki_vector.behavior import MIN_LIFT_HEIGHT_MM, MAX_LIFT_HEIGHT_MM import time with anki_vector.AsyncRobot() as robot: robot.behavior.set_lift_height(1.0) time.sleep(1.0) lift_future = robot.behavior.set_lift_height(0.0) time.sleep(1.0) lift_future = robot.behavior.set_lift_height(1.0) lift_future.cancel()
- 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, _behavior_id=None)¶ Turn the robot around its current position.
Vector must be off of the charger for this movement action.
Note that actions that use the wheels cannot be performed at the same time, otherwise you may see a TRACKS_LOCKED error. Methods that use the wheels include
go_to_pose()
,dock_with_cube()
,turn_in_place()
,drive_straight()
, andpickup_object()
.- 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 reattempt 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))
Example of cancelling the
turn_in_place()
behavior:import anki_vector from anki_vector.util import degrees import time with anki_vector.AsyncRobot() as robot: turn_future = robot.behavior.turn_in_place(degrees(360)) time.sleep(0.5) turn_future.cancel()
- Return type
TurnInPlaceResponse
-
turn_towards_face
(face, num_retries=0, _behavior_id=None)¶ Tells Vector to turn towards this face.
- Parameters
face_id – The face Vector will turn towards.
num_retries (
int
) – Number of times to reattempt 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.turn_towards_face(1)
Example of cancelling the
turn_towards_face()
behavior:import anki_vector with anki_vector.Robot() as robot: turn_towards_face_future = robot.behavior.turn_towards_face(1) turn_towards_face_future.cancel()
- Return type
TurnTowardsFaceResponse
-
update_settings
(settings)¶ Send Vector an intention to do something.
import anki_vector with anki_vector.Robot() as robot: robot.behavior.update_settings(settings={'locale':'en_US'})
- Parameters
settings – A list object with the following keys clock_24_hour: bool eye_color: EyeColor default_location: string, dist_is_metric: bool locale: string master_volume: Volume temp_is_fahrenheit: bool time_zone: string button_wakeword: ButtonWakeWord
- Return type
UpdateSettingsResponse
- Returns
object that provides the status
-
-
class
anki_vector.behavior.
ReserveBehaviorControl
(serial=None, ip=None, config=None, behavior_activation_timeout=10)¶ A ReserveBehaviorControl object can be used to suppress the ordinary idle behaviors of the Robot and keep Vector still between SDK control instances. Care must be taken when blocking background behaviors, as this may make Vector appear non-responsive.
This class is most easily used via a built-in SDK script, and can be called on the command-line via the executable module
anki_vector.reserve_control
:python3 -m anki_vector.reserve_control
As long as the script is running, background behaviors will not activate, keeping Vector still while other SDK scripts may take control. Highest-level behaviors like returning to the charger due to low battery will still activate.
System-specific shortcuts calling this executable module can be found in the examples/scripts folder. These scripts can be double-clicked to easily reserve behavior control for the current SDK default robot.
If there is a need to keep background behaviors from activating in a single script, the class may be used to reserve behavior control while in scope:
import anki_vector from anki_vector import behavior with behavior.ReserveBehaviorControl(): # At this point, Vector will remain still, even without # a Robot instance being in scope. # take control of the robot as usual with anki_vector.Robot() as robot: robot.anim.play_animation("anim_turn_left_01") # Robot will not perform idle behaviors until the script completes
- Parameters
serial (
Optional
[str
]) – Vector’s serial number. The robot’s serial number (ex. 00e20100) is located on the underside of Vector, or accessible from Vector’s debug screen. Used to identify which Vector configuration to load.config (
Optional
[dict
]) – A customdict
to override values in Vector’s configuration. (optional) Example:{"cert": "/path/to/file.cert", "name": "Vector-XXXX", "guid": "<secret_key>"}
wherecert
is the certificate to identify Vector,name
is the name on Vector’s face when his backpack is double-clicked on the charger, andguid
is the authorization token that identifies the SDK user. Note: Never share your authentication credentials with anyone.behavior_activation_timeout (
int
) – The time to wait for control of the robot before failing.