34 auto can_factory = CanClientFactory::Instance();
35 can_factory->RegisterCanClients();
38 AERROR <<
"Failed to create can client.";
41 AINFO <<
"Can client is successfully created.";
43 message_manager_ = this->CreateMessageManager();
44 if (message_manager_ ==
nullptr) {
45 AERROR <<
"Failed to create message manager.";
48 AINFO <<
"Message manager is successfully created.";
50 if (can_receiver_.Init(can_client_.get(), message_manager_.get(),
52 AERROR <<
"Failed to init can receiver.";
55 AINFO <<
"The can receiver is successfully initialized.";
57 if (can_sender_.Init(can_client_.get(), message_manager_.get(),
59 AERROR <<
"Failed to init can sender.";
62 AINFO <<
"The can sender is successfully initialized.";
64 vehicle_controller_ = CreateVehicleController();
65 if (vehicle_controller_ ==
nullptr) {
66 AERROR <<
"Failed to create vehicle controller.";
69 AINFO <<
"The vehicle controller is successfully created.";
72 message_manager_.get()) != ErrorCode::OK) {
73 AERROR <<
"Failed to init vehicle controller.";
77 AINFO <<
"The vehicle controller is successfully"
78 <<
" initialized with canbus conf as : "
83 chassis_detail_writer_ =
87 FLAGS_chassis_detail_sender_topic);
94 if (can_client_->Start() != ErrorCode::OK) {
95 AERROR <<
"Failed to start can client";
98 AINFO <<
"Can client is started.";
101 if (can_receiver_.Start() != ErrorCode::OK) {
102 AERROR <<
"Failed to start can receiver.";
105 AINFO <<
"Can receiver is started.";
108 if (can_sender_.Start() != ErrorCode::OK) {
109 AERROR <<
"Failed to start can sender.";
114 if (!vehicle_controller_->Start()) {
115 AERROR <<
"Failed to start vehicle controller.";
124 can_receiver_.Stop();
126 vehicle_controller_->Stop();
127 AINFO <<
"Cleanup cansender, canreceiver, canclient, vehicle controller.";
132 if (vehicle_controller_->Update(*control_command) != ErrorCode::OK) {
133 AERROR <<
"Failed to process callback function OnControlCommand because "
134 "vehicle_controller_->Update error.";
137 can_sender_.Update();
142 if (vehicle_controller_->Update(*chassis_command) != ErrorCode::OK) {
143 AERROR <<
"Failed to process callback function OnControlCommand because "
144 "vehicle_controller_->Update error.";
147 can_sender_.Update();
151 Chassis chassis = vehicle_controller_->chassis();
152 ADEBUG << chassis.ShortDebugString();
157 Devkit chassis_detail = vehicle_controller_->GetNewRecvChassisDetail();
158 ADEBUG <<
"latest chassis_detail is " << chassis_detail.ShortDebugString();
159 chassis_detail_writer_->Write(chassis_detail);
163 Devkit sender_chassis_detail =
164 vehicle_controller_->GetNewSenderChassisDetail();
165 ADEBUG <<
"latest sender_chassis_detail is "
166 << sender_chassis_detail.ShortDebugString();
167 chassis_detail_sender_writer_->Write(sender_chassis_detail);
173 if (vehicle_controller_->CheckChassisCommunicationError()) {
180 vehicle_controller_->AddSendMessage();
186 if (can_sender_.IsMessageClear()) {
193 return vehicle_controller_->driving_mode();
196std::unique_ptr<VehicleController<::apollo::canbus::Devkit>>
197DevkitVehicleFactory::CreateVehicleController() {
198 return std::unique_ptr<VehicleController<::apollo::canbus::Devkit>>(
202std::unique_ptr<MessageManager<::apollo::canbus::Devkit>>
203DevkitVehicleFactory::CreateMessageManager() {
204 return std::unique_ptr<MessageManager<::apollo::canbus::Devkit>>(
205 new devkit::DevkitMessageManager());
Defines the CanClientFactory class.
bool Start() override
start canclient, cansender, canreceiver, vehicle controller
void ClearSendProtocol() override
clear the can sender messages
void AddSendProtocol() override
add the can sender messages
Chassis::DrivingMode Driving_Mode() override
get the latest chassis driving mode
void PublishChassisDetail() override
publish chassis for vehicle messages
bool Init(const CanbusConf *canbus_conf) override
init vehicle factory
bool IsSendProtocolClear() override
check the sender message clear or not
void Stop() override
create ch vehicle controller
void UpdateHeartbeat() override
create cansender heartbeat
void UpdateCommand(const apollo::control::ControlCommand *control_command) override
update control command
bool CheckChassisCommunicationFault() override
check chassis can receiver lost
Chassis publish_chassis() override
publish chassis messages
void PublishChassisDetailSender() override
publish chassis for apollo sender messages
CanClientFactory inherites apollo::common::util::Factory.
std::unique_ptr< Node > CreateNode(const std::string &node_name, const std::string &name_space)
optional apollo::drivers::canbus::CANCardParameter can_card_parameter
optional bool enable_receiver_log
optional bool enable_sender_log
optional VehicleParameter vehicle_parameter