La manipulation des trajectoires

Une fois qu’une trajectoire a été générée, vous pouvez en extraire des informations à l’aide de certaines méthodes. Ces méthodes seront utiles lors de l’écriture de code pour suivre ces trajectoires.

Obtenir la durée totale de la trajectoire

Because all trajectories have timestamps at each point, the amount of time it should take for a robot to traverse the entire trajectory is pre-determined. The TotalTime() (C++) / getTotalTimeSeconds() (Java) / totalTime (Python) method can be used to determine the time it takes to traverse the trajectory.

// Get the total time of the trajectory in seconds
double duration = trajectory.getTotalTimeSeconds();
// Get the total time of the trajectory
units::second_t duration = trajectory.TotalTime();
# Get the total time of the trajectory
duration = trajectory.totalTime()

Échantillonnage de la trajectoire

The trajectory can be sampled at various timesteps to get the pose, velocity, and acceleration at that point. The Sample(units::second_t time) (C++) / sample(double timeSeconds) (Java/Python) method can be used to sample the trajectory at any timestep. The parameter refers to the amount of time passed since 0 seconds (the starting point of the trajectory). This method returns a Trajectory::Sample with information about that sample point.

// Sample the trajectory at 1.2 seconds. This represents where the robot
// should be after 1.2 seconds of traversal.
Trajectory.Sample point = trajectory.sample(1.2);
// Sample the trajectory at 1.2 seconds. This represents where the robot
// should be after 1.2 seconds of traversal.
Trajectory::State point = trajectory.Sample(1.2_s);
# Sample the trajectory at 1.2 seconds. This represents where the robot
# should be after 1.2 seconds of traversal.
point = trajectory.sample(1.2)

La structure Trajectory::Sample contient plusieurs informations sur le point d’échantillonnage:

  • t: Le temps écoulé depuis le début de la trajectoire jusqu’au point d’échantillonnage.

  • velocity: la vélocité au point d’échantillonnage.

  • acceleration: l’accélération au point d’échantillonnage.

  • pose: la pose (x, y, cap) au point d’échantillonnage.

  • curvature: la courbure (taux de changement de cap par rapport à la distance le long de la trajectoire) au point d’échantillonnage.

Remarque: La vitesse angulaire au point d’échantillonnage peut être calculée en multipliant la vitesse par la courbure.

Obtention de tous les états de la trajectoire (avancé)

A more advanced user can get a list of all states of the trajectory by calling the States() (C++) / getStates() (Java) / states (Python) method. Each state represents a point on the trajectory. When the trajectory is created using the TrajectoryGenerator::GenerateTrajectory(...) method, a list of trajectory points / states are created. When the user samples the trajectory at a particular timestep, a new sample point is interpolated between two existing points / states in the list.