Apollo 10.0
自动驾驶开放平台
apollo::canbus::lexus::LexusController类 参考final

#include <lexus_controller.h>

类 apollo::canbus::lexus::LexusController 继承关系图:
apollo::canbus::lexus::LexusController 的协作图:

Public 成员函数

virtual ~LexusController ()
 
::apollo::common::ErrorCode Init (const VehicleParameter &params, CanSender<::apollo::canbus::Lexus > *const can_sender, MessageManager<::apollo::canbus::Lexus > *const message_manager) override
 
bool Start () override
 start the vehicle controller.
 
void Stop () override
 stop the vehicle controller.
 
Chassis chassis () override
 calculate and return the chassis.
 
 FRIEND_TEST (LexusControllerTest, SetDrivingMode)
 
 FRIEND_TEST (LexusControllerTest, Status)
 
 FRIEND_TEST (LexusControllerTest, UpdateDrivingMode)
 
- Public 成员函数 继承自 apollo::canbus::VehicleController<::apollo::canbus::Lexus >
virtual ~VehicleController ()=default
 
virtual common::ErrorCode Init (const VehicleParameter &params, CanSender< ::apollo::canbus::Lexus > *const can_sender, MessageManager< ::apollo::canbus::Lexus > *const message_manager)=0
 initialize the vehicle controller.
 
virtual common::ErrorCode Update (const control::ControlCommand &command)
 update the vehicle controller.
 
virtual common::ErrorCode Update (const external_command::ChassisCommand &command)
 
virtual common::ErrorCode SetDrivingMode (const Chassis::DrivingMode &driving_mode)
 set vehicle to appointed driving mode.
 
virtual bool CheckChassisCommunicationError ()
 
virtual void AddSendMessage ()
 
virtual ::apollo::canbus::Lexus GetNewRecvChassisDetail ()
 
virtual ::apollo::canbus::Lexus GetNewSenderChassisDetail ()
 
virtual Chassis::DrivingMode driving_mode ()
 

额外继承的成员函数

- Protected 成员函数 继承自 apollo::canbus::VehicleController<::apollo::canbus::Lexus >
virtual void set_driving_mode (const Chassis::DrivingMode &driving_mode)
 
- Protected 属性 继承自 apollo::canbus::VehicleController<::apollo::canbus::Lexus >
common::VehicleSignal last_chassis_command_
 
common::VehicleSignal last_control_command_
 
canbus::VehicleParameter params_
 
common::VehicleParam vehicle_params_
 
CanSender< ::apollo::canbus::Lexus > * can_sender_
 
CanReceiver< ::apollo::canbus::Lexus > * can_receiver_
 
MessageManager< ::apollo::canbus::Lexus > * message_manager_
 
bool is_initialized_
 
Chassis::DrivingMode driving_mode_
 
bool is_reset_
 
std::mutex mode_mutex_
 
uint32_t lost_chassis_reveive_detail_count_
 
bool is_need_count_
 
size_t sender_data_size_previous_
 
int64_t start_time_
 
bool is_chassis_communication_error_
 

详细描述

在文件 lexus_controller.h47 行定义.

构造及析构函数说明

◆ ~LexusController()

apollo::canbus::lexus::LexusController::~LexusController ( )
virtual

在文件 lexus_controller.cc121 行定义.

121{}

成员函数说明

◆ chassis()

Chassis apollo::canbus::lexus::LexusController::chassis ( )
overridevirtual

calculate and return the chassis.

返回
a copy of chassis. Use copy here to avoid multi-thread issues.

实现了 apollo::canbus::VehicleController<::apollo::canbus::Lexus >.

在文件 lexus_controller.cc147 行定义.

147 {
148 chassis_.Clear();
149
150 Lexus chassis_detail;
151 message_manager_->GetSensorData(&chassis_detail);
152
153 // 21, 22, previously 1, 2
155 set_chassis_error_code(Chassis::NO_ERROR);
156 }
157
158 chassis_.set_driving_mode(driving_mode());
159 chassis_.set_error_code(chassis_error_code());
160
161 // 3
162 chassis_.set_engine_started(true);
163
164 // 5
165 if (chassis_detail.has_vehicle_speed_rpt_400() &&
166 chassis_detail.vehicle_speed_rpt_400().has_vehicle_speed()) {
167 chassis_.set_speed_mps(static_cast<float>(
168 chassis_detail.vehicle_speed_rpt_400().vehicle_speed()));
169 } else {
170 chassis_.set_speed_mps(0);
171 }
172
173 if (chassis_detail.has_wheel_speed_rpt_407()) {
174 // TODO(QiL) : No wheel speed valid bit in lexus, so default valid
175 chassis_.mutable_wheel_speed()->set_is_wheel_spd_rr_valid(true);
176 // chassis_.mutable_wheel_speed()->set_wheel_direction_rr(true);
177 chassis_.mutable_wheel_speed()->set_wheel_spd_rr(
178 chassis_detail.wheel_speed_rpt_407().wheel_spd_rear_right());
179
180 chassis_.mutable_wheel_speed()->set_is_wheel_spd_rl_valid(true);
181 /*
182 chassis_.mutable_wheel_speed()->set_wheel_direction_rl(
183 chassis_detail.vehicle_spd().wheel_direction_rl());
184 */
185 chassis_.mutable_wheel_speed()->set_wheel_spd_rl(
186 chassis_detail.wheel_speed_rpt_407().wheel_spd_rear_left());
187
188 chassis_.mutable_wheel_speed()->set_is_wheel_spd_fr_valid(true);
189 /*
190 chassis_.mutable_wheel_speed()->set_wheel_direction_fr(
191 chassis_detail.vehicle_spd().wheel_direction_fr());
192 */
193 chassis_.mutable_wheel_speed()->set_wheel_spd_fr(
194 chassis_detail.wheel_speed_rpt_407().wheel_spd_front_right());
195
196 chassis_.mutable_wheel_speed()->set_is_wheel_spd_fl_valid(true);
197 /*
198 chassis_.mutable_wheel_speed()->set_wheel_direction_fl(
199 chassis_detail.vehicle_spd().wheel_direction_fl());
200 */
201 chassis_.mutable_wheel_speed()->set_wheel_spd_fl(
202 chassis_detail.wheel_speed_rpt_407().wheel_spd_front_left());
203 }
204
205 // 7
206 chassis_.set_fuel_range_m(0);
207 // 8
208 if (chassis_detail.has_accel_rpt_200() &&
209 chassis_detail.accel_rpt_200().has_output_value()) {
210 // TODO(snehagn): Temp fix until AS to fix the scaling
211 chassis_.set_throttle_percentage(static_cast<float>(
212 chassis_detail.accel_rpt_200().output_value() * 100));
213 } else {
214 chassis_.set_throttle_percentage(0);
215 }
216 // 9
217 if (chassis_detail.has_brake_rpt_204() &&
218 chassis_detail.brake_rpt_204().has_output_value()) {
219 // TODO(snehagn): Temp fix until AS to fix the scaling
220 chassis_.set_brake_percentage(static_cast<float>(
221 chassis_detail.brake_rpt_204().output_value() * 100));
222 } else {
223 chassis_.set_brake_percentage(0);
224 }
225
226 // 23, previously 10
227 if (chassis_detail.has_shift_rpt_228() &&
228 chassis_detail.shift_rpt_228().has_output_value()) {
229 AINFO << "Start reading shift values";
231
232 if (chassis_detail.shift_rpt_228().output_value() ==
234 gear_pos = Chassis::GEAR_PARKING;
235 }
236
237 if (chassis_detail.shift_rpt_228().output_value() ==
239 gear_pos = Chassis::GEAR_NEUTRAL;
240 }
241 if (chassis_detail.shift_rpt_228().output_value() ==
243 gear_pos = Chassis::GEAR_REVERSE;
244 }
245 if (chassis_detail.shift_rpt_228().output_value() ==
247 gear_pos = Chassis::GEAR_DRIVE;
248 }
249
250 chassis_.set_gear_location(gear_pos);
251 } else {
252 chassis_.set_gear_location(Chassis::GEAR_NONE);
253 }
254
255 // 11
256 // TODO(QiL) : verify the unit here.
257 if (chassis_detail.has_steering_rpt_22c() &&
258 chassis_detail.steering_rpt_22c().has_output_value()) {
259 chassis_.set_steering_percentage(
260 static_cast<float>(chassis_detail.steering_rpt_22c().output_value() *
262 } else {
263 chassis_.set_steering_percentage(0);
264 }
265
266 // 16, 17
267 if (chassis_detail.has_turn_rpt_230() &&
268 chassis_detail.turn_rpt_230().has_output_value() &&
269 chassis_detail.turn_rpt_230().output_value() !=
271 if (chassis_detail.turn_rpt_230().output_value() ==
273 chassis_.mutable_signal()->set_turn_signal(
275 } else if (chassis_detail.turn_rpt_230().output_value() ==
277 chassis_.mutable_signal()->set_turn_signal(
279 } else {
280 chassis_.mutable_signal()->set_turn_signal(
282 }
283 } else {
284 chassis_.mutable_signal()->set_turn_signal(
286 }
287
288 // TODO(all): implement the rest here/
289 // 26
290 if (chassis_error_mask_) {
291 chassis_.set_chassis_error_mask(chassis_error_mask_);
292 }
293
294 // give engage_advice based on error_code and canbus feedback
295 if (!chassis_error_mask_ && !chassis_.parking_brake()) {
296 chassis_.mutable_engage_advice()->set_advice(
298 } else {
299 chassis_.mutable_engage_advice()->set_advice(
301 chassis_.mutable_engage_advice()->set_reason(
302 "CANBUS not ready, firmware error or emergency button pressed!");
303 }
304
305 return chassis_;
306}
MessageManager< ::apollo::canbus::Lexus > * message_manager_
#define AINFO
Definition log.h:42
optional bool parking_brake
Definition chassis.proto:94

◆ FRIEND_TEST() [1/3]

apollo::canbus::lexus::LexusController::FRIEND_TEST ( LexusControllerTest  ,
SetDrivingMode   
)

◆ FRIEND_TEST() [2/3]

apollo::canbus::lexus::LexusController::FRIEND_TEST ( LexusControllerTest  ,
Status   
)

◆ FRIEND_TEST() [3/3]

apollo::canbus::lexus::LexusController::FRIEND_TEST ( LexusControllerTest  ,
UpdateDrivingMode   
)

◆ Init()

ErrorCode apollo::canbus::lexus::LexusController::Init ( const VehicleParameter params,
CanSender<::apollo::canbus::Lexus > *const  can_sender,
MessageManager<::apollo::canbus::Lexus > *const  message_manager 
)
override

在文件 lexus_controller.cc44 行定义.

47 {
48 if (is_initialized_) {
49 AINFO << "LexusController has already been initiated.";
50 return ErrorCode::CANBUS_ERROR;
51 }
52 vehicle_params_.CopyFrom(
53 common::VehicleConfigHelper::Instance()->GetConfig().vehicle_param());
54 params_.CopyFrom(params);
55 if (!params_.has_driving_mode()) {
56 AERROR << "Vehicle conf pb not set driving_mode.";
57 return ErrorCode::CANBUS_ERROR;
58 }
59
60 if (can_sender == nullptr) {
61 AERROR << "Canbus sender is null.";
62 return ErrorCode::CANBUS_ERROR;
63 }
64 can_sender_ = can_sender;
65
66 if (message_manager == nullptr) {
67 AERROR << "Protocol manager is null.";
68 return ErrorCode::CANBUS_ERROR;
69 }
70 message_manager_ = message_manager;
71
72 // Sender part
73 accel_cmd_100_ = dynamic_cast<Accelcmd100*>(
74 message_manager_->GetMutableProtocolDataById(Accelcmd100::ID));
75 if (accel_cmd_100_ == nullptr) {
76 AERROR << "Accelcmd100 does not exist in the LexusMessalexusanager!";
77 return ErrorCode::CANBUS_ERROR;
78 }
79
80 brake_cmd_104_ = dynamic_cast<Brakecmd104*>(
81 message_manager_->GetMutableProtocolDataById(Brakecmd104::ID));
82 if (brake_cmd_104_ == nullptr) {
83 AERROR << "Brakecmd104 does not exist in the LexusMessalexusanager!";
84 return ErrorCode::CANBUS_ERROR;
85 }
86
87 shift_cmd_128_ = dynamic_cast<Shiftcmd128*>(
88 message_manager_->GetMutableProtocolDataById(Shiftcmd128::ID));
89 if (shift_cmd_128_ == nullptr) {
90 AERROR << "Shiftcmd128 does not exist in the LexusMessalexusanager!";
91 return ErrorCode::CANBUS_ERROR;
92 }
93
94 turn_cmd_130_ = dynamic_cast<Turncmd130*>(
95 message_manager_->GetMutableProtocolDataById(Turncmd130::ID));
96 if (turn_cmd_130_ == nullptr) {
97 AERROR << "Turncmd130 does not exist in the LexusMessageManager!";
98 return ErrorCode::CANBUS_ERROR;
99 }
100
101 steering_cmd_12c_ = dynamic_cast<Steeringcmd12c*>(
102 message_manager_->GetMutableProtocolDataById(Steeringcmd12c::ID));
103 if (steering_cmd_12c_ == nullptr) {
104 AERROR << "Steeringcmd12c does not exist in the LexusMessageManager!";
105 return ErrorCode::CANBUS_ERROR;
106 }
107
108 can_sender_->AddMessage(Accelcmd100::ID, accel_cmd_100_, false);
109 can_sender_->AddMessage(Brakecmd104::ID, brake_cmd_104_, false);
110 can_sender_->AddMessage(Shiftcmd128::ID, shift_cmd_128_, false);
111 can_sender_->AddMessage(Steeringcmd12c::ID, steering_cmd_12c_, false);
112 can_sender_->AddMessage(Turncmd130::ID, turn_cmd_130_, false);
113
114 // Need to sleep to ensure all messages were received
115 AINFO << "LexusController is initialized.";
116
117 is_initialized_ = true;
118 return ErrorCode::OK;
119}
#define AERROR
Definition log.h:44

◆ Start()

bool apollo::canbus::lexus::LexusController::Start ( )
overridevirtual

start the vehicle controller.

返回
true if successfully started.

实现了 apollo::canbus::VehicleController<::apollo::canbus::Lexus >.

在文件 lexus_controller.cc123 行定义.

123 {
124 if (!is_initialized_) {
125 AERROR << "LexusController has NOT been initiated.";
126 return false;
127 }
128 const auto& update_func = [this] { SecurityDogThreadFunc(); };
129 thread_.reset(new std::thread(update_func));
130
131 return true;
132}

◆ Stop()

void apollo::canbus::lexus::LexusController::Stop ( )
overridevirtual

stop the vehicle controller.

实现了 apollo::canbus::VehicleController<::apollo::canbus::Lexus >.

在文件 lexus_controller.cc134 行定义.

134 {
135 if (!is_initialized_) {
136 AERROR << "LexusController stops or starts improperly!";
137 return;
138 }
139
140 if (thread_ != nullptr && thread_->joinable()) {
141 thread_->join();
142 thread_.reset();
143 AINFO << "LexusController stopped.";
144 }
145}

该类的文档由以下文件生成: