Apollo  6.0
Open source self driving car software
transit_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 
17 #pragma once
18 
19 #include <memory>
20 #include <thread>
21 
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 
35 
36 namespace apollo {
37 namespace canbus {
38 namespace transit {
39 
40 class TransitController final : public VehicleController {
41  public:
43 
44  virtual ~TransitController();
45 
46  ::apollo::common::ErrorCode Init(
47  const VehicleParameter& params,
48  CanSender<::apollo::canbus::ChassisDetail>* const can_sender,
49  MessageManager<::apollo::canbus::ChassisDetail>* const message_manager)
50  override;
51 
52  bool Start() override;
53 
57  void Stop() override;
58 
63  Chassis chassis() override;
64  FRIEND_TEST(TransitControllerTest, SetDrivingMode);
65  FRIEND_TEST(TransitControllerTest, Status);
66  FRIEND_TEST(TransitControllerTest, UpdateDrivingMode);
67 
68  private:
69  // main logical function for operation the car enter or exit the auto driving
70  void Emergency() override;
71  ::apollo::common::ErrorCode EnableAutoMode() override;
72  ::apollo::common::ErrorCode DisableAutoMode() override;
73  ::apollo::common::ErrorCode EnableSteeringOnlyMode() override;
74  ::apollo::common::ErrorCode EnableSpeedOnlyMode() override;
75 
76  // NEUTRAL, REVERSE, DRIVE
77  void Gear(Chassis::GearPosition state) override;
78 
79  // brake with new acceleration
80  // acceleration:0.00~99.99, unit:
81  // acceleration_spd: 60 ~ 100, suggest: 90
82  void Brake(double acceleration) override;
83 
84  // drive with old acceleration
85  // gas:0.00~99.99 unit:
86  void Throttle(double throttle) override;
87 
88  // drive with acceleration/deceleration
89  // acc:-7.0~5.0 unit:m/s^2
90  void Acceleration(double acc) override;
91 
92  // steering with old angle speed
93  // angle:-99.99~0.00~99.99, unit:, left:+, right:-
94  void Steer(double angle) override;
95 
96  // steering with new angle speed
97  // angle:-99.99~0.00~99.99, unit:, left:+, right:-
98  // angle_spd:0.00~99.99, unit:deg/s
99  void Steer(double angle, double angle_spd) override;
100 
101  // set Electrical Park Brake
102  void SetEpbBreak(const ::apollo::control::ControlCommand& command) override;
103  void SetBeam(const ::apollo::control::ControlCommand& command) override;
104  void SetHorn(const ::apollo::control::ControlCommand& command) override;
105  void SetTurningSignal(
106  const ::apollo::control::ControlCommand& command) override;
107 
108  void ResetProtocol();
109  bool CheckChassisError();
110  bool CheckSafetyError(const canbus::ChassisDetail& chassis);
111 
112  void SetLimits() override;
113 
114  private:
115  void SecurityDogThreadFunc();
116  virtual bool CheckResponse();
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  Adcauxiliarycontrol110* adc_auxiliarycontrol_110_ = nullptr;
125  Adcmotioncontrol110* adc_motioncontrol1_10_ = nullptr;
126  Adcmotioncontrollimits112* adc_motioncontrollimits1_12_ = nullptr;
127  Llcdiagbrakecontrol721* llc_diag_brakecontrol_721_ = nullptr;
128  Llcdiagsteeringcontrol722* llc_diag_steeringcontrol_722_ = nullptr;
129 
130  Chassis chassis_;
131  std::unique_ptr<std::thread> thread_;
132  bool is_chassis_error_ = false;
133 
134  std::mutex chassis_error_code_mutex_;
135  Chassis::ErrorCode chassis_error_code_ = Chassis::NO_ERROR;
136 
137  std::mutex chassis_mask_mutex_;
138  int32_t chassis_error_mask_ = 0;
139  bool received_vin_ = false;
140  bool button_pressed_ = false;
141 };
142 
143 } // namespace transit
144 } // namespace canbus
145 } // namespace apollo
Definition: llc_diag_steeringcontrol_722.h:26
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: adc_motioncontrol1_10.h:28
Definition: transit_controller.h:40
Chassis chassis() override
calculate and return the chassis.
virtual common::ErrorCode SetDrivingMode(const Chassis::DrivingMode &driving_mode)
set vehicle to appointed driving mode.
void Stop() override
stop the vehicle controller.
Definition: adc_motioncontrollimits1_12.h:27
bool Start() override
start the vehicle controller.
::apollo::common::ErrorCode Init(const VehicleParameter &params, CanSender<::apollo::canbus::ChassisDetail > *const can_sender, MessageManager<::apollo::canbus::ChassisDetail > *const message_manager) override
The class of VehicleController.
TransitController()
Definition: transit_controller.h:42
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: adc_auxiliarycontrol_110.h:27
Definition: llc_diag_brakecontrol_721.h:28
FRIEND_TEST(TransitControllerTest, SetDrivingMode)