/****************Apollo源码分析****************************
Copyright 2018 The File Authors & zouyu. All Rights Reserved.
Contact with: 1746430162@qq.com 181663309504
源码主要是c++实现的,也有少量python,git下载几百兆,其实代码不太多,主要是地图和数据了大量空间,主要程序
在apollo/modules目录中,
在apollo/modules目录中,
我们把它分成以下几部分(具体说明见各目录下的modules):
感知:感知当前位置,速度,障碍物等等
Apollo/modules/perception
预测:对场景下一步的变化做出预测
Apollo/modules/prediction
规划:
(1) 全局路径规划:通过起点终点计算行驶路径
Apollo/modules/routing
(2) 规划当前轨道:通过感知,预测,路径规划等信息计算轨道
Apollo/modules/planning
(3) 规划转换成命令:将轨道转换成控制汽车的命令(加速,制动,转向等)
Apollo/modules/control
其它
(1) 输入输出
i. Apollo/modules/drivers 设备驱动
ii. Apollo/modules/localization 位置信息
iii. Apollo/modules/monitor 监控模块
iv. Apollo/modules/canbus 与汽车硬件交互
v. Apollo/modules/map 地图数据
vi. Apollo/modules/third_party_perception 三方感知器支持
(2) 交互
i. Apollo/modules/dreamview 可视化模块
ii. Apollo/modules/hmi 把汽车当前状态显示给用户
(3) 工具
i. Apollo/modules/calibration 标注工具
ii. Apollo/modules/common 支持其它模块的公共工具
iii. Apollo/modules/data 数据工具
iv. Apollo/modules/tools 一些Python工具
(4) 其它
i. Apollo/modules/elo 高精度定位系统,无源码,但有文档
ii. Apollo/modules/e2e 收集传感器数据给PX2,ROS
自动驾驶系统先通过起点终点规划出整体路径(routing);然后在行驶过程中感知(perception)当前环境
(识别车辆行人路况标志等),并预测下一步发展;然后把已知信息都传入规划模块(planning),规划出之后的轨道;
控制模块(control)将轨道数据转换成对车辆的控制信号,通过汽车交互模块(canbus)控制汽车.
(识别车辆行人路况标志等),并预测下一步发展;然后把已知信息都传入规划模块(planning),规划出之后的轨道;
控制模块(control)将轨道数据转换成对车辆的控制信号,通过汽车交互模块(canbus)控制汽车.
我觉得这里面算法技术含量最高的是感知perception和规划planning,具体请见本博客中各模块的分析代码。
/****************************************************************************************
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#ifndef MODULES_PERCEPTION_OBSTACLE_BASE_OBJECT_SUPPLEMENT_H_
#define MODULES_PERCEPTION_OBSTACLE_BASE_OBJECT_SUPPLEMENT_H_
#include <boost/circular_buffer.hpp>
#include <opencv2/opencv.hpp>
#include <memory>
#include <string>
#include <vector>
#include "Eigen/Core"
#include "modules/perception/obstacle/base/types.h"
namespace apollo {
namespace perception {
struct alignas(16) RadarSupplement {
RadarSupplement();
~RadarSupplement();
RadarSupplement(const RadarSupplement& rhs);
RadarSupplement& operator = (const RadarSupplement& rhs);
void clone(const RadarSupplement& rhs);
// distance
float range = 0.0f;
// x -> forward, y -> left
float angle = 0.0f;
float relative_radial_velocity = 0.0f;
float relative_tangential_velocity = 0.0f;
float radial_velocity = 0.0f;
};
typedef std::shared_ptr<RadarSupplement> RadarSupplementPtr;
typedef std::shared_ptr<const RadarSupplement> RadarSupplementConstPtr;
struct alignas(16) RadarFrameSupplement {
RadarFrameSupplement();
~RadarFrameSupplement();
RadarFrameSupplement(const RadarFrameSupplement& rhs);
RadarFrameSupplement& operator = (const RadarFrameSupplement& rhs);
void clone(const RadarFrameSupplement& rhs);
};
typedef std::shared_ptr<RadarFrameSupplement> RadarFrameSupplementPtr;
typedef std::shared_ptr<const RadarFrameSupplement>
RadarFrameSupplementConstPtr;
struct alignas(16) CameraFrameSupplement {
CameraFrameSupplement();
~CameraFrameSupplement();
CameraFrameSupplement(const CameraFrameSupplement& rhs);
CameraFrameSupplement& operator=(const CameraFrameSupplement& rhs);
void clone(const CameraFrameSupplement& rhs);
cv::Mat depth_map;
cv::Mat label_map;
cv::Mat lane_map;
cv::Mat img_src;
std::string source_topic;
};
typedef std::shared_ptr<CameraFrameSupplement> CameraFrameSupplementPtr;
typedef std::shared_ptr<const CameraFrameSupplement>
CameraFrameSupplementConstPtr;
struct alignas(16) CameraSupplement {
CameraSupplement();
~CameraSupplement();
CameraSupplement(const CameraSupplement& rhs);
CameraSupplement& operator=(const CameraSupplement& rhs);
void clone(const CameraSupplement& rhs);
// upper-left corner: x1, y1
Eigen::Vector2d upper_left;
// lower-right corner: x2, y2
Eigen::Vector2d lower_right;
// local track id
int local_track_id = -1;
// 2Dto3D, pts8.resize(16), x, y...
std::vector<float> pts8;
// front box upper-left corner: x1, y1
Eigen::Vector2d front_upper_left;
// front box lower-right corner: x2, y2
Eigen::Vector2d front_lower_right;
// front box upper-left corner: x1, y1
Eigen::Vector2d back_upper_left;
// front box lower-right corner: x2, y2
Eigen::Vector2d back_lower_right;
std::vector<float> object_feature;
// this is `alpha` angle from KITTI: Observation angle of object,
// ranging [-pi..pi]
double alpha = 0.0;
};
typedef std::shared_ptr<CameraSupplement> CameraSupplementPtr;
typedef std::shared_ptr<const CameraSupplement> CameraSupplementConstPtr;
struct alignas(16) VehicleStatus {
float yaw_rate;
float velocity;
float time_t; // time stamp
float time_d; // time stamp difference in image
Eigen::Matrix3f motion; // Motion Matrix
};
typedef boost::circular_buffer<VehicleStatus> MotionBuffer;
typedef std::shared_ptr<MotionBuffer> MotionBufferPtr;
typedef std::shared_ptr<const MotionBuffer> MotionBufferConstPtr;
struct alignas(16) Vehicle3DStatus {
float yaw_delta; // azimuth angle change
float pitch_delta;
float roll_delta;
float velocity_x; // east
float velocity_y; // north
float velocity_z; // up
float time_t; // time stamp
float time_d; // time stamp difference in image
Eigen::Matrix4f motion3d; // 3-d Motion Matrix
};
typedef boost::circular_buffer<Vehicle3DStatus> Motion3DBuffer;
typedef std::shared_ptr<Motion3DBuffer> Motion3DBufferPtr;
typedef std::shared_ptr<const Motion3DBuffer> Motion3DBufferConstPtr;
} // namespace perception
} // namespace apollo
#endif // MODULES_PERCEPTION_OBSTACLE_BASE_OBJECT_SUPPLEMENT_H_
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#ifndef
MODULES_PERCEPTION_OBSTACLE_BASE_OBJECT_SUPPLEMENT_H_
#define
MODULES_PERCEPTION_OBSTACLE_BASE_OBJECT_SUPPLEMENT_H_
//这里定义了各种传感器的目标补偿,我的理解是
//无人驾驶汽车在行进的过程中,获得的数据会产生偏差,需要及时补偿差值
#include
<boost/circular_buffer.hpp>
#include
<opencv2/opencv.hpp>
#include
<memory>
#include
<string>
#include
<vector>
#include
"Eigen/Core"
#include
"modules/perception/obstacle/base/types.h"
namespace
apollo
{
namespace
perception
{
struct
alignas
(
16
) RadarSupplement {
//雷达补偿
RadarSupplement
();
~RadarSupplement
();
RadarSupplement
(
const
RadarSupplement
&
rhs);
RadarSupplement
&
operator
=
(
const
RadarSupplement
&
rhs);
void
clone
(
const
RadarSupplement
&
rhs);
// distance
float
range
=
0.0f
;
// x -> forward, y -> left
float
angle
=
0.0f
;
float
relative_radial_velocity
=
0.0f
;
float
relative_tangential_velocity
=
0.0f
;
float
radial_velocity
=
0.0f
;
};
typedef
std::shared_ptr
<
RadarSupplement
>
RadarSupplementPtr;
typedef
std::shared_ptr
<
const
RadarSupplement
>
RadarSupplementConstPtr;
struct
alignas
(
16
) RadarFrameSupplement {
RadarFrameSupplement
();
~RadarFrameSupplement
();
RadarFrameSupplement
(
const
RadarFrameSupplement
&
rhs);
RadarFrameSupplement
&
operator
=
(
const
RadarFrameSupplement
&
rhs);
void
clone
(
const
RadarFrameSupplement
&
rhs);
};
typedef
std::shared_ptr
<
RadarFrameSupplement
>
RadarFrameSupplementPtr;
typedef
std::shared_ptr
<
const
RadarFrameSupplement
>
RadarFrameSupplementConstPtr;
struct
alignas
(
16
) CameraFrameSupplement {
//摄像头补偿
CameraFrameSupplement
();
~CameraFrameSupplement
();
CameraFrameSupplement
(
const
CameraFrameSupplement
&
rhs);
CameraFrameSupplement
&
operator
=
(
const
CameraFrameSupplement
&
rhs);
void
clone
(
const
CameraFrameSupplement
&
rhs);
cv::Mat depth_map;
cv::Mat label_map;
cv::Mat lane_map;
cv::Mat img_src;
std::string source_topic;
};
typedef
std::shared_ptr
<
CameraFrameSupplement
>
CameraFrameSupplementPtr;
typedef
std::shared_ptr
<
const
CameraFrameSupplement
>
CameraFrameSupplementConstPtr;
struct
alignas
(
16
) CameraSupplement {
CameraSupplement
();
~CameraSupplement
();
CameraSupplement
(
const
CameraSupplement
&
rhs);
CameraSupplement
&
operator
=
(
const
CameraSupplement
&
rhs);
void
clone
(
const
CameraSupplement
&
rhs);
// upper-left corner: x1, y1
Eigen::Vector2d upper_left;
// lower-right corner: x2, y2
Eigen::Vector2d lower_right;
// local track id
int
local_track_id
=
-
1
;
// 2Dto3D, pts8.resize(16), x, y...
std::vector
<
float
>
pts8;
// front box upper-left corner: x1, y1
Eigen::Vector2d front_upper_left;
// front box lower-right corner: x2, y2
Eigen::Vector2d front_lower_right;
// front box upper-left corner: x1, y1
Eigen::Vector2d back_upper_left;
// front box lower-right corner: x2, y2
Eigen::Vector2d back_lower_right;
std::vector
<
float
>
object_feature;
// this is `alpha` angle from KITTI: Observation angle of object,
// ranging [-pi..pi]
double
alpha
=
0.0
;
};
typedef
std::shared_ptr
<
CameraSupplement
>
CameraSupplementPtr;
typedef
std::shared_ptr
<
const
CameraSupplement
>
CameraSupplementConstPtr;
struct
alignas
(
16
) VehicleStatus {
float
yaw_rate;
float
velocity;
float
time_t
;
// time stamp
float
time_d;
// time stamp difference in image
Eigen::Matrix3f motion;
// Motion Matrix
};
typedef
boost::circular_buffer
<
VehicleStatus
>
MotionBuffer;
typedef
std::shared_ptr
<
MotionBuffer
>
MotionBufferPtr;
typedef
std::shared_ptr
<
const
MotionBuffer
>
MotionBufferConstPtr;
struct
alignas
(
16
) Vehicle3DStatus {
//车辆的3D实时状态
float
yaw_delta;
// azimuth angle change
float
pitch_delta;
float
roll_delta;
float
velocity_x;
// east
float
velocity_y;
// north
float
velocity_z;
// up
float
time_t
;
// time stamp
float
time_d;
// time stamp difference in image
Eigen::Matrix4f motion3d;
// 3-d Motion Matrix
};
typedef
boost::circular_buffer
<
Vehicle3DStatus
>
Motion3DBuffer;
typedef
std::shared_ptr
<
Motion3DBuffer
>
Motion3DBufferPtr;
typedef
std::shared_ptr
<
const
Motion3DBuffer
>
Motion3DBufferConstPtr;
}
// namespace perception
}
// namespace apollo
#endif
// MODULES_PERCEPTION_OBSTACLE_BASE_OBJECT_SUPPLEMENT_H_