Apollo  6.0
Open source self driving car software
ge3_controller.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2019 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 
17 #pragma once
18 
19 #include <memory>
20 #include <thread>
21 #include "modules/canbus/proto/canbus_conf.pb.h"
22 #include "modules/canbus/proto/chassis.pb.h"
23 #include "modules/canbus/proto/vehicle_parameter.pb.h"
30 #include "modules/common/proto/error_code.pb.h"
31 #include "modules/control/proto/control_cmd.pb.h"
32 
33 namespace apollo {
34 namespace canbus {
35 namespace ge3 {
36 
37 class Ge3Controller final : public VehicleController {
38  public:
40 
41  virtual ~Ge3Controller();
42 
43  ::apollo::common::ErrorCode Init(
44  const VehicleParameter& params,
45  CanSender<::apollo::canbus::ChassisDetail>* const can_sender,
46  MessageManager<::apollo::canbus::ChassisDetail>* const message_manager)
47  override;
48 
49  bool Start() override;
50 
54  void Stop() override;
55 
60  Chassis chassis() override;
61  FRIEND_TEST(Ge3ControllerTest, SetDrivingMode);
62  FRIEND_TEST(Ge3ControllerTest, Status);
63  FRIEND_TEST(Ge3ControllerTest, UpdateDrivingMode);
64 
65  private:
66  // main logical function for operation the car enter or exit the auto driving
67  void Emergency() override;
68  ::apollo::common::ErrorCode EnableAutoMode() override;
69  ::apollo::common::ErrorCode DisableAutoMode() override;
70  ::apollo::common::ErrorCode EnableSteeringOnlyMode() override;
71  ::apollo::common::ErrorCode EnableSpeedOnlyMode() override;
72 
73  // NEUTRAL, REVERSE, DRIVE
74  void Gear(Chassis::GearPosition state) override;
75 
76  // brake with new acceleration
77  // acceleration:0.00~99.99, unit:
78  // acceleration_spd: 60 ~ 100, suggest: 90
79  void Brake(double acceleration) override;
80 
81  // drive with old acceleration
82  // gas:0.00~99.99 unit:
83  void Throttle(double throttle) override;
84 
85  // drive with acceleration/deceleration
86  // acc:-7.0~5.0 unit:m/s^2
87  void Acceleration(double acc) override;
88 
89  // steering with old angle speed
90  // angle:-99.99~0.00~99.99, unit:, left:+, right:-
91  void Steer(double angle) override;
92 
93  // steering with new angle speed
94  // angle:-99.99~0.00~99.99, unit:, left:+, right:-
95  // angle_spd:0.00~99.99, unit:deg/s
96  void Steer(double angle, double angle_spd) override;
97 
98  // set Electrical Park Brake
99  void SetEpbBreak(const ::apollo::control::ControlCommand& command) override;
100  void SetBeam(const ::apollo::control::ControlCommand& command) override;
101  void SetHorn(const ::apollo::control::ControlCommand& command) override;
102  void SetTurningSignal(
103  const ::apollo::control::ControlCommand& command) override;
104 
105  void ResetProtocol();
106  bool CheckChassisError();
107  bool CheckSafetyError(const canbus::ChassisDetail& chassis);
108 
109  private:
110  void SecurityDogThreadFunc();
111  virtual bool CheckResponse(const int32_t flags, bool need_wait);
112  void set_chassis_error_mask(const int32_t mask);
113  int32_t chassis_error_mask();
114  Chassis::ErrorCode chassis_error_code();
115  void set_chassis_error_code(const Chassis::ErrorCode& error_code);
116 
117  private:
118  // control protocol
119  Pcbcm201* pc_bcm_201_ = nullptr;
120  Pcbcs202* pc_bcs_202_ = nullptr;
121  Pcepb203* pc_epb_203_ = nullptr;
122  Pceps204* pc_eps_204_ = nullptr;
123  Pcvcu205* pc_vcu_205_ = nullptr;
124 
125  Chassis chassis_;
126  std::unique_ptr<std::thread> thread_;
127  bool is_chassis_error_ = false;
128  bool received_vin_ = false;
129 
130  std::mutex chassis_error_code_mutex_;
131  Chassis::ErrorCode chassis_error_code_ = Chassis::NO_ERROR;
132 
133  std::mutex chassis_mask_mutex_;
134  int32_t chassis_error_mask_ = 0;
135 };
136 
137 } // namespace ge3
138 } // namespace canbus
139 } // namespace apollo
FRIEND_TEST(Ge3ControllerTest, SetDrivingMode)
Chassis chassis() override
calculate and return the chassis.
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
::apollo::common::ErrorCode Init(const VehicleParameter &params, CanSender<::apollo::canbus::ChassisDetail > *const can_sender, MessageManager<::apollo::canbus::ChassisDetail > *const message_manager) override
virtual common::ErrorCode SetDrivingMode(const Chassis::DrivingMode &driving_mode)
set vehicle to appointed driving mode.
Definition: pc_epb_203.h:26
Definition: pc_vcu_205.h:26
Definition: ge3_controller.h:37
Definition: pc_eps_204.h:26
void Stop() override
stop the vehicle controller.
The class of VehicleController.
This is the interface class of vehicle controller. It defines pure virtual functions, and also some implemented common functions.
Definition: vehicle_controller.h:53
Definition: pc_bcm_201.h:26
bool Start() override
start the vehicle controller.
Definition: pc_bcs_202.h:26
Ge3Controller()
Definition: ge3_controller.h:39