/****************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,具体请见本博客中各模块的分析代码。
/****************************************************************************************
对于Apollo 2.0自动驾驶系统,如何在系统中添加一个GPS接收器来增加控制精度,请看如下参考:
#如何添加新的GPS接收器
GPS接收器是一种从GPS卫星接收信息,然后计算设备的地理位置,速度和精确时间的设备。该设备通常包括一个接收器,一个IMU,一个车轮编码器的接口,以及融合来自这些传感器信息的融合引擎。阿波罗使用的默认GPS接收器是Novatel卡。该指令演示如何使用新的GPS接收器。
##添加新的GPS接收器的步骤
请按照以下步骤添加新的GPS接收器。
*通过继承“Parser”类实现新的GPS接收器的新数据解析器
*在新的GPS接收器的“Parser”类中添加新接口
*在config.proto中,为新的GPS接收器添加新的数据格式
*从文件data_parser.cpp的函数`create_parser`中,为新的GPS接收器添加新的解析器实例
假设我们想添加一个新的GPS接收器:`u-blox`。
步骤1:通过继承Parser类实现新的GPS接收器的新数据解析器
```cpp
class UbloxParser : public Parser {
public:
UbloxParser();
virtual MessageType get_message(MessagePtr& message_ptr);
private:
bool verify_checksum();
Parser::MessageType prepare_message(MessagePtr& message_ptr);
// The handle_xxx functions return whether a message is ready.
bool handle_esf_raw(const ublox::EsfRaw* raw, size_t data_size);
bool handle_esf_ins(const ublox::EsfIns* ins);
bool handle_hnr_pvt(const ublox::HnrPvt* pvt);
bool handle_nav_att(const ublox::NavAtt *att);
bool handle_nav_pvt(const ublox::NavPvt* pvt);
bool handle_nav_cov(const ublox::NavCov *cov);
bool handle_rxm_rawx(const ublox::RxmRawx *raw);
double _gps_seconds_base = -1.0;
double _gyro_scale = 0.0;
double _accel_scale = 0.0;
float _imu_measurement_span = 0.0;
int _imu_frame_mapping = 5;
double _imu_measurement_time_previous = -1.0;
std::vector<uint8_t> _buffer;
size_t _total_length = 0;
::apollo::drivers::gnss::Gnss _gnss;
::apollo::drivers::gnss::Imu _imu;
::apollo::drivers::gnss::Ins _ins;
};
```
###第2步:在新的GPS接收器中为Parser类添加新的接口
Add the function `create_ublox` in `Parser` class:
```cpp
class Parser {
public:
// Return a pointer to a NovAtel parser. The caller should take ownership.
static Parser* create_novatel();
// Return a pointer to a u-blox parser. The caller should take ownership.
static Parser* create_ublox();
virtual ~Parser() {}
// Updates the parser with new data. The caller must keep the data valid until get_message()
// returns NONE.
void update(const uint8_t* data, size_t length) {
_data = data;
_data_end = data + length;
}
void update(const std::string& data) {
update(reinterpret_cast<const uint8_t*>(data.data()), data.size());
}
enum class MessageType {
NONE,
GNSS,
GNSS_RANGE,
IMU,
INS,
WHEEL,
EPHEMERIDES,
OBSERVATION,
GPGGA,
};
// Gets a parsed protobuf message. The caller must consume the message before calling another
// get_message() or update();
virtual MessageType get_message(MessagePtr& message_ptr) = 0;
protected:
Parser() {}
// Point to the beginning and end of data. Do not take ownership.
const uint8_t* _data = nullptr;
const uint8_t* _data_end = nullptr;
private:
DISABLE_COPY_AND_ASSIGN(Parser);
};
Parser* Parser::create_ublox() {
return new UbloxParser();
}
```
### Step 3: in config.proto, add the new data format definition for the new GPS receiver
Add `UBLOX_TEXT` and `UBLOX_BINARY` in the config file: modules/drivers/gnss/proto/config.proto
```txt
message Stream {
enum Format {
UNKNOWN = 0;
NMEA = 1;
RTCM_V2 = 2;
RTCM_V3 = 3;
NOVATEL_TEXT = 10;
NOVATEL_BINARY = 11;
UBLOX_TEXT = 20;
UBLOX_BINARY = 21;
}
... ...
```
### Step 4: in function `create_parser` from file data_parser.cpp, add new parser instance for new GPS receiver
Add code to process config::Stream::UBLOX_BINARY as below:
``` cpp
Parser* create_parser(config::Stream::Format format, bool is_base_station = false) {
switch (format) {
case config::Stream::NOVATEL_BINARY:
return Parser::create_novatel();
case config::Stream::UBLOX_BINARY:
return Parser::create_ubloxl();
default:
return nullptr;
}
}
```
备注:上述解释代码中存在一些中文字符,请参照原版代码来理解,如果有什么问题,欢迎留言讨论。
/home/zy/zouyu/deeping/apollo/docs/howto/how_to_add_a_gps_receiver.md