Apollo  6.0
Open source self driving car software
canbus_component.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2017 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
21 #pragma once
22 
23 #include <memory>
24 #include <string>
25 #include <utility>
26 #include <vector>
27 
28 #include "cyber/common/macros.h"
30 #include "cyber/cyber.h"
31 #include "cyber/timer/timer.h"
32 
33 #include "modules/canbus/proto/chassis_detail.pb.h"
34 #include "modules/drivers/canbus/proto/can_card_parameter.pb.h"
35 #include "modules/guardian/proto/guardian.pb.h"
36 
40 #include "modules/control/proto/control_cmd.pb.h"
45 
50 namespace apollo {
51 namespace canbus {
52 
60  public:
66  std::string Name() const;
67 
68  private:
73  bool Init() override;
74 
78  bool Proc() override;
79 
83  void Clear() override;
84 
85  void PublishChassis();
86  void PublishChassisDetail();
87  void OnControlCommand(const apollo::control::ControlCommand &control_command);
88  void OnGuardianCommand(
89  const apollo::guardian::GuardianCommand &guardian_command);
90  apollo::common::Status OnError(const std::string &error_msg);
91  void RegisterCanClients();
92 
93  CanbusConf canbus_conf_;
94  std::shared_ptr<cyber::Reader<apollo::guardian::GuardianCommand>>
95  guardian_cmd_reader_;
96  std::shared_ptr<cyber::Reader<apollo::control::ControlCommand>>
97  control_command_reader_;
98  std::unique_ptr<apollo::drivers::canbus::CanClient> can_client_;
99  CanSender<ChassisDetail> can_sender_;
101  std::unique_ptr<MessageManager<ChassisDetail>> message_manager_;
102  std::unique_ptr<VehicleController> vehicle_controller_;
103  int64_t last_timestamp_ = 0;
104  ::apollo::common::monitor::MonitorLogBuffer monitor_logger_buffer_;
105  std::shared_ptr<cyber::Writer<Chassis>> chassis_writer_;
106  std::shared_ptr<cyber::Writer<ChassisDetail>> chassis_detail_writer_;
107 };
108 
110 
111 } // namespace canbus
112 } // namespace apollo
TimerComponent is a timer component. Your component can inherit from Component, and implement Init() ...
Definition: timer_component.h:35
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Defines the CanFrame struct and CanClient interface.
The class of MessageManager.
Defines SenderMessage class and CanSender class.
The class of VehicleController.
Definition: canbus_component.h:59
Defines CanReceiver class.
The class of MonitorLogBuffer.
A general class to denote the return status of an API call. It can either be an OK status for success...
Definition: status.h:43
#define CYBER_REGISTER_COMPONENT(name)
Definition: component.h:551
This class help collect MonitorMessage pb to monitor topic. The messages can be published automatical...
Definition: monitor_log_buffer.h:60
std::string Name() const
obtain module name