Apollo  6.0
Open source self driving car software
gem_controller.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2018 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 
22 #include "cyber/common/macros.h"
23 
24 #include "modules/canbus/proto/canbus_conf.pb.h"
25 #include "modules/canbus/proto/chassis.pb.h"
26 #include "modules/canbus/proto/vehicle_parameter.pb.h"
27 #include "modules/common/proto/error_code.pb.h"
28 #include "modules/control/proto/control_cmd.pb.h"
29 
37 
38 namespace apollo {
39 namespace canbus {
40 namespace gem {
41 
42 class GemController final : public VehicleController {
43  public:
45 
46  virtual ~GemController();
47 
48  ::apollo::common::ErrorCode Init(
49  const VehicleParameter& params,
50  CanSender<::apollo::canbus::ChassisDetail>* const can_sender,
51  MessageManager<::apollo::canbus::ChassisDetail>* const message_manager)
52  override;
53 
54  bool Start() override;
55 
59  void Stop() override;
60 
65  Chassis chassis() override;
66 
67  FRIEND_TEST(GemControllerTest, SetDrivingMode);
68  FRIEND_TEST(GemControllerTest, Status);
69  FRIEND_TEST(GemControllerTest, UpdateDrivingMode);
70 
71  private:
72  // main logical function for operation the car enter or exit the auto driving
73  void Emergency() override;
74  ::apollo::common::ErrorCode EnableAutoMode() override;
75  ::apollo::common::ErrorCode DisableAutoMode() override;
76  ::apollo::common::ErrorCode EnableSteeringOnlyMode() override;
77  ::apollo::common::ErrorCode EnableSpeedOnlyMode() override;
78 
79  // NEUTRAL, REVERSE, DRIVE
80  void Gear(Chassis::GearPosition state) override;
81 
82  // brake with new acceleration
83  // acceleration:0.00~99.99, unit:
84  // acceleration_spd: 60 ~ 100, suggest: 90
85  void Brake(double acceleration) override;
86 
87  // drive with old acceleration
88  // gas:0.00~99.99 unit:
89  void Throttle(double throttle) override;
90 
91  // drive with acceleration/deceleration
92  // acc:-7.0~5.0 unit:m/s^2
93  void Acceleration(double acc) override;
94 
95  // steering with old angle speed
96  // angle:-99.99~0.00~99.99, unit:, left:+, right:-
97  void Steer(double angle) override;
98 
99  // steering with new angle speed
100  // angle:-99.99~0.00~99.99, unit:, left:+, right:-
101  // angle_spd:0.00~99.99, unit:deg/s
102  void Steer(double angle, double angle_spd) override;
103 
104  // set Electrical Park Brake
105  void SetEpbBreak(const ::apollo::control::ControlCommand& command) override;
106  void SetBeam(const ::apollo::control::ControlCommand& command) override;
107  void SetHorn(const ::apollo::control::ControlCommand& command) override;
108  void SetTurningSignal(
109  const ::apollo::control::ControlCommand& command) override;
110 
111  void ResetProtocol();
112  bool CheckChassisError();
113 
114  private:
115  void SecurityDogThreadFunc();
116  virtual bool CheckResponse(const int32_t flags, bool need_wait);
117  void set_chassis_error_mask(const int32_t mask);
118  int32_t chassis_error_mask();
119  Chassis::ErrorCode chassis_error_code();
120  void set_chassis_error_code(const Chassis::ErrorCode& error_code);
121 
122  private:
123  // control protocol
124  Accelcmd67* accel_cmd_67_ = nullptr;
125  Brakecmd6b* brake_cmd_6b_ = nullptr;
126  Shiftcmd65* shift_cmd_65_ = nullptr;
127  Steeringcmd6d* steering_cmd_6d_ = nullptr;
128  Turncmd63* turn_cmd_63_ = nullptr;
129  Globalcmd69* global_cmd_69_ = nullptr;
130 
131  Chassis chassis_;
132  std::unique_ptr<std::thread> thread_;
133  bool is_chassis_error_ = false;
134 
135  std::mutex chassis_error_code_mutex_;
136  Chassis::ErrorCode chassis_error_code_ = Chassis::NO_ERROR;
137 
138  std::mutex chassis_mask_mutex_;
139  int32_t chassis_error_mask_ = 0;
140 };
141 
142 } // namespace gem
143 } // namespace canbus
144 } // namespace apollo
Definition: global_cmd_69.h:26
FRIEND_TEST(GemControllerTest, SetDrivingMode)
Definition: brake_cmd_6b.h:26
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: shift_cmd_65.h:26
Definition: accel_cmd_67.h:26
Chassis chassis() override
calculate and return the chassis.
Definition: gem_controller.h:42
The class of VehicleController.
Definition: steering_cmd_6d.h:26
This is the interface class of vehicle controller. It defines pure virtual functions, and also some implemented common functions.
Definition: vehicle_controller.h:53
GemController()
Definition: gem_controller.h:44
bool Start() override
start the vehicle controller.
Definition: turn_cmd_63.h:26
void Stop() override
stop the vehicle controller.