Apollo学习笔记(9)纵向控制代码详读

之前的大致说了一下纵向控制的原理,实际的代码中还有很多小细节需要注意的地方,这里就主要记录下来,阅读纵向控制代码中的一些体会。
这里就直接在代码中加入一些笔记,这样比较好理解。

Status LonController::ComputeControlCommand(
    const localization::LocalizationEstimate *localization,
    const canbus::Chassis *chassis,
    const planning::ADCTrajectory *planning_published_trajectory,
    control::ControlCommand *cmd) 
{
   
	localization_ = localization;
	chassis_ = chassis;	
	trajectory_message_ = planning_published_trajectory;
	// vrf表示车辆参考坐标系,右前上为正,会根据下面不同的情况获取车辆目前的速度,右为x轴,前为y轴,上为z轴
	if(FLAGS_use_localization_vrf_linear_velocity && localization_->pose().has_linear_velocity_vrf())
	{
   
		linear_velocity_ = std::max(0.0,localization_->pose().linear_velocity_vrf().y());
	}
	else
	{
   
		linear_velocity_ = VehicleStateProvider::Instance()->linear_velocity();
	}
	// 对获取到的车速 MeanFilter
	if(FLAGS_enable_longitudinal_speed_filter)
	{
   
		linear_velocity_ = speed_filter_.Update(linear_velocity_);
	}
	// control_interpolation_ 在类初始化时载入参数表中完成插值,主要是对车辆在不同速度下,油门或者刹车的开度值
	// 所对应的车身加速度,纵向控制归根到底还是加速度的控制
	if (!control_interpolation_) 
	{
   
		AERROR << "Fail to initialize calibration table.";
		return Status(ErrorCode::CONTROL_COMPUTE_ERROR, "Fail to initialize calibration table.");		      
	}
	
	if (trajectory_analyzer_ == nullptr || trajectory_analyzer_->seq_num() != trajectory_message_->header().sequence_num()) 
	{
   
		trajectory_analyzer_.reset(new TrajectoryAnalyzer(trajectory_message_));
	}
 // 获取纵向参数配置
	const LonControllerConf &lon_controller_conf = control_conf_->lon_controller_conf();
		
	auto debug = cmd->mutable_debug()->mutable_simple_lon_debug();
	debug->Clear();
	
	double brake_cmd = 0.0;
	double throttle_cmd = 0.0;
	double ts = lon_controller_conf.ts();
	double preview_time = lon_controller_conf.preview_window() * ts;    // 预瞄时间
	bool enable_leadlag = lon_controller_conf.enable_reverse_leadlag_compensation();
		
	if (preview_time < 0.0) 
	{
   
		const auto error_msg = absl::StrCat("Preview time set as: ", preview_time, " less than 0");
		
		AERROR << error_msg;
		return Status(ErrorCode::CONTROL_COMPUTE_ERROR, error_msg);
	}
	// 计算纵向误差,这个函数在后面会有补充说明
	ComputeLongitudinalErrors(trajectory_analyzer_.get(), preview_time, ts, debug);
	                
	// 对纵向误差进行限幅,防止出现纵向不停加减速情况
	double station_error_limit = lon_controller_conf.station_error_limit();
	double station_error_limited = 0.0;
	if (FLAGS_enable_speed_station_preview) 
	{
   
		station_error_limited =
			common::math::Clamp(debug->preview_station_error(), -station_error_limit, station_error_limit);		                
	} 
	else 
	{
   
		station_error_limited = common::math::Clamp(debug->station_error(), -station_error_limit, station_error_limit);	
	}
	
	// R 档,D档使用不同的PID参数
	if (trajectory_message_->gear() == canbus::Chassis::GEAR_REVERSE) 
	{
   
		station_pid_controller_.SetPID(lon_controller_conf.reverse_station_pid_conf());	
		speed_pid_controller_.SetPID(lon_controller_conf.reverse_speed_pid_conf());
		
		if (enable_leadlag) 
		{
   
			station_leadlag_controller_.SetLeadlag(lon_controller_conf.reverse_station_leadlag_conf());			
			speed_leadlag_controller_.SetLeadlag(lon_controller_conf.reverse_speed_leadlag_conf());			
		}
	} 
	// 这里只有两组PID参数,在不同速度时,纵向控制精度无法保证,后续需要改进
	else if (linear_velocity_ <= lon_controller_conf.switch_speed()) 
	{
   
		speed_pid_controller_.SetPID(lon_controller_conf.low_speed_pid_conf());
	} 
	else 
	{
   
		speed_pid_controller_
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Apollo控制代码学习可以通过研究Apollo项目中的Control模块来进行。Control模块是Apollo项目中的一个重要组成部分,它提供了纵向控制、横向控制和MPC控制三种控制方法。在学习Apollo控制代码之前,了解整体的项目结构以及控制模块的相关概念是很有帮助的。 为了更好地理解Apollo的控制逻辑,一本名为《Vehicle Dynamics and Control》的书籍是非常推荐的。这本书对Apollo控制代码提供了很好的参考,因此在研究代码之前,建议先准备好这本书并结合它来理解Control模块的相关代码,这样可以事半功倍。此外,对Frenet坐标系也需要有一定的了解,可以参考一篇名为《Optimal trajectory generation for dynamic street scenarios in a Frenét Frame》的文章进行学习。 在学习Apollo控制代码时,还可以参考一些个人对Apollo6.0的代码进行记录的笔记。这些笔记是个人的思考和理解,可以作为学习和探讨的参考。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Apollo代码学习(一)—控制模块概述](https://blog.csdn.net/u013914471/article/details/82775091)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Apollo规划控制学习笔记](https://blog.csdn.net/qq_42027654/article/details/126453968)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值