anki_vector.util¶
Utility functions and classes for the Vector SDK.
Functions
|
This function converts an angle in the z axis (Euler angle z component) to a quaternion. |
|
Use this to denote a property that may need some delay before it appears. |
|
An Angle instance set to the specified number of degrees. |
|
Returns an |
|
Returns an |
|
Helper to create logger for a given class (and module). |
|
Parses command line arguments. |
|
An Angle instance set to the specified number of radians. |
|
Open the default conf file, and read it into a |
|
Helper to perform basic setup of the Python logger. |
|
|
Classes
|
Represents an angle. |
|
A base overlay is used as a base class for other forms of overlays that can be drawn on top of an image. |
|
Base class for all components. |
|
Represents a distance. |
|
Defines a bounding box within an image frame. |
|
A 4x4 Matrix for representing the rotation and/or position of an object in the world. |
|
Represents where an object is in the world. |
|
Represents the position of an object in the world. |
|
Represents the rotation of an object in the world. |
|
A rectangle that can be drawn on top of a given image. |
|
Represents a speed. |
|
Represents a 2D Vector (type/units aren’t specified). |
|
Represents a 3D Vector (type/units aren’t specified). |
-
class
anki_vector.util.
Angle
(radians=None, degrees=None)¶ Represents an angle.
Use the
degrees()
orradians()
convenience methods to generate an Angle instance.- Parameters
-
property
abs_value
¶ The absolute value of the angle.
If the Angle is positive then it returns a copy of this Angle, otherwise it returns -Angle.
-
class
anki_vector.util.
BaseOverlay
(line_thickness, line_color)¶ A base overlay is used as a base class for other forms of overlays that can be drawn on top of an image.
- Parameters
-
class
anki_vector.util.
Component
(robot)¶ Base class for all components.
-
property
grpc_interface
¶ A direct reference to the connected aiogrpc interface.
-
property
-
class
anki_vector.util.
Distance
(distance_mm=None, distance_inches=None)¶ Represents a distance.
The class allows distances to be returned in either millimeters or inches.
Use the
distance_inches()
ordistance_mm()
convenience methods to generate a Distance instance.- Parameters
-
class
anki_vector.util.
ImageRect
(x_top_left, y_top_left, width, height)¶ Defines a bounding box within an image frame.
This is used when objects and faces are observed to denote where in the robot’s camera view the object or face actually appears. It’s then used by the annotate module to show an outline of a box around the object or face.
-
property
height
¶ The height of the object from when it was last visible within Vector’s camera view.
- Return type
-
scale_by
(scale_multiplier)¶ Scales the image rectangle by the multiplier provided.
- Return type
None
-
property
width
¶ The width of the object from when it was last visible within Vector’s camera view.
- Return type
-
property
x_top_left
¶ The top left x value of where the object was last visible within Vector’s camera view.
- Return type
-
property
-
class
anki_vector.util.
Matrix44
(m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33)¶ A 4x4 Matrix for representing the rotation and/or position of an object in the world.
Can be generated from a
Quaternion
for a pure rotation matrix, or combined with a position for a full translation matrix, as done byPose.to_matrix()
.-
property
forward_xyz
¶ The x,y,z components representing the matrix’s forward vector.
- Type
tuple of 3 floats
-
property
in_column_order
¶ The contents of the matrix in column order.
- Type
tuple of 16 floats
-
property
in_row_order
¶ The contents of the matrix in row order.
- Type
tuple of 16 floats
-
property
left_xyz
¶ The x,y,z components representing the matrix’s left vector.
- Type
tuple of 3 floats
-
property
pos_xyz
¶ The x,y,z components representing the matrix’s position vector.
- Type
tuple of 3 floats
-
set_forward
(x, y, z)¶ Set the x,y,z components representing the matrix’s forward vector.
-
set_left
(x, y, z)¶ Set the x,y,z components representing the matrix’s left vector.
-
set_pos
(x, y, z)¶ Set the x,y,z components representing the matrix’s position vector.
-
set_up
(x, y, z)¶ Set the x,y,z components representing the matrix’s up vector.
-
property
tabulated_string
¶ A multi-line string formatted with tabs to show the matrix contents.
- Return type
-
property
up_xyz
¶ The x,y,z components representing the matrix’s up vector.
- Type
tuple of 3 floats
-
property
-
class
anki_vector.util.
Pose
(x, y, z, q0=None, q1=None, q2=None, q3=None, angle_z=None, origin_id=-1)¶ Represents where an object is in the world.
Whenever Vector is delocalized (i.e. whenever Vector no longer knows where he is - e.g. when he’s picked up), Vector creates a new pose starting at (0,0,0) with no rotation, with origin_id incremented to show that these poses cannot be compared with earlier ones. As Vector drives around, his pose (and the pose of other objects he observes - e.g. faces, his LightCube, charger, etc.) is relative to this initial position and orientation.
The coordinate space is relative to Vector, where Vector’s origin is the point on the ground between Vector’s two front wheels. The X axis is Vector’s forward direction, the Y axis is to Vector’s left, and the Z axis is up.
Only poses of the same origin_id can safely be compared or operated on.
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)
-
define_pose_relative_this
(new_pose)¶ Creates a new pose such that new_pose’s origin is now at the location of this pose.
- Parameters
new_pose (anki_vector.util.Pose) – The pose which origin is being changed.
- Returns
A
anki_vector.util.Pose
object for which the origin was this pose’s origin.
-
is_comparable
(other_pose)¶ Checks whether these two poses are comparable.
Poses are comparable if they’re valid and having matching origin IDs.
- Parameters
other_pose – The other pose to compare against. Type is Pose.
- Returns
True if the two poses are comparable, False otherwise.
- Return type
-
property
origin_id
¶ An ID maintained by the robot which represents which coordinate frame this pose is in.
- Return type
-
property
rotation
¶ The rotation component of this pose.
- Return type
-
to_matrix
()¶ Convert the Pose to a Matrix44.
- Returns
A matrix representing this Pose’s position and rotation.
- Return type
-
to_proto_pose_struct
()¶ Converts the Pose into the robot’s messaging pose format.
- Return type
PoseStruct
-
-
class
anki_vector.util.
Position
(x, y, z)¶ Represents the position of an object in the world.
A position consists of its x, y and z values in millimeters.
-
class
anki_vector.util.
Quaternion
(q0=None, q1=None, q2=None, q3=None, angle_z=None)¶ Represents the rotation of an object in the world.
-
property
angle_z
¶ An Angle instance representing the z Euler component of the object’s rotation.
Defined as the rotation in the z axis.
- Return type
-
property
q0_q1_q2_q3
¶ Contains all elements of the quaternion (q0,q1,q2,q3)
- Type
tuple of float
-
to_matrix
(pos_x=0.0, pos_y=0.0, pos_z=0.0)¶ Convert the Quaternion to a 4x4 matrix representing this rotation.
A position can also be provided to generate a full translation matrix.
- Parameters
- Returns
A matrix representing this Quaternion’s rotation, with the provided position (which defaults to 0,0,0).
- Return type
-
property
-
class
anki_vector.util.
RectangleOverlay
(width, height, line_thickness=5, line_color=(255, 0, 0))¶ A rectangle that can be drawn on top of a given image.
- Parameters
-
apply_overlay
(image)¶ Draw a rectangle on top of the given image.
- Return type
None
-
class
anki_vector.util.
Speed
(speed_mmps=None)¶ Represents a speed.
This class allows speeds to be measured in millimeters per second.
The maximum speed is 220 mm/s and is clamped internally.
Use
speed_mmps()
convenience methods to generate a Speed instance.
-
class
anki_vector.util.
Vector2
(x, y)¶ Represents a 2D Vector (type/units aren’t specified).
-
set_to
(rhs)¶ Copy the x and y components of the given Vector2 instance.
- Parameters
rhs – The right-hand-side of this assignment - the source Vector2 to copy into this Vector2 instance.
-
-
class
anki_vector.util.
Vector3
(x, y, z)¶ Represents a 3D Vector (type/units aren’t specified).
-
cross
(other)¶ The cross product of this and another Vector3 instance
-
dot
(other)¶ The dot product of this and another Vector3 instance
-
property
normalized
¶ A Vector3 instance with the same direction and unit magnitude
-
set_to
(rhs)¶ Copy the x, y and z components of the given Vector3 instance.
- Parameters
rhs – The right-hand-side of this assignment - the source Vector3 to copy into this Vector3 instance.
-
-
anki_vector.util.
angle_z_to_quaternion
(angle_z)¶ This function converts an angle in the z axis (Euler angle z component) to a quaternion.
-
anki_vector.util.
block_while_none
(interval=0.1, max_iterations=50)¶ Use this to denote a property that may need some delay before it appears.
- Parameters
This will raise a
VectorControlTimeoutException
if the property cannot be retrieved beforemax_iterations
.
-
anki_vector.util.
degrees
(degrees)¶ An Angle instance set to the specified number of degrees.
- Return type
-
anki_vector.util.
distance_mm
(distance_mm)¶ Returns an
anki_vector.util.Distance
instance set to the specified number of millimeters.
-
anki_vector.util.
distance_inches
(distance_inches)¶ Returns an
anki_vector.util.Distance
instance set to the specified number of inches.
-
anki_vector.util.
get_class_logger
(module, obj)¶ Helper to create logger for a given class (and module).
import anki_vector logger = anki_vector.util.get_class_logger("module_name", "object_name")
-
anki_vector.util.
parse_command_args
(parser=None)¶ Parses command line arguments.
Attempts to read the robot serial number from the command line arguments. If no serial number is specified, we next attempt to read the robot serial number from environment variable ANKI_ROBOT_SERIAL. If ANKI_ROBOT_SERIAL is specified, the value will be used as the robot’s serial number.
import anki_vector import argparse parser = argparse.ArgumentParser() parser.add_argument("--new_param") args = anki_vector.util.parse_command_args(parser)
- Parameters
parser (
Optional
[ArgumentParser
]) – To add new command line arguments, pass an argparse parser with the new options already defined. Leave empty to use the defaults.
-
anki_vector.util.
radians
(radians)¶ An Angle instance set to the specified number of radians.
- Return type
-
anki_vector.util.
setup_basic_logging
(custom_handler=None, general_log_level=None, target=None)¶ Helper to perform basic setup of the Python logger.
- Parameters
custom_handler (
Optional
[Handler
]) – provide an external logger for custom logging locationsgeneral_log_level (
Optional
[str
]) – ‘DEBUG’, ‘INFO’, ‘WARN’, ‘ERROR’ or an equivalent constant from thelogging
module. If None then a value will be read from the VECTOR_LOG_LEVEL environment variable.target (
Optional
[object
]) – The stream to send the log data to; defaults to stderr
-
anki_vector.util.
speed_mmps
(speed_mmps)¶ anki_vector.util.Speed
instance set to the specified millimeters per second speed.