Apollo  6.0
Open source self driving car software
vehicle_controller.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 
22 #pragma once
23 
24 #include <unordered_map>
25 
26 #include "modules/canbus/proto/canbus_conf.pb.h"
27 #include "modules/canbus/proto/chassis.pb.h"
28 #include "modules/canbus/proto/chassis_detail.pb.h"
29 #include "modules/control/proto/control_cmd.pb.h"
30 
32 #include "modules/common/proto/error_code.pb.h"
36 
41 namespace apollo {
42 namespace canbus {
43 
44 using ::apollo::drivers::canbus::CanSender;
45 using ::apollo::drivers::canbus::MessageManager;
46 
54  public:
55  virtual ~VehicleController() = default;
56 
63  virtual common::ErrorCode Init(
64  const VehicleParameter &params,
65  CanSender<ChassisDetail> *const can_sender,
66  MessageManager<ChassisDetail> *const message_manager) = 0;
67 
72  virtual bool Start() = 0;
73 
77  virtual void Stop() = 0;
78 
83  virtual Chassis chassis() = 0;
84 
90  virtual common::ErrorCode Update(const control::ControlCommand &command);
91 
97  virtual common::ErrorCode SetDrivingMode(
98  const Chassis::DrivingMode &driving_mode);
99 
100  private:
101  /*
102  * @brief main logical function for operation the car enter or exit the auto
103  * driving
104  */
105  virtual void Emergency() = 0;
106 
107  virtual common::ErrorCode EnableAutoMode() = 0;
108  virtual common::ErrorCode DisableAutoMode() = 0;
109  virtual common::ErrorCode EnableSteeringOnlyMode() = 0;
110  virtual common::ErrorCode EnableSpeedOnlyMode() = 0;
111 
112  /*
113  * @brief NEUTRAL, REVERSE, DRIVE
114  */
115  virtual void Gear(Chassis::GearPosition state) = 0;
116 
117  /*
118  * @brief detail function for auto driving brake with new acceleration
119  * acceleration:0.00~99.99, unit:%
120  */
121  virtual void Brake(double acceleration) = 0;
122 
123  /*
124  * @brief drive with old acceleration gas:0.00~99.99 unit:%
125  */
126  virtual void Throttle(double throttle) = 0;
127 
128  /*
129  * @brief drive with new acceleration/deceleration:-7.0~7.0, unit:m/s^2,
130  * acc:-7.0~7.0, unit:m/s^2
131  */
132  virtual void Acceleration(double acc) = 0;
133 
134  /*
135  * @brief steering with old angle speed angle:-99.99~0.00~99.99, unit:%,
136  * left:+, right:-
137  */
138  virtual void Steer(double angle) = 0;
139 
140  /*
141  * @brief steering with new angle speed angle:-99.99~0.00~99.99, unit:%,
142  * left:+, right:- angle_spd:0.00~99.99, unit:deg/s
143  */
144  virtual void Steer(double angle, double angle_spd) = 0;
145 
146  /*
147  * @brief set Electrical Park Brake
148  */
149  virtual void SetEpbBreak(const control::ControlCommand &command) = 0;
150  virtual void SetBeam(const control::ControlCommand &command) = 0;
151  virtual void SetHorn(const control::ControlCommand &command) = 0;
152  virtual void SetTurningSignal(const control::ControlCommand &command) = 0;
153 
154  virtual void SetLimits() {}
155 
156  protected:
157  virtual Chassis::DrivingMode driving_mode();
158  virtual void set_driving_mode(const Chassis::DrivingMode &driving_mode);
159 
160  protected:
161  canbus::VehicleParameter params_;
162  common::VehicleParam vehicle_params_;
163  CanSender<ChassisDetail> *can_sender_ = nullptr;
164  MessageManager<ChassisDetail> *message_manager_ = nullptr;
165  bool is_initialized_ = false; // own by derviative concrete controller
166  Chassis::DrivingMode driving_mode_ = Chassis::COMPLETE_MANUAL;
167  bool is_reset_ = false; // reset command from control command
168  std::mutex mode_mutex_; // only use in this base class
169 };
170 
171 } // namespace canbus
172 } // namespace apollo
virtual ~VehicleController()=default
bool is_reset_
Definition: vehicle_controller.h:167
virtual common::ErrorCode Update(const control::ControlCommand &command)
update the vehicle controller.
virtual void Stop()=0
stop the vehicle controller.
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
The class of MessageManager.
virtual void set_driving_mode(const Chassis::DrivingMode &driving_mode)
CanSender< ChassisDetail > * can_sender_
Definition: vehicle_controller.h:163
std::mutex mode_mutex_
Definition: vehicle_controller.h:168
virtual common::ErrorCode SetDrivingMode(const Chassis::DrivingMode &driving_mode)
set vehicle to appointed driving mode.
common::VehicleParam vehicle_params_
Definition: vehicle_controller.h:162
Defines SenderMessage class and CanSender class.
virtual bool Start()=0
start the vehicle controller.
virtual Chassis chassis()=0
calculate and return the chassis.
bool is_initialized_
Definition: vehicle_controller.h:165
This is the interface class of vehicle controller. It defines pure virtual functions, and also some implemented common functions.
Definition: vehicle_controller.h:53
virtual Chassis::DrivingMode driving_mode()
MessageManager< ChassisDetail > * message_manager_
Definition: vehicle_controller.h:164
Chassis::DrivingMode driving_mode_
Definition: vehicle_controller.h:166
The class of ProtocolData.
virtual common::ErrorCode Init(const VehicleParameter &params, CanSender< ChassisDetail > *const can_sender, MessageManager< ChassisDetail > *const message_manager)=0
initialize the vehicle controller.
canbus::VehicleParameter params_
Definition: vehicle_controller.h:161