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

#include <gem_controller.h>

类 apollo::canbus::gem::GemController 继承关系图:
apollo::canbus::gem::GemController 的协作图:

Public 成员函数

 GemController ()
 
virtual ~GemController ()
 
::apollo::common::ErrorCode Init (const VehicleParameter &params, CanSender<::apollo::canbus::Gem > *const can_sender, MessageManager<::apollo::canbus::Gem > *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 (GemControllerTest, SetDrivingMode)
 
 FRIEND_TEST (GemControllerTest, Status)
 
 FRIEND_TEST (GemControllerTest, UpdateDrivingMode)
 
- Public 成员函数 继承自 apollo::canbus::VehicleController<::apollo::canbus::Gem >
virtual ~VehicleController ()=default
 
virtual common::ErrorCode Init (const VehicleParameter &params, CanSender< ::apollo::canbus::Gem > *const can_sender, MessageManager< ::apollo::canbus::Gem > *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::Gem GetNewRecvChassisDetail ()
 
virtual ::apollo::canbus::Gem GetNewSenderChassisDetail ()
 
virtual Chassis::DrivingMode driving_mode ()
 

额外继承的成员函数

- Protected 成员函数 继承自 apollo::canbus::VehicleController<::apollo::canbus::Gem >
virtual void set_driving_mode (const Chassis::DrivingMode &driving_mode)
 
- Protected 属性 继承自 apollo::canbus::VehicleController<::apollo::canbus::Gem >
common::VehicleSignal last_chassis_command_
 
common::VehicleSignal last_control_command_
 
canbus::VehicleParameter params_
 
common::VehicleParam vehicle_params_
 
CanSender< ::apollo::canbus::Gem > * can_sender_
 
CanReceiver< ::apollo::canbus::Gem > * can_receiver_
 
MessageManager< ::apollo::canbus::Gem > * 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_
 

详细描述

在文件 gem_controller.h41 行定义.

构造及析构函数说明

◆ GemController()

apollo::canbus::gem::GemController::GemController ( )
inline

在文件 gem_controller.h43 行定义.

43{}

◆ ~GemController()

apollo::canbus::gem::GemController::~GemController ( )
virtual

在文件 gem_controller.cc131 行定义.

131{}

成员函数说明

◆ chassis()

Chassis apollo::canbus::gem::GemController::chassis ( )
overridevirtual

calculate and return the chassis.

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

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

在文件 gem_controller.cc157 行定义.

157 {
158 chassis_.Clear();
159
160 Gem chassis_detail;
161 message_manager_->GetSensorData(&chassis_detail);
162
163 // 21, 22, previously 1, 2
165 set_chassis_error_code(Chassis::NO_ERROR);
166 }
167
168 chassis_.set_driving_mode(driving_mode());
169 chassis_.set_error_code(chassis_error_code());
170
171 // 3
172 chassis_.set_engine_started(true);
173
174 // 5
175 if (chassis_detail.has_vehicle_speed_rpt_6f() &&
176 chassis_detail.vehicle_speed_rpt_6f().has_vehicle_speed()) {
177 chassis_.set_speed_mps(static_cast<float>(
178 chassis_detail.vehicle_speed_rpt_6f().vehicle_speed()));
179 } else {
180 chassis_.set_speed_mps(0);
181 }
182
183 // 7
184 chassis_.set_fuel_range_m(0);
185 // 8
186 if (chassis_detail.has_accel_rpt_68() &&
187 chassis_detail.accel_rpt_68().has_output_value()) {
188 chassis_.set_throttle_percentage(
189 static_cast<float>(chassis_detail.accel_rpt_68().output_value()));
190 } else {
191 chassis_.set_throttle_percentage(0);
192 }
193 // 9
194 if (chassis_detail.has_brake_rpt_6c() &&
195 chassis_detail.brake_rpt_6c().has_output_value()) {
196 chassis_.set_brake_percentage(
197 static_cast<float>(chassis_detail.brake_rpt_6c().output_value()));
198 } else {
199 chassis_.set_brake_percentage(0);
200 }
201
202 // 23, previously 10
203 if (chassis_detail.has_shift_rpt_66() &&
204 chassis_detail.shift_rpt_66().has_output_value()) {
206
207 if (chassis_detail.shift_rpt_66().output_value() ==
209 gear_pos = Chassis::GEAR_NEUTRAL;
210 }
211 if (chassis_detail.shift_rpt_66().output_value() ==
213 gear_pos = Chassis::GEAR_REVERSE;
214 }
215 if (chassis_detail.shift_rpt_66().output_value() ==
217 gear_pos = Chassis::GEAR_DRIVE;
218 }
219
220 chassis_.set_gear_location(gear_pos);
221 } else {
222 chassis_.set_gear_location(Chassis::GEAR_NONE);
223 }
224
225 // 11
226 // TODO(QiL) : verify the unit here.
227 if (chassis_detail.has_steering_rpt_1_6e() &&
228 chassis_detail.steering_rpt_1_6e().has_output_value()) {
229 chassis_.set_steering_percentage(
230 static_cast<float>(chassis_detail.steering_rpt_1_6e().output_value() *
232 } else {
233 chassis_.set_steering_percentage(0);
234 }
235
236 if (chassis_detail.has_global_rpt_6a() &&
237 chassis_detail.global_rpt_6a().has_pacmod_status()) {
238 if (chassis_detail.global_rpt_6a().pacmod_status() ==
240 chassis_.set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE);
241 global_cmd_69_->set_clear_override(
243 } else {
244 chassis_.set_driving_mode(Chassis::COMPLETE_MANUAL);
245 }
246 } else {
247 chassis_.set_driving_mode(Chassis::COMPLETE_MANUAL);
248 }
249
250 // TODO(QiL) : implement the turn light signal here
251
252 // 16, 17
253 if (chassis_detail.has_light() &&
254 chassis_detail.light().has_turn_light_type() &&
255 chassis_detail.light().turn_light_type() != Light::TURN_LIGHT_OFF) {
256 if (chassis_detail.light().turn_light_type() == Light::TURN_LEFT_ON) {
257 chassis_.mutable_signal()->set_turn_signal(
259 } else if (chassis_detail.light().turn_light_type() ==
261 chassis_.mutable_signal()->set_turn_signal(
263 } else {
264 chassis_.mutable_signal()->set_turn_signal(
266 }
267 } else {
268 chassis_.mutable_signal()->set_turn_signal(
270 }
271
272 // TODO(all): implement the rest here/
273 // 26
274 if (chassis_error_mask_) {
275 chassis_.set_chassis_error_mask(chassis_error_mask_);
276 }
277
278 // Give engage_advice based on error_code and canbus feedback
279 if (!chassis_error_mask_ && !chassis_.parking_brake() &&
280 chassis_.throttle_percentage() == 0.0 &&
281 chassis_.brake_percentage() != 0.0) {
282 chassis_.mutable_engage_advice()->set_advice(
284 } else {
285 chassis_.mutable_engage_advice()->set_advice(
287 chassis_.mutable_engage_advice()->set_reason(
288 "CANBUS not ready, firmware error or emergency button pressed!");
289 }
290
291 return chassis_;
292}
MessageManager< ::apollo::canbus::Gem > * message_manager_
Globalcmd69 * set_clear_override(Global_cmd_69::Clear_overrideType clear_override)
optional float brake_percentage
Definition chassis.proto:82
optional bool parking_brake
Definition chassis.proto:94
optional float throttle_percentage
Definition chassis.proto:79

◆ FRIEND_TEST() [1/3]

apollo::canbus::gem::GemController::FRIEND_TEST ( GemControllerTest  ,
SetDrivingMode   
)

◆ FRIEND_TEST() [2/3]

apollo::canbus::gem::GemController::FRIEND_TEST ( GemControllerTest  ,
Status   
)

◆ FRIEND_TEST() [3/3]

apollo::canbus::gem::GemController::FRIEND_TEST ( GemControllerTest  ,
UpdateDrivingMode   
)

◆ Init()

ErrorCode apollo::canbus::gem::GemController::Init ( const VehicleParameter params,
CanSender<::apollo::canbus::Gem > *const  can_sender,
MessageManager<::apollo::canbus::Gem > *const  message_manager 
)
override

在文件 gem_controller.cc48 行定义.

51 {
52 if (is_initialized_) {
53 AINFO << "GemController has already been initialized.";
54 return ErrorCode::CANBUS_ERROR;
55 }
56 vehicle_params_.CopyFrom(
57 common::VehicleConfigHelper::Instance()->GetConfig().vehicle_param());
58 params_.CopyFrom(params);
59 if (!params_.has_driving_mode()) {
60 AERROR << "Vehicle conf pb not set driving_mode.";
61 return ErrorCode::CANBUS_ERROR;
62 }
63
64 if (can_sender == nullptr) {
65 AERROR << "Canbus sender is null.";
66 return ErrorCode::CANBUS_ERROR;
67 }
68 can_sender_ = can_sender;
69
70 if (message_manager == nullptr) {
71 AERROR << "Protocol manager is null.";
72 return ErrorCode::CANBUS_ERROR;
73 }
74 message_manager_ = message_manager;
75
76 // Sender part
77 brake_cmd_6b_ = dynamic_cast<Brakecmd6b*>(
78 message_manager_->GetMutableProtocolDataById(Brakecmd6b::ID));
79 if (brake_cmd_6b_ == nullptr) {
80 AERROR << "Brakecmd6b does not exist in the GemMessageManager!";
81 return ErrorCode::CANBUS_ERROR;
82 }
83
84 accel_cmd_67_ = dynamic_cast<Accelcmd67*>(
85 message_manager_->GetMutableProtocolDataById(Accelcmd67::ID));
86 if (accel_cmd_67_ == nullptr) {
87 AERROR << "Accelcmd67 does not exist in the GemMessageManager!";
88 return ErrorCode::CANBUS_ERROR;
89 }
90
91 steering_cmd_6d_ = dynamic_cast<Steeringcmd6d*>(
92 message_manager_->GetMutableProtocolDataById(Steeringcmd6d::ID));
93 if (steering_cmd_6d_ == nullptr) {
94 AERROR << "Steeringcmd6d does not exist in the GemMessageManager!";
95 return ErrorCode::CANBUS_ERROR;
96 }
97
98 shift_cmd_65_ = dynamic_cast<Shiftcmd65*>(
99 message_manager_->GetMutableProtocolDataById(Shiftcmd65::ID));
100 if (shift_cmd_65_ == nullptr) {
101 AERROR << "Shiftcmd65 does not exist in the GemMessageManager!";
102 return ErrorCode::CANBUS_ERROR;
103 }
104 turn_cmd_63_ = dynamic_cast<Turncmd63*>(
105 message_manager_->GetMutableProtocolDataById(Turncmd63::ID));
106 if (turn_cmd_63_ == nullptr) {
107 AERROR << "Turncmd63 does not exist in the GemMessageManager!";
108 return ErrorCode::CANBUS_ERROR;
109 }
110 global_cmd_69_ = dynamic_cast<Globalcmd69*>(
111 message_manager_->GetMutableProtocolDataById(Globalcmd69::ID));
112 if (global_cmd_69_ == nullptr) {
113 AERROR << "Turncmd63 does not exist in the GemMessageManager!";
114 return ErrorCode::CANBUS_ERROR;
115 }
116
117 can_sender_->AddMessage(Brakecmd6b::ID, brake_cmd_6b_, false);
118 can_sender_->AddMessage(Accelcmd67::ID, accel_cmd_67_, false);
119 can_sender_->AddMessage(Steeringcmd6d::ID, steering_cmd_6d_, false);
120 can_sender_->AddMessage(Shiftcmd65::ID, shift_cmd_65_, false);
121 can_sender_->AddMessage(Turncmd63::ID, turn_cmd_63_, false);
122 can_sender_->AddMessage(Globalcmd69::ID, global_cmd_69_, false);
123
124 // Need to sleep to ensure all messages received.
125 AINFO << "GemController is initialized.";
126
127 is_initialized_ = true;
128 return ErrorCode::OK;
129}
static const int32_t ID
Definition turn_cmd_63.h:29
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42

◆ Start()

bool apollo::canbus::gem::GemController::Start ( )
overridevirtual

start the vehicle controller.

返回
true if successfully started.

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

在文件 gem_controller.cc133 行定义.

133 {
134 if (!is_initialized_) {
135 AERROR << "GemController has NOT been initiated.";
136 return false;
137 }
138 const auto& update_func = [this] { SecurityDogThreadFunc(); };
139 thread_.reset(new std::thread(update_func));
140
141 return true;
142}

◆ Stop()

void apollo::canbus::gem::GemController::Stop ( )
overridevirtual

stop the vehicle controller.

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

在文件 gem_controller.cc144 行定义.

144 {
145 if (!is_initialized_) {
146 AERROR << "GemController stops or starts improperly!";
147 return;
148 }
149
150 if (thread_ != nullptr && thread_->joinable()) {
151 thread_->join();
152 thread_.reset();
153 AINFO << "GemController stopped.";
154 }
155}

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