Animation

Inheritance diagram of hermespy.simulation.animation.Trajectory, hermespy.simulation.animation.StaticTrajectory, hermespy.simulation.animation.LinearTrajectory

Movements of devices and other objects within simulations may be described by Trajectories, which model the veloctiy, position and orientation of the object as a function of time. Generally, objects that may be animated within a simulation should inherit from the Moveable class, which exposes the trajectory property. The currently available trajectory types are:

Trajectory Types

Type

Description

StaticTrajectory

A trajectory that does not change over time.

LinearTrajectory

A trajectory that moves in a straight line at a constant velocity.

The following example demonstrates how to assign a linear trajectory to a device within a simulation and plot the scenario:

 1# Create a new simulation featuring two devices
 2simulation = Simulation()
 3device_alpha = simulation.new_device()
 4device_beta = simulation.new_device()
 5
 6# Assign each device a linear trajectory
 7device_alpha.trajectory = LinearTrajectory(
 8    initial_pose=Transformation.From_Translation(np.array([0, 0, 20])),
 9    final_pose=Transformation.From_Translation(np.array([0, 100, 5])),
10    duration=60,
11)
12device_beta.trajectory = LinearTrajectory(
13    initial_pose=Transformation.From_Translation(np.array([100, 100, 0])),
14    final_pose=Transformation.From_Translation(np.array([0, 0, 0])),
15    duration=60,
16)
17
18# Visualize the trajectories
19simulation.scenario.visualize()
20plt.show()
class Trajectory[source]

Bases: ABC

Base class for motion trajectories of moveable objects within simulation scenarios.

lookat(target, up=array([0., 1., 0.]))[source]

Set a target to look at and track.

Parameters:
  • target (Trajectory) – Target trajectory.

  • up (numpy.ndarray) – Up/sky/head/ceiling global unit vector. Defaults to [0., 1., 0.].

Return type:

None

lookat_disable()[source]
Return type:

None

lookat_enable()[source]
Return type:

None

sample(timestamp)[source]

Sample the trajectory at a given point in time.

Parameters:

timestamp (float) – Time at which to sample the trajectory in seconds.

Return type:

TrajectorySample

Returns: A sample of the trajectory.

abstract sample_orientation(timestamp)[source]

Sample the trajectory’s orientation. Does not consider lookat.

Parameters:

timestamp (float) – Time at which to sample the trajectory in seconds.

Return type:

ndarray

Returns: A sample of the trajectory’s orientation matrix (matrix (3, 3) of float).

abstract sample_translation(timestamp)[source]

Sample the trajectory’s translation.

Parameters:

timestamp (float) – Time at which to sample the trajectory in seconds.

Return type:

ndarray

Returns: A sample of the trajectory’s translation (vector (3,) of floats).

abstract sample_velocity(timestamp)[source]

Sample the trajectory’s velocity.

Parameters:

timestamp (float) – Time at which to sample the trajectory in seconds.

Return type:

ndarray

Returns: A sample of the trajectory’s velocity (vector (3,) of floats).

abstract property max_timestamp: float

Maximum timestamp of the trajectory in seconds.

For times greater than this value the represented object’s pose is assumed to be constant.

class StaticTrajectory(pose=None, velocity=None)[source]

Bases: Serializable, Trajectory

A helper class generating a static trajectory.

sample(timestamp)[source]

Sample the trajectory at a given point in time.

Parameters:

timestamp (float) – Time at which to sample the trajectory in seconds.

Return type:

TrajectorySample

Returns: A sample of the trajectory.

sample_orientation(timestamp)[source]

Sample the trajectory’s orientation. Does not consider lookat.

Parameters:

timestamp (float) – Time at which to sample the trajectory in seconds.

Return type:

ndarray

Returns: A sample of the trajectory’s orientation matrix (matrix (3, 3) of float).

sample_translation(timestamp)[source]

Sample the trajectory’s translation.

Parameters:

timestamp (float) – Time at which to sample the trajectory in seconds.

Return type:

ndarray

Returns: A sample of the trajectory’s translation (vector (3,) of floats).

sample_velocity(timestamp)[source]

Sample the trajectory’s velocity.

Parameters:

timestamp (float) – Time at which to sample the trajectory in seconds.

Return type:

ndarray

Returns: A sample of the trajectory’s velocity (vector (3,) of floats).

property max_timestamp: float

Maximum timestamp of the trajectory in seconds.

For times greater than this value the represented object’s pose is assumed to be constant.

property pose: Transformation

Static pose of the object.

property velocity: ndarray

Static velocity of the object.

class LinearTrajectory(initial_pose, final_pose, duration, start=0.0)[source]

Bases: Trajectory

A helper class generating a linear trajectory between two poses.

sample_orientation(timestamp)[source]

Sample the trajectory’s orientation. Does not consider lookat.

Parameters:

timestamp (float) – Time at which to sample the trajectory in seconds.

Return type:

ndarray

Returns: A sample of the trajectory’s orientation matrix (matrix (3, 3) of float).

sample_translation(timestamp)[source]

Sample the trajectory’s translation.

Parameters:

timestamp (float) – Time at which to sample the trajectory in seconds.

Return type:

ndarray

Returns: A sample of the trajectory’s translation (vector (3,) of floats).

sample_velocity(timestamp)[source]

Sample the trajectory’s velocity.

Parameters:

timestamp (float) – Time at which to sample the trajectory in seconds.

Return type:

ndarray

Returns: A sample of the trajectory’s velocity (vector (3,) of floats).

property max_timestamp: float

Maximum timestamp of the trajectory in seconds.

For times greater than this value the represented object’s pose is assumed to be constant.

class Moveable(trajectory)[source]

Bases: object

Base class of moveable objects within simulation scenarios.

Parameters:

trajectory (Trajectory, optional) – Trajectory this object is following. If not provided, the object is assumed to be static.

property max_trajectory_timestamp: float

Maximum timestamp of this object’s motion trajectory.

property trajectory: Trajectory

Motion trajectory this object is following.

class TrajectorySample(timestamp, pose, velocity)[source]

Bases: object

Dataclass for a single pose sample within a trajectory.

Parameters:
  • timestamp (float) – Time at which the trajectory was sampled in seconds.

  • pose (Timestamp) – Pose of the object at the given time.

  • velocity (numpy.ndarray) – Velocity of the object at the given time.

property pose: Transformation

Pose of the object at the given time.

property timestamp: float

Time at which the trajectory was sampled in seconds.

property velocity: ndarray

Velocity of the object at the given time.