Apollo 10.0
自动驾驶开放平台
neolix_edu_controller.h
浏览该文件的文档.
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/vehicle_parameter.pb.h"
24#include "modules/common_msgs/basic_msgs/error_code.pb.h"
25#include "modules/common_msgs/chassis_msgs/chassis.pb.h"
26#include "modules/common_msgs/control_msgs/control_cmd.pb.h"
27
34
35namespace apollo {
36namespace canbus {
37namespace neolix_edu {
38
40 : public VehicleController<::apollo::canbus::Neolix_edu> {
41 public:
42 virtual ~Neolix_eduController();
43
45 const VehicleParameter& params,
46 CanSender<::apollo::canbus::Neolix_edu>* const can_sender,
47 MessageManager<::apollo::canbus::Neolix_edu>* const message_manager)
48 override;
49
50 bool Start() override;
51
55 void Stop() override;
56
61 Chassis chassis() override;
62
66 void AddSendMessage() override;
67
71 FRIEND_TEST(Neolix_eduControllerTest, SetDrivingMode);
72 FRIEND_TEST(Neolix_eduControllerTest, Status);
73 FRIEND_TEST(Neolix_eduControllerTest, UpdateDrivingMode);
74
75 private:
76 // main logical function for operation the car enter or exit the auto driving
77 void Emergency() override;
78 ::apollo::common::ErrorCode EnableAutoMode() override;
79 ::apollo::common::ErrorCode DisableAutoMode() override;
80 ::apollo::common::ErrorCode EnableSteeringOnlyMode() override;
81 ::apollo::common::ErrorCode EnableSpeedOnlyMode() override;
82
83 // NEUTRAL, REVERSE, DRIVE
84 void Gear(Chassis::GearPosition state) override;
85
86 // brake with new acceleration
87 // acceleration:0.00~99.99, unit:
88 // acceleration_spd: 60 ~ 100, suggest: 90
89 void Brake(double acceleration) override;
90
91 // drive with old acceleration
92 // gas:0.00~99.99 unit:
93 void Throttle(double throttle) override;
94
95 // drive with acceleration/deceleration
96 // acc:-7.0~5.0 unit:m/s^2
97 void Acceleration(double acc) override;
98
99 // steering with old angle speed
100 // angle:-99.99~0.00~99.99, unit:, left:+, right:-
101 void Steer(double angle) override;
102
103 // steering with new angle speed
104 // angle:-99.99~0.00~99.99, unit:, left:+, right:-
105 // angle_spd:0.00~99.99, unit:deg/s
106 void Steer(double angle, double angle_spd) override;
107
108 // set Electrical Park Brake
109 void SetEpbBreak(const control::ControlCommand& command) override;
110 common::ErrorCode HandleCustomOperation(
111 const external_command::ChassisCommand& command) override;
112 void SetBeam(const common::VehicleSignal& signal) override;
113 void SetHorn(const common::VehicleSignal& signal) override;
114 void SetTurningSignal(const common::VehicleSignal& signal) override;
115
116 bool VerifyID() override;
117 void ResetProtocol();
118 bool CheckChassisError();
119
120 private:
121 void SecurityDogThreadFunc();
122 virtual bool CheckResponse(const int32_t flags, bool need_wait);
123 void set_chassis_error_mask(const int32_t mask);
124 int32_t chassis_error_mask();
125 Chassis::ErrorCode chassis_error_code();
126 void set_chassis_error_code(const Chassis::ErrorCode& error_code);
127
128 private:
129 // control protocol
130 Adsbrakecommand46* ads_brake_command_46_ = nullptr;
131 Adsdiagnosis628* ads_diagnosis_628_ = nullptr;
132 Adsdrivecommand50* ads_drive_command_50_ = nullptr;
133 Adsepscommand56* ads_eps_command_56_ = nullptr;
134 Adslighthorncommand310* ads_light_horn_command_310_ = nullptr;
135
136 Chassis chassis_;
137 std::unique_ptr<std::thread> thread_;
138 bool is_chassis_error_ = false;
139
140 std::mutex chassis_error_code_mutex_;
141 Chassis::ErrorCode chassis_error_code_ = Chassis::NO_ERROR;
142
143 std::mutex chassis_mask_mutex_;
144 int32_t chassis_error_mask_ = 0;
145};
146
147} // namespace neolix_edu
148} // namespace canbus
149} // namespace apollo
This is the interface class of vehicle controller.
virtual common::ErrorCode SetDrivingMode(const Chassis::DrivingMode &driving_mode)
set vehicle to appointed driving mode.
void Stop() override
stop the vehicle controller.
void AddSendMessage() override
add the sender message.
FRIEND_TEST(Neolix_eduControllerTest, SetDrivingMode)
for test
Chassis chassis() override
calculate and return the chassis.
FRIEND_TEST(Neolix_eduControllerTest, Status)
bool Start() override
start the vehicle controller.
FRIEND_TEST(Neolix_eduControllerTest, UpdateDrivingMode)
::apollo::common::ErrorCode Init(const VehicleParameter &params, CanSender<::apollo::canbus::Neolix_edu > *const can_sender, MessageManager<::apollo::canbus::Neolix_edu > *const message_manager) override
class register implement
Definition arena_queue.h:37
The class of VehicleController