Manipulando trayectorias

Una vez que se ha generado una trayectoria, puede recuperar información de ella utilizando ciertos métodos. Estos métodos serán útiles al escribir el código para seguir estas trayectorias.

Obteniendo la duración total de la trayectoria

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()

Una muestra de la trayectoria

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 estructura Trajectory::Sample tiene varias piezas de información acerca del punto de muestra:

  • t: El tiempo transcurrido desde el inicio de la trayectoria hasta el punto de muestra.

  • velocity: La velocidad en el punto de muestra.

  • acceleration: La aceleracion en el punto de muestra.

  • `pose: la pose (x, y, rumbo) en el punto de muestra.

  • curvature: la curvatura (tasa de cambio de rumbo con respecto a la distancia a lo largo de la trayectoria) en el punto de muestra.

Nota: La velocidad angular en el punto de muestra se puede calcular multiplicando la velocidad por la curvatura.

Obteniendo todos los estados de la trayectoria (avanzado)

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.