36 auto can_factory = CanClientFactory::Instance();
37 can_factory->RegisterCanClients();
40 AERROR <<
"Failed to create can client.";
43 AINFO <<
"Can client is successfully created.";
45 message_manager_ = this->CreateMessageManager();
46 if (message_manager_ ==
nullptr) {
47 AERROR <<
"Failed to create message manager.";
50 AINFO <<
"Message manager is successfully created.";
52 if (can_receiver_.Init(can_client_.get(), message_manager_.get(),
54 AERROR <<
"Failed to init can receiver.";
57 AINFO <<
"The can receiver is successfully initialized.";
59 if (can_sender_.Init(can_client_.get(), message_manager_.get(),
61 AERROR <<
"Failed to init can sender.";
64 AINFO <<
"The can sender is successfully initialized.";
66 vehicle_controller_ = CreateVehicleController();
67 if (vehicle_controller_ ==
nullptr) {
68 AERROR <<
"Failed to create vehicle controller.";
71 AINFO <<
"The vehicle controller is successfully created.";
74 message_manager_.get()) != ErrorCode::OK) {
75 AERROR <<
"Failed to init vehicle controller.";
79 AINFO <<
"The vehicle controller is successfully"
80 <<
" initialized with canbus conf as : "
85 chassis_detail_writer_ =
93 if (can_client_->Start() != ErrorCode::OK) {
94 AERROR <<
"Failed to start can client";
97 AINFO <<
"Can client is started.";
100 if (can_receiver_.Start() != ErrorCode::OK) {
101 AERROR <<
"Failed to start can receiver.";
104 AINFO <<
"Can receiver is started.";
107 if (can_sender_.Start() != ErrorCode::OK) {
108 AERROR <<
"Failed to start can sender.";
113 if (!vehicle_controller_->Start()) {
114 AERROR <<
"Failed to start vehicle controller.";
123 can_receiver_.Stop();
125 vehicle_controller_->Stop();
126 AINFO <<
"Cleanup cansender, canreceiver, canclient, vehicle controller.";
131 if (vehicle_controller_->Update(*control_command) != ErrorCode::OK) {
132 AERROR <<
"Failed to process callback function OnControlCommand because "
133 "vehicle_controller_->Update error.";
136 can_sender_.Update();
141 if (vehicle_controller_->Update(*chassis_command) != ErrorCode::OK) {
142 AERROR <<
"Failed to process callback function OnControlCommand because "
143 "vehicle_controller_->Update error.";
146 can_sender_.Update();
150 Chassis chassis = vehicle_controller_->chassis();
151 ADEBUG << chassis.ShortDebugString();
156 Lexus chassis_detail;
157 message_manager_->GetSensorData(&chassis_detail);
158 ADEBUG << chassis_detail.ShortDebugString();
159 chassis_detail_writer_->Write(chassis_detail);
162std::unique_ptr<VehicleController<::apollo::canbus::Lexus>>
163LexusVehicleFactory::CreateVehicleController() {
164 return std::unique_ptr<VehicleController<::apollo::canbus::Lexus>>(
168std::unique_ptr<MessageManager<::apollo::canbus::Lexus>>
169LexusVehicleFactory::CreateMessageManager() {
170 return std::unique_ptr<MessageManager<::apollo::canbus::Lexus>>(
171 new lexus::LexusMessageManager());
Defines the CanClientFactory class.
bool Start() override
start canclient, cansender, canreceiver, vehicle controller
void UpdateCommand(const apollo::control::ControlCommand *control_command) override
update control command
void PublishChassisDetail() override
publish chassis for vehicle messages
bool Init(const CanbusConf *canbus_conf) override
init vehicle factory
void Stop() override
create ch vehicle controller
Chassis publish_chassis() override
publish chassis 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