Apollo  6.0
Open source self driving car software
lincoln_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 <memory>
25 #include <thread>
26 
27 #include "gtest/gtest_prod.h"
28 
29 #include "cyber/common/macros.h"
30 
31 #include "modules/canbus/proto/canbus_conf.pb.h"
32 #include "modules/canbus/proto/chassis.pb.h"
33 #include "modules/canbus/proto/chassis_detail.pb.h"
34 #include "modules/canbus/proto/vehicle_parameter.pb.h"
35 #include "modules/common/proto/error_code.pb.h"
36 #include "modules/control/proto/control_cmd.pb.h"
37 
44 
49 namespace apollo {
50 namespace canbus {
51 namespace lincoln {
52 
58 class LincolnController final : public VehicleController {
59  public:
64  common::ErrorCode Init(
65  const VehicleParameter &params,
66  CanSender<::apollo::canbus::ChassisDetail> *const can_sender,
67  MessageManager<::apollo::canbus::ChassisDetail> *const message_manager)
68  override;
69 
74  bool Start() override;
75 
79  void Stop() override;
80 
85  Chassis chassis() override;
86 
87  FRIEND_TEST(LincolnControllerTest, SetDrivingMode);
88  FRIEND_TEST(LincolnControllerTest, Status);
89  FRIEND_TEST(LincolnControllerTest, UpdateDrivingMode);
90 
91  private:
92  // main logical function for operation the car enter or exit the auto driving
93  void Emergency() override;
94  common::ErrorCode EnableAutoMode() override;
95  common::ErrorCode DisableAutoMode() override;
96  common::ErrorCode EnableSteeringOnlyMode() override;
97  common::ErrorCode EnableSpeedOnlyMode() override;
98 
99  // NEUTRAL, REVERSE, DRIVE
100  void Gear(Chassis::GearPosition state) override;
101 
102  // brake with new acceleration
103  // acceleration:0.00~99.99, unit:%
104  // acceleration_spd: 60 ~ 100, suggest: 90
105  void Brake(double acceleration) override;
106 
107  // drive with old acceleration
108  // gas:0.00~99.99 unit:%
109  void Throttle(double throttle) override;
110 
111  // drive with acceleration/deceleration
112  // acc:-7.0~5.0 unit:m/s^2
113  void Acceleration(double acc) override;
114 
115  // steering with old angle speed
116  // angle:-99.99~0.00~99.99, unit:%, left:+, right:-
117  void Steer(double angle) override;
118 
119  // steering with new angle speed
120  // angle:-99.99~0.00~99.99, unit:%, left:+, right:-
121  // angle_spd:0.00~99.99, unit:deg/s
122  void Steer(double angle, double angle_spd) override;
123 
124  // set Electrical Park Brake
125  void SetEpbBreak(const control::ControlCommand &command) override;
126  void SetBeam(const control::ControlCommand &command) override;
127  void SetHorn(const control::ControlCommand &command) override;
128  void SetTurningSignal(const control::ControlCommand &command) override;
129 
130  void ResetProtocol();
131  bool CheckChassisError();
132  bool CheckSafetyError(const canbus::ChassisDetail &chassis);
133 
134  private:
135  void SecurityDogThreadFunc();
136  virtual bool CheckResponse(const int32_t flags, bool need_wait);
137  void set_chassis_error_mask(const int32_t mask);
138  int32_t chassis_error_mask();
139  Chassis::ErrorCode chassis_error_code();
140  void set_chassis_error_code(const Chassis::ErrorCode &error_code);
141 
142  private:
143  // control protocol
144  Brake60 *brake_60_ = nullptr;
145  Throttle62 *throttle_62_ = nullptr;
146  Steering64 *steering_64_ = nullptr;
147  Gear66 *gear_66_ = nullptr;
148  Turnsignal68 *turnsignal_68_ = nullptr;
149 
150  Chassis chassis_;
151  std::unique_ptr<std::thread> thread_;
152  bool is_chassis_error_ = false;
153 
154  std::mutex chassis_error_code_mutex_;
155  Chassis::ErrorCode chassis_error_code_ = Chassis::NO_ERROR;
156 
157  std::mutex chassis_mask_mutex_;
158  int32_t chassis_error_mask_ = 0;
159 
160  bool received_vin_ = false;
161 
162  canbus::Chassis::GearPosition gear_tmp_;
163 };
164 
165 } // namespace lincoln
166 } // namespace canbus
167 } // namespace apollo
the class of Brake60 (for lincoln vehicle)
one of the protocol data of lincoln vehicle
Definition: steering_64.h:40
the class of Turnsignal68 (for lincoln vehicle)
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
one of the protocol data of lincoln vehicle
Definition: throttle_62.h:40
virtual common::ErrorCode SetDrivingMode(const Chassis::DrivingMode &driving_mode)
set vehicle to appointed driving mode.
common::ErrorCode Init(const VehicleParameter &params, CanSender<::apollo::canbus::ChassisDetail > *const can_sender, MessageManager<::apollo::canbus::ChassisDetail > *const message_manager) override
initialize the lincoln vehicle controller.
the class of Steering64 (for lincoln vehicle)
Chassis chassis() override
calculate and return the chassis.
one of the protocol data of lincoln vehicle
Definition: brake_60.h:40
the class of Throttle62 (for lincoln vehicle)
The class of VehicleController.
bool Start() override
start the vehicle controller.
one of the protocol data of lincoln vehicle
Definition: gear_66.h:40
This is the interface class of vehicle controller. It defines pure virtual functions, and also some implemented common functions.
Definition: vehicle_controller.h:53
one of the protocol data of lincoln vehicle
Definition: turnsignal_68.h:40
FRIEND_TEST(LincolnControllerTest, SetDrivingMode)
the class of Gear66 (for lincoln vehicle)
void Stop() override
stop the vehicle controller.
this class implements the vehicle controller for lincoln vehicle.
Definition: lincoln_controller.h:58