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