Apollo  6.0
Open source self driving car software
neolix_edu_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 
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 neolix_edu {
39 
41  public:
42  virtual ~Neolix_eduController();
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  FRIEND_TEST(Neolix_eduControllerTest, SetDrivingMode);
63  FRIEND_TEST(Neolix_eduControllerTest, Status);
64  FRIEND_TEST(Neolix_eduControllerTest, UpdateDrivingMode);
65 
66  private:
67  // main logical function for operation the car enter or exit the auto driving
68  void Emergency() override;
69  ::apollo::common::ErrorCode EnableAutoMode() override;
70  ::apollo::common::ErrorCode DisableAutoMode() override;
71  ::apollo::common::ErrorCode EnableSteeringOnlyMode() override;
72  ::apollo::common::ErrorCode EnableSpeedOnlyMode() override;
73 
74  // NEUTRAL, REVERSE, DRIVE
75  void Gear(Chassis::GearPosition state) override;
76 
77  // brake with new acceleration
78  // acceleration:0.00~99.99, unit:
79  // acceleration_spd: 60 ~ 100, suggest: 90
80  void Brake(double acceleration) override;
81 
82  // drive with old acceleration
83  // gas:0.00~99.99 unit:
84  void Throttle(double throttle) override;
85 
86  // drive with acceleration/deceleration
87  // acc:-7.0~5.0 unit:m/s^2
88  void Acceleration(double acc) override;
89 
90  // steering with old angle speed
91  // angle:-99.99~0.00~99.99, unit:, left:+, right:-
92  void Steer(double angle) override;
93 
94  // steering with new angle speed
95  // angle:-99.99~0.00~99.99, unit:, left:+, right:-
96  // angle_spd:0.00~99.99, unit:deg/s
97  void Steer(double angle, double angle_spd) override;
98 
99  // set Electrical Park Brake
100  void SetEpbBreak(const ::apollo::control::ControlCommand& command) override;
101  void SetBeam(const ::apollo::control::ControlCommand& command) override;
102  void SetHorn(const ::apollo::control::ControlCommand& command) override;
103  void SetTurningSignal(
104  const ::apollo::control::ControlCommand& command) override;
105 
106  void ResetProtocol();
107  bool CheckChassisError();
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  Adsbrakecommand46* ads_brake_command_46_ = nullptr;
120  Adsdiagnosis628* ads_diagnosis_628_ = nullptr;
121  Adsdrivecommand50* ads_drive_command_50_ = nullptr;
122  Adsepscommand56* ads_eps_command_56_ = nullptr;
123  Adslighthorncommand310* ads_light_horn_command_310_ = nullptr;
124 
125  Chassis chassis_;
126  std::unique_ptr<std::thread> thread_;
127  bool is_chassis_error_ = false;
128 
129  std::mutex chassis_error_code_mutex_;
130  Chassis::ErrorCode chassis_error_code_ = Chassis::NO_ERROR;
131 
132  std::mutex chassis_mask_mutex_;
133  int32_t chassis_error_mask_ = 0;
134 };
135 
136 } // namespace neolix_edu
137 } // namespace canbus
138 } // namespace apollo
Definition: neolix_edu_controller.h:40
Definition: ads_drive_command_50.h:26
Definition: ads_light_horn_command_310.h:26
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
FRIEND_TEST(Neolix_eduControllerTest, SetDrivingMode)
virtual common::ErrorCode SetDrivingMode(const Chassis::DrivingMode &driving_mode)
set vehicle to appointed driving mode.
Chassis chassis() override
calculate and return the chassis.
bool Start() override
start the vehicle controller.
void Stop() override
stop the vehicle controller.
Definition: ads_eps_command_56.h:26
::apollo::common::ErrorCode Init(const VehicleParameter &params, CanSender<::apollo::canbus::ChassisDetail > *const can_sender, MessageManager<::apollo::canbus::ChassisDetail > *const message_manager) override
Definition: ads_diagnosis_628.h:26
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: ads_brake_command_46.h:26