APIs: SDK

class TrajectoryTracker

DRLTT Trajectory Tracking C++ SDK.

Nomenclature for documentation:

  • x: X-coordinate in [m] within (-inf, +inf).

  • y: Y-coordinate in [m] within (-inf, +inf).

  • r: heading in [rad] within [-pi, pi), following convention of math lib like std::atan2.

  • v: scalar speed in [m/s] within [0, +inf)。

  • a: acceleration in [m/s/s] within [0, +inf)。

  • s: steering angle in [rad] within [-max_s, +max_s] where max_s is the steering limit.

TODO: move this part to the doc. of protobuf.

Predefined type for documentation

  • STATE : tuple<float x, float y, float r, float v>, state of dynamics model.

  • ACTION : tuple<float a, float s>, action of dynamics model.

  • OBSERVATION : vector<float>, vectorized observation feature.

  • REFERENCE_WAYPOINT : tuple<float x, float y>, vectorized observation feature.

  • REFERENCE_LINE : vector<REFERENCE_WAYPOINT>, reference line for the dynamics model to track.

Public Functions

TrajectoryTracker(const std::string &load_path, int dynamics_model_index)
Parameters:
  • load_path – Path to checkpoint. See “Checkpoint Structure” in ./README.md for detail.

  • dynamics_model_index – The index of dynamics model. The order corresponds to the dynamics_model_configs within the config YAML in the checkpoint folder.

bool set_reference_line(const REFERENCE_LINE &reference_line)

Set a reference line.

It will estimate an initial state of the dynamics model, which may be overwritten by other function later if necessary.

Parameters:

reference_line – Reference line to be tracked.

Returns:

Success flag.

bool set_dynamics_model_initial_state(const STATE &init_state)

Set the Dynamics Model Initial State object.

Parameters:

init_state – Initial state.

Returns:

true Setting succeeded.

Returns:

false Setting failed.

TRAJECTORY TrackReferenceLine()

Perform trajectory tracking.

Roll out a trajectory and return the tracked trajectory.

Returns:

Trajectory containing states, actions, and observations of the roll-out. Format=<vector<STATE>, vector<ACTION>, vector<OBSERVATION>>.

class TrajectoryTracking

Trajectory tracking environment.

Class for managing dynamics models/reference lines/policy model/etc. and performing rollouts.

Public Functions

bool LoadPolicy(const std::string &policy_path)

Load the underlying policy.

Parameters:

policy_path – Path to the policy.

Returns:

true Loading succeeded.

Returns:

false Loading failed.

bool LoadEnvData(const std::string &env_data_path)

Load the environment data.

Parameters:

env_data_path – Path to the protobuf binary file of environment data.

Returns:

true Loading succeeded.

Returns:

false Loading failed.

bool set_dynamics_model_hyper_parameter(int index)

Set the dynamics model hyper parameter with index. TODO: provide function to set dynamics model by name.

Parameters:

index – The index of dynamicsmo stored in the env_data.

Returns:

true Setting succeeded.

Returns:

false Setting failed.

bool set_reference_line(const std::vector<REFERENCE_WAYPOINT> &reference_line)

Set the reference line object.

Parameters:

reference_line – Reference line.

Returns:

true Setting succeeded.

Returns:

false Setting failed.

bool set_reference_line(const drltt_proto::ReferenceLine &reference_line)

Set the reference line object.

Parameters:

reference_line – Reference line.

Returns:

true Setting succeeded.

Returns:

false Setting failed.

bool set_dynamics_model_initial_state(STATE state)

Set the dynamics model initial state object.

Parameters:

state – Initial state to be set to dynamics model.

Returns:

true Setting succeeded.

Returns:

false Setting failed.

bool set_dynamics_model_initial_state(drltt_proto::State state)

Set the dynamics model initial state object.

Parameters:

state – Initial state to be set to dynamics model.

Returns:

true Setting succeeded.

Returns:

false Setting failed.

bool RollOut()

Roll out a trajectory based on underlying policy model and environment.

Returns:

true Roll-out succeeded.

Returns:

false Roll-out failed.

TRAJECTORY get_tracked_trajectory()

Get the tracked trajectory object.

Returns:

TRAJECTORY Tracked trajectory, format=<vector<STATE>,, vector<ACTION>, vector<OBSERVATION>>

Public Static Functions

static bool EstimateInitialState(const drltt_proto::ReferenceLine &reference_line, drltt_proto::State &state, float delta_t)

Estimate the initial state.

Parameters:
  • reference_line – Reference line.

  • state – The returned initial state.

  • delta_t – Step interval.

Returns:

true Setting succeeded.

Returns:

false Setting failed.

class TorchJITModulePolicy

A policy based on torch JIT module.

Public Functions

bool Load(const std::string &jit_module_path)

Load a JIT module from a specified path.

Parameters:

jit_module_path – Path to JIT module.

Returns:

true Module loading succeeded.

Returns:

false Module loading failed.

torch::Tensor Infer(const torch::Tensor &observations_tensor)

Perform inference.

Parameters:

observations_tensor – The torch tensor of observations, Shape={batch_size, observation_dim}.

Returns:

torch::Tensor The torch tensor of actions. Shape={batch_size, action_dim}

std::vector<float> Infer(const std::vector<float> &observations_vec, const std::initializer_list<int64_t> &shape_vec)

Perform inference.

Parameters:
  • observations_vec – Vector of observation data.

  • shape_vec – Vector of the shape of observation tensor.

Returns:

std::vector<float> , size=batch_size*action_dim

std::vector<float> Infer(const std::vector<float> &observations_vec)

Perform inference.

Parameters:

observations_vec – Vector of observation data. Assuming batch_size=1, i.e. original shape={1, observation_dim}

Returns:

std::vector<float> , size=batch_size*action_dim.