【Apollo源码分析】系列的第三部分【prediction】

来源:互联网 发布:sql server 进程死锁 编辑:程序博客网 时间:2024/06/09 08:22

【Apollo源码分析】系列的第三部分【prediction】

prediction


prediction模块目前依然处于待完善的状态,代码大概只有200行左右。 
预测模块的任务主要是:接收来自perception感知模块的基本信息,包括障碍物的位置,运动方向角,移动速度,加速度等。然后结合这些信息对障碍物进行轨迹预测trajectories Prediction,综合判断物体移动方向。

prediction/main.cc

先看main.cc的内容,只有一行代码。

  1. APOLLO_MAIN(apollo::prediction::Prediction);
  2. 注册Prediction模块,并执行该模块的内容。

prediction/prediction.h

本文件代码也不多。

  1. class Prediction : public apollo::common::ApolloApp {
  2. public:
  3. ~Prediction() = default;
  4. std::string Name() const override; //模块名称
  5. common::Status Init() override; //初始化操作
  6. common::Status Start() override; //模块的内容
  7. void Stop() override; //清理函数
  8. private:
  9. void OnPerception(//预测的回调函数
  10. const perception::PerceptionObstacles &perception_obstacles);
  11. };

.cc文件:

  1. apollo::common::Status Prediction::Init() {
  2. AdapterManager::instance()->Init();
  3. //注册预测部分的回调函数
  4. AdapterManager::SetPerceptionObstaclesCallback(&Prediction::OnPerception,this);
  5. return apollo::common::Status::OK();
  6. }
  1. apollo::common::Status Prediction::Start() {
  2. return apollo::common::Status::OK();
  3. }
  4. void Prediction::Stop() {}
  5. 以上都是常规例行代码。
  1. void Prediction::OnPerception(const PerceptionObstacles &perception_obstacles) {
  2. PredictionObstacles prediction_obstacles;
  3. AdapterManager::FillPredictionHeader(Name(),
  4. prediction_obstacles.mutable_header());
  5. AdapterManager::PublishPrediction(prediction_obstacles);
  6. //发送预测结果。但是这里并没有任何结果。还需要完善...。
  7. ADEBUG << prediction_obstacles.ShortDebugString();
  8. }

prediction/common/prediction_gflags.h

  1. // System gflags
  2. DECLARE_string(prediction_module_name);//声明模块名称

.cc文件:

  1. // System gflags
  2. DEFINE_string(prediction_module_name, "prediction",
  3. "Default prediciton module name");//定义模块名称

prediction/proto/prediction_obstacle.proto

以下是prediction_obstacle的定义。

  1. syntax = "proto2";
  2. package apollo.prediction;
  3. import "modules/common/proto/error_code.proto";
  4. import "modules/common/proto/header.proto";
  5. import "modules/perception/proto/perception_obstacle.proto";
  6. // 预测的障碍物轨迹节点,[x,y,z]表示位置,velocity表示速度 m/s.
  7. message TrajectoryPoint {
  8. optional double x = 1; // x,y,z表示轨迹point位置,单位是m.
  9. optional double y = 2; //
  10. optional double z = 3; //
  11. optional double velocity = 4; // 速度 v
  12. optional double t = 5; //节点point距离message发布的时间
  13. optional double heading = 6; // head角。
  14. }
  15. //以概率表示的轨迹节点
  16. message Trajectory {
  17. optional double probability = 1; //概率
  18. repeated TrajectoryPoint trajectory_point = 2;//多个轨迹节点point
  19. }
  20. //预测障碍物信息
  21. message PredictionObstacle {
  22. //障碍物描述子
  23. optional apollo.perception.PerceptionObstacle perception_obstacle = 1;
  24. optional double time_stamp = 2; //以GPS计算的时间 GPS time in seconds
  25. // the length of the time for this prediction (e.g. 10s)
  26. optional double predicted_period = 3;//预测持续时间段
  27. repeated Trajectory trajectory = 4;//多个轨迹节点
  28. }
  29. message PredictionObstacles {
  30. optional apollo.common.Header header = 1;
  31. repeated PredictionObstacle prediction_obstacle = 2;//多个预测的障碍物,以概率表示
  32. optional apollo.common.ErrorCode perception_error_code = 3;//预测错误码
  33. }

总结

预测部分的代码就是这么多。是不是很简洁? 
自动驾驶难不难?我个人觉得这是一件很难的事情。 
但是把复杂的事分解为简单的事的能力却很重要。 
Apollo的一个优点是模块化的工作做的非常好。 
有很清晰的分工,有良好的架构设计。

最重要的一点:

化繁为简的能力很重要。

过一段时间推荐些 Motion prediction的 文章。 
本文首发于微信公众号slamcode


注释版源码:源码




阅读全文
1 0