概述
对discretized_trajectory.cc和.h进行解析,以及通过discretized_trajectory_test.cc测试用例来了解DiscretizedTrajectory类的使用。
TrajectoryPoint类,该类由.proto文件生成 proto文件位于modules\common\proto\pnc_point.proto proto文件中的message TrajectoryPoint 每个TrajectoryPoint,包含x,y,heading,v,a,s,t,da,steer等信息 DiscretizedTrajectory类就是存放一系列TrajectoryPoint轨迹点的一个数据结构类,以及一些相关增删改以及根据时间插值,根据纵向位置s插值等操作
discretized_trajectory.h
#pragma once
#include <vector>
#include "cyber/common/log.h"
#include "modules/common/math/vec2d.h"
#include "modules/planning/proto/planning.pb.h"
namespace apollo {
namespace planning {
class DiscretizedTrajectory : public std::vector<common::TrajectoryPoint> {
public:
DiscretizedTrajectory() = default;
explicit DiscretizedTrajectory(const ADCTrajectory& trajectory);
explicit DiscretizedTrajectory(
const std::vector<common::TrajectoryPoint>& trajectory_points);
void SetTrajectoryPoints(
const std::vector<common::TrajectoryPoint>& trajectory_points);
virtual ~DiscretizedTrajectory() = default;
virtual common::TrajectoryPoint StartPoint() const;
virtual double GetTemporalLength() const;
virtual double GetSpatialLength() const;
virtual common::TrajectoryPoint Evaluate(const double relative_time) const;
virtual size_t QueryLowerBoundPoint(const double relative_time,
const double epsilon = 1.0e-5) const;
virtual size_t QueryNearestPoint(const common::math::Vec2d& position) const;
size_t QueryNearestPointWithBuffer(const common::math::Vec2d& position,
const double buffer) const;
virtual void AppendTrajectoryPoint(
const common::TrajectoryPoint& trajectory_point);
void PrependTrajectoryPoints(
const std::vector<common::TrajectoryPoint>& trajectory_points) {
if (!empty() && trajectory_points.size() > 1) {
ACHECK(trajectory_points.back().relative_time() <
front().relative_time());
}
insert(begin(), trajectory_points.begin(), trajectory_points.end());
}
const common::TrajectoryPoint& TrajectoryPointAt(const size_t index) const;
size_t NumOfPoints() const;
virtual void Clear();
};
inline size_t DiscretizedTrajectory::NumOfPoints() const { return size(); }
inline void DiscretizedTrajectory::Clear() { clear(); }
}
}
感觉.h文件已经把DiscretizedTrajectory类的作用介绍的很清楚了,该类的实现文件discretized_trajectory.cc和测试文件discretized_trajectory_test.cc不再解析。
|