操纵轨迹

生成轨迹后,您可以使用某些方法从中检索信息。在编写代码以追踪这些轨迹时,这些方法将非常有用。

获取轨迹的总持续时间

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

轨迹采样

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)

Trajectory::Sample结构包含有关采样点的几条信息:

  • t:从轨迹开始到采样点为止的时间。

  • velocity:采样点的速度。

  • acceleration: 采样点的加速度。

  • pose:采样点的姿态 (x, y, heading)

  • “曲率”:采样点的曲率(航向的变化率,相对于沿着轨迹的距离)。

注意:可以通过将速度乘以曲率来计算采样点的角速度。

获取轨迹的所有状态(高级)

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.