pycozmo.util¶
Utility classes and functions.
Functions
angle_z_to_quaternion (angle_z) |
Converts an angle in the z axis (Euler angle z component) to a quaternion. |
check_assets () |
Check whether Cozmo assets are available. |
frange (start, stop, step) |
|
get_cozmo_anim_dir () |
Get Cozmo animation asset directory. |
get_cozmo_asset_dir () |
Get Cozmo asset directory. |
get_pycozmo_dir () |
Get PyCozmo directory. |
hex_dump (data) |
|
hex_load (data) |
Classes
Angle (radians, degrees) |
Angle representation. |
Distance (mm, inches) |
Represents a distance. |
FPSTimer (fps) |
A timer that maintains frame rate by sleeping for a variable amount of time. |
Matrix44 (m00, m10, m20, m30, m01, m11, m21, …) |
A 4x4 Matrix for representing the rotation and/or position of an object in the world. |
Pose (x, y, z, q0, q1, q2, q3, angle_z, …) |
A combination of position (vector) and rotation (quaternion). |
Quaternion (q0, q1, q2, q3, angle_z) |
Represents rotation. |
Speed (mmps) |
Speed representation. |
Vector3 (x, y, z) |
Represents a 3D Vector (type/units aren’t specified). |
-
class
pycozmo.util.
Angle
(radians: Optional[float] = None, degrees: Optional[float] = None)¶ Bases:
object
Angle representation.
- Args:
- radians (float): The number of radians the angle should represent
- (cannot be combined with
degrees
) - degrees (float): The number of degrees the angle should represent
- (cannot be combined with
radians
)
-
abs_value
¶ cozmo.util.Angle
: The absolute value of the angle.If the Angle is positive then it returns a copy of this Angle, otherwise it returns -Angle.
-
degrees
¶ Returns the angle in degrees.
-
radians
¶ Returns the angle in radians.
-
class
pycozmo.util.
Distance
(mm: Optional[float] = None, inches: Optional[float] = None)¶ Bases:
object
Represents a distance.
The class allows distances to be returned in either millimeters or inches.
- Args:
- mm (float): The number of millimeters the distance should
- represent (cannot be combined with
distance_inches
). - inches (float): The number of inches the distance should
- represent (cannot be combined with
distance_mm
).
-
inches
¶ The distance in inches.
-
mm
¶ The distance in millimeters.
-
class
pycozmo.util.
Speed
(mmps: float)¶ Bases:
object
Speed representation.
- Args:
- mmps (float): The number of millimeters per second the speed should represent.
-
mmps
¶ Returns the speed in millimeters per second (mmps).
-
class
pycozmo.util.
Vector3
(x: float, y: float, z: float)¶ Bases:
object
Represents a 3D Vector (type/units aren’t specified).
- Args:
- x (float): X component y (float): Y component z (float): Z component
-
set_to
(rhs)¶ Copy the x, y and z components of the given vector.
- Args:
- rhs (
Vector3
): The right-hand-side of this assignment - the - source vector to copy into this vector.
- rhs (
-
x
¶ The x component.
-
x_y_z
¶ The X, Y, Z elements of the Vector3 (x,y,z).
-
y
¶ The y component.
-
z
¶ The z component.
-
pycozmo.util.
angle_z_to_quaternion
(angle_z: pycozmo.util.Angle) → Tuple[float, float, float, float]¶ Converts an angle in the z axis (Euler angle z component) to a quaternion.
-
class
pycozmo.util.
Matrix44
(m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33)¶ Bases:
object
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 by Pose.to_matrix().
-
forward_xyz
¶ Returns the x,y,z components representing the matrix’s forward vector.
-
in_column_order
¶ Returns the contents of the matrix in column order.
-
in_row_order
¶ Returns the contents of the matrix in row order.
-
left_xyz
¶ Returns the x,y,z components representing the matrix’s left vector.
-
m00
¶
-
m01
¶
-
m02
¶
-
m03
¶
-
m10
¶
-
m11
¶
-
m12
¶
-
m13
¶
-
m20
¶
-
m21
¶
-
m22
¶
-
m23
¶
-
m30
¶
-
m31
¶
-
m32
¶
-
m33
¶
-
pos_xyz
¶ Returns the x,y,z components representing the matrix’s position vector.
-
set_forward
(x: float, y: float, z: float) → None¶ Set the x,y,z components representing the matrix’s forward vector.
-
set_left
(x: float, y: float, z: float) → None¶ Set the x,y,z components representing the matrix’s left vector.
-
set_pos
(x: float, y: float, z: float) → None¶ Set the x,y,z components representing the matrix’s position vector.
-
set_up
(x: float, y: float, z: float) → None¶ Set the x,y,z components representing the matrix’s up vector.
-
tabulated_string
¶ str: A multi-line string formatted with tabs to show the matrix contents.
-
up_xyz
¶ Returns the x,y,z components representing the matrix’s up vector.
-
-
class
pycozmo.util.
Quaternion
(q0: Optional[float] = None, q1: Optional[float] = None, q2: Optional[float] = None, q3: Optional[float] = None, angle_z: Optional[pycozmo.util.Angle] = None)¶ Bases:
object
Represents rotation.
-
angle_z
¶
-
euler_angles
¶ Returns the pitch, yaw, roll Euler components of the object’s rotation defined as rotations in the x, y, and z axis respectively.
Returns:
-
q0
¶
-
q0_q1_q2_q3
¶
-
q1
¶
-
q2
¶
-
q3
¶
-
to_matrix
(pos_x: float = 0.0, pos_y: float = 0.0, pos_z: float = 0.0) → pycozmo.util.Matrix44¶ Convert the Quaternion to a 4x4 matrix representing this rotation.
A position can also be provided to generate a full translation matrix.
-
-
class
pycozmo.util.
Pose
(x: float, y: float, z: float, q0: Optional[float] = None, q1: Optional[float] = None, q2: Optional[float] = None, q3: Optional[float] = None, angle_z: Optional[pycozmo.util.Angle] = None, origin_id: int = -1, is_accurate: bool = True)¶ Bases:
object
A combination of position (vector) and rotation (quaternion).
-
define_pose_relative_this
(new_pose)¶ Creates a new pose such that new_pose’s origin is now at the location of this pose.
-
invalidate
() → None¶ Mark this pose as being invalid (unusable).
-
is_accurate
¶ Returns True if this pose is valid and accurate.
Poses are marked as inaccurate if we detect movement via accelerometer, or if they were observed from far enough away that we’re less certain of the exact pose.
-
is_comparable
(other_pose: pycozmo.util.Pose) → bool¶ Are these two poses comparable.
Poses are comparable if they’re valid and having matching origin IDs.
-
is_valid
¶ Checks whether a pose is valid (usable).
-
origin_id
¶ Returns an ID maintained by the robot (engine) which represents which coordinate frame this pose is in.
-
position
¶ Returns the position component of this pose.
-
rotation
¶ Returns the rotation component of this pose.
-
to_matrix
()¶ Convert the Pose to a Matrix44.
-
-
class
pycozmo.util.
FPSTimer
(fps: int)¶ Bases:
object
A timer that maintains frame rate by sleeping for a variable amount of time.
-
sleep
()¶ Sleep to maintain the framerate. Should be called at the end of a frame.
-
-
pycozmo.util.
hex_dump
(data: bytes) → str¶
-
pycozmo.util.
hex_load
(data: str) → bytes¶
-
pycozmo.util.
frange
(start, stop, step)¶
-
pycozmo.util.
get_pycozmo_dir
() → pathlib.Path¶ Get PyCozmo directory.
-
pycozmo.util.
get_cozmo_asset_dir
() → pathlib.Path¶ Get Cozmo asset directory.
-
pycozmo.util.
check_assets
() → None¶ Check whether Cozmo assets are available.
-
pycozmo.util.
get_cozmo_anim_dir
() → pathlib.Path¶ Get Cozmo animation asset directory.