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 : "
84 FLAGS_chassis_detail_topic);
86 chassis_detail_sender_writer_ =
88 FLAGS_chassis_detail_sender_topic);
95 if (can_client_->Start() != ErrorCode::OK) {
96 AERROR <<
"Failed to start can client";
99 AINFO <<
"Can client is started.";
102 if (can_receiver_.Start() != ErrorCode::OK) {
103 AERROR <<
"Failed to start can receiver.";
106 AINFO <<
"Can receiver is started.";
109 if (can_sender_.Start() != ErrorCode::OK) {
110 AERROR <<
"Failed to start can sender.";
115 if (!vehicle_controller_->Start()) {
116 AERROR <<
"Failed to start vehicle controller.";
125 can_receiver_.Stop();
127 vehicle_controller_->Stop();
128 AINFO <<
"Cleanup cansender, canreceiver, canclient, vehicle controller.";
133 if (vehicle_controller_->Update(*control_command) != ErrorCode::OK) {
134 AERROR <<
"Failed to process callback function OnControlCommand because "
135 "vehicle_controller_->Update error.";
138 can_sender_.Update();
143 if (vehicle_controller_->Update(*chassis_command) != ErrorCode::OK) {
144 AERROR <<
"Failed to process callback function OnControlCommand because "
145 "vehicle_controller_->Update error.";
148 can_sender_.Update();
152 Chassis chassis = vehicle_controller_->chassis();
153 ADEBUG << chassis.ShortDebugString();
158 Neolix_edu chassis_detail = vehicle_controller_->GetNewRecvChassisDetail();
159 ADEBUG <<
"latest chassis_detail is " << chassis_detail.ShortDebugString();
160 chassis_detail_writer_->Write(chassis_detail);
165 vehicle_controller_->GetNewSenderChassisDetail();
166 ADEBUG <<
"latest sender_chassis_detail is "
167 << sender_chassis_detail.ShortDebugString();
168 chassis_detail_sender_writer_->Write(sender_chassis_detail);
172 can_sender_.Update_Heartbeat();
176 if (vehicle_controller_->CheckChassisCommunicationError()) {
183 vehicle_controller_->AddSendMessage();
187 can_sender_.ClearMessage();
191 if (can_sender_.IsMessageClear()) {
198 return vehicle_controller_->driving_mode();
201std::unique_ptr<VehicleController<::apollo::canbus::Neolix_edu>>
202Neolix_eduVehicleFactory::CreateVehicleController() {
203 return std::unique_ptr<VehicleController<::apollo::canbus::Neolix_edu>>(
207std::unique_ptr<MessageManager<::apollo::canbus::Neolix_edu>>
208Neolix_eduVehicleFactory::CreateMessageManager() {
209 return std::unique_ptr<MessageManager<::apollo::canbus::Neolix_edu>>(
210 new neolix_edu::Neolix_eduMessageManager());
Defines the CanClientFactory class.
void UpdateHeartbeat() override
create cansender heartbeat
void AddSendProtocol() override
add the can sender messages
void ClearSendProtocol() override
clear the can sender messages
void Stop() override
create ch vehicle controller
bool IsSendProtocolClear() override
check the sender message clear or not
bool Init(const CanbusConf *canbus_conf) override
init vehicle factory
void UpdateCommand(const apollo::control::ControlCommand *control_command) override
update control command
Chassis::DrivingMode Driving_Mode() override
get the latest chassis driving mode
void PublishChassisDetailSender() override
publish chassis for apollo sender messages
void PublishChassisDetail() override
publish chassis for vehicle messages
bool Start() override
start canclient, cansender, canreceiver, vehicle controller
Chassis publish_chassis() override
publish chassis messages
bool CheckChassisCommunicationFault() override
check chassis can receiver lost
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