Main Content

Trajectory

Create trajectory using timestamps and waypoints

Since R2024b

Description

The Trajectory object creates a trajectory using timestamps and waypoints.

Creation

Description

trajectory = scenariobuilder.Trajectory(timestamps,x,y,z) creates a trajectory object, trajectory, using the specified timestamps timestamps and the corresponding xyz-coordinates of waypoints. x, y, and z specify the first, second, and third columns of the Position property, respectively.

example

trajectory = scenariobuilder.Trajectory(timestamps,waypoints) creates a trajectory object, trajectory, using the specified timestamps timestamps and the corresponding waypoints waypoints. The waypoints argument specifies the Position property.

example

trajectory = scenariobuilder.Trajectory(___,Name=Value) sets writable properties using one or more name-value arguments, in addition to any combination of input arguments from the previous syntaxes. For example, Attributes=attributes specifies the optional trajectory attributes attributes.

Note

This object requires the Scenario Builder for Automated Driving Toolbox™ support package. You can install the Scenario Builder for Automated Driving Toolbox support package from the Add-On Explorer. For more information about installing add-ons, see Get and Manage Add-Ons.

Input Arguments

expand all

Timestamps of the waypoint data, specified as an N-element numeric column vector, an N-element datetime array, or an N-element duration array. N is the number of timestamps. Each element in the timestamps argument specifies the time at which the corresponding waypoint data was collected. If you specify an N-element numeric column vector, units must be in seconds.

When you initialize the object with timestamp and waypoint data, the object arranges the data by the input timestamps in increasing order.

This argument sets the Timestamps property.

x-coordinates of waypoints in the world coordinate system, specified as an N-element numeric column vector. N is the number of timestamps. Units are in meters.

This argument sets the first column of Position property.

Data Types: single | double

y-coordinates of waypoints in the world coordinate system, specified as an N-element numeric column vector. N is the number of timestamps. Units are in meters.

This argument sets the second column of Position property.

Data Types: single | double

z-coordinates of waypoints in the world coordinate system, specified as an N-element numeric column vector. N is the number of timestamps. Units are in meters.

This argument sets the third column of Position property.

Data Types: single | double

Trajectory waypoints, specified as a real-valued N-by-3 matrix. N is the number of waypoints. Each row represents the x-, y-, and z-coordinates of a waypoint.

Waypoints are in the world coordinate system. Units are in meters.

This argument sets the Position property.

Data Types: single | double

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: scenariobuilder.Trajectory(Name="Trajectory1") specifies the name of the trajectory object as "Trajectory1".

Name of the trajectory object, specified as a string scalar or character vector.

This argument sets the Name property.

Data Types: char | string

Anchor of trajectory, specified as a three-element row vector.

For a trajectory created from GPS data, the LocalOrigin value defines the anchor for the local coordinate system, specified as a three-element row vector of the form [latitude longitude altitude]. Units of latitude and longitude are in degrees, and units of altitude are in meters.

For a trajectory created from sensor data other than GPS data, the LocalOrigin value defines the origin of the local Cartesian coordinate system, specified as a three-element row vector of the form [x y z]. Units are in meters.

This argument sets the LocalOrigin property.

Data Types: single | double

Reference time of the trajectory, specified as a nonnegative scalar. The data type of the TimeOrigin value and the data type of the Timestamps property must be the same. If you specify a nonnegative scalar, units must be in seconds.

The trajectory object subtracts the TimeOrigin value from all timestamps and updates the Timestamps property with the subtracted timestamps.

This argument sets the TimeOrigin property.

Data Types: single | double

Optional trajectory attributes, specified as an N-by-1 cell array. N is the number of timestamps. Each cell contains additional trajectory attributes recorded at the corresponding timestamp.

This argument sets the Attributes property.

Data Types: cell

Properties

expand all

Name of the trajectory object, specified as a string scalar or character vector.

Data Types: char | string

This property is read-only.

Number of waypoints in the trajectory data, represented as a nonnegative integer.

Data Types: uint8 | uint16 | uint32 | uint64

This property is read-only.

Time duration for which the trajectory data was acquired, represented as a nonnegative scalar. Units are in seconds.

Data Types: double

This property is read-only.

Mean sample rate of the trajectory waypoints, represented as a nonnegative scalar. This value defines the number of waypoints recorded per second. Units are in hertz.

Data Types: double

This property is read-only.

Mean sample time of the trajectory waypoints, represented as a nonnegative scalar. This value defines the mean time interval between two consecutive waypoint samples. Units are in seconds.

Data Types: double

This property is read-only after object creation. To set this property, use the timestamps argument when calling the scenarioBuilder.Trajectory function.

Timestamps of the waypoint data, represented as an N-element numeric column vector, an N-element datetime array, or an N-element duration array. N is the number of timestamps. Each element in the Timestamps property specifies the time at which the waypoint data was collected. If you specify an N-element numeric column vector, units must be in seconds.

When you initialize the object with timestamps and waypoint data, the object arranges the data in increasing order of the input timestamps.

This property is read-only after object creation. To set this property, use the waypoints argument, or x, y, and z arguments when calling the scenarioBuilder.Trajectory function.

Position of each waypoint, represented as a real-valued N-by-3 matrix. N is the number of waypoints. Each row represents the x-, y-, and z-coordinates of a waypoint.

Position of waypoints are in the world coordinate system. Units are in meters.

Data Types: single | double

This property is read-only.

Orientation angle at each waypoint, represented as a real-valued N-by-3 matrix. N is the number of waypoints. Each row represents the orientation angles relative to the x-, y-, and z-axes of the corresponding waypoint.

Orientations are in the local coordinate system. Units are in radians.

Data Types: double

This property is read-only.

Velocity at each waypoint, represented as a real-valued N-by-3 matrix. N is the number of waypoints. Each row represents the velocity in the x-, y-, and z-directions at the corresponding waypoint. Units are in meters per second.

Data Types: double

This property is read-only.

Course angle at each waypoint, represented as a real-valued N-element column vector. N is the number of waypoints. Each row represents the course angle at a waypoint. Units are in degrees.

Data Types: double

This property is read-only.

Ground speed at each waypoint, represented as a real-valued N-element column vector. N is the number of waypoints. Each row represents the ground speed at a waypoint. Units are in meters per second.

Data Types: double

This property is read-only.

Acceleration at each waypoint, represented as a real-valued N-by-3 matrix. N is the number of waypoints. Each row represents the acceleration relative to the x-, y-, and z-axes of the corresponding waypoint.

Accelerations are in the local coordinate system. Units are in meters per second squared.

Data Types: double

This property is read-only.

Angular velocity at each waypoint, represented as a real-valued N-by-3 matrix. N is the number of waypoints. Each row represents the angular velocities relative to the x-, y-, and z-axes of the corresponding waypoint.

Angular velocities are in the local coordinate system. Units are in radian per second squared.

Data Types: double

Anchor of trajectory, specified as a three-element row vector.

For a trajectory created from GPS data, the LocalOrigin value defines the anchor for the local coordinate system, specified as a three-element row vector of the form [latitude longitude altitude]. Units of latitude and longitude are in degrees, and units of altitude are in meters.

For a trajectory created from sensor data other than GPS data, the LocalOrigin value defines the origin of the local Cartesian coordinate system, specified as a three-element row vector of the form [x y z]. Units are in meters.

Data Types: single | double

Reference time of the trajectory, specified as a nonnegative scalar. The data type of the TimeOrigin value and the data type of the Timestamps property must be the same. If you specify a nonnegative scalar, units must be in seconds.

The trajectory object subtracts the TimeOrigin value from all timestamps and updates the Timestamps property with the subtracted timestamps.

Data Types: single | double

Optional trajectory attributes, specified as an N-by-1 cell array. N is the number of timestamps. Each cell contains additional trajectory attributes recorded at the corresponding timestamp.

Data Types: cell

Object Functions

addAdd waypoints to trajectory object
removeRemove data from sensor data object
readRead data from sensor data object
copyCreate copy of sensor data object
cropCrop data from sensor data object
synchronizeSynchronize sensor data with reference sensor information
plotPlot trajectory data
writeCSVWrite trajectory data into CSV file
distanceCompute total traveled distance of trajectory data
normalizeTimestampsNormalize timestamps of sensor data object
smoothSmooth trajectory data
exportToDrivingScenarioExport trajectory to driving scenario
exportToRoadRunnerExport trajectory to RoadRunner

Examples

collapse all

Load recorded GPS trajectory data into the workspace.

load("recordedGPSData.mat","X","Y","Z","timestamps")

Create a trajectory object by using the loaded timestamps and xyz-coordinates.

traj1 = scenariobuilder.Trajectory(timestamps,X,Y,Z)
traj1 = 
  Trajectory with properties:

               Name: ''

         NumSamples: 392
           Duration: 19.5498
         SampleRate: 20.0513
         SampleTime: 0.0500
         Timestamps: [392×1 double]

           Position: [392×3 double]
        Orientation: [392×3 double]
           Velocity: [392×3 double]
             Course: [392×1 double]
        GroundSpeed: [392×1 double]
       Acceleration: [392×3 double]
    AngularVelocity: [392×3 double]

        LocalOrigin: [0 0 0]
         TimeOrigin: 0

         Attributes: []

Plot the trajectory object.

plot(traj1,ShowZ=true,ShowSpeed=true,ShowVelocity=true,LineWidth=0.1,MarkerSize=1)

Combine the xyz-coordinates into a waypoint matrix, and create another trajectory by using the timestamps and waypoints.

waypoints = [X Y Z];
traj2 = scenariobuilder.Trajectory(timestamps,waypoints)
traj2 = 
  Trajectory with properties:

               Name: ''

         NumSamples: 392
           Duration: 19.5498
         SampleRate: 20.0513
         SampleTime: 0.0500
         Timestamps: [392×1 double]

           Position: [392×3 double]
        Orientation: [392×3 double]
           Velocity: [392×3 double]
             Course: [392×1 double]
        GroundSpeed: [392×1 double]
       Acceleration: [392×3 double]
    AngularVelocity: [392×3 double]

        LocalOrigin: [0 0 0]
         TimeOrigin: 0

         Attributes: []

Plot the trajectory object.

plot(traj2,ShowHeading=true,ShowOrientation=true,LineWidth=0.1,MarkerSize=1)

Version History

Introduced in R2024b