Apollo 10.0
自动驾驶开放平台
zhongyun_controller.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 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 zhongyun {
38
40 : public VehicleController<::apollo::canbus::Zhongyun> {
41 public:
43
44 virtual ~ZhongyunController();
45
47 const VehicleParameter& params,
48 CanSender<::apollo::canbus::Zhongyun>* const can_sender,
49 MessageManager<::apollo::canbus::Zhongyun>* const message_manager)
50 override;
51
52 bool Start() override;
53
57 void Stop() override;
58
63 Chassis chassis() override;
64 FRIEND_TEST(ZhongyunControllerTest, SetDrivingMode);
65 FRIEND_TEST(ZhongyunControllerTest, Status);
66 FRIEND_TEST(ZhongyunControllerTest, 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 control::ControlCommand& command) override;
103 common::ErrorCode HandleCustomOperation(
104 const external_command::ChassisCommand& command) override;
105 void SetBeam(const common::VehicleSignal& signal) override;
106 void SetHorn(const common::VehicleSignal& signal) override;
107 void SetTurningSignal(const common::VehicleSignal& signal) override;
108
109 bool VerifyID() override;
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 Brakecontrola4* brake_control_a4_ = nullptr;
124 Gearcontrola1* gear_control_a1_ = nullptr;
125 Parkingcontrola5* parking_control_a5_ = nullptr;
126 Steeringcontrola2* steering_control_a2_ = nullptr;
127 Torquecontrola3* torque_control_a3_ = 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 zhongyun
141} // namespace canbus
142} // 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.
FRIEND_TEST(ZhongyunControllerTest, UpdateDrivingMode)
bool Start() override
start the vehicle controller.
void Stop() override
stop the vehicle controller.
FRIEND_TEST(ZhongyunControllerTest, Status)
::apollo::common::ErrorCode Init(const VehicleParameter &params, CanSender<::apollo::canbus::Zhongyun > *const can_sender, MessageManager<::apollo::canbus::Zhongyun > *const message_manager) override
Chassis chassis() override
calculate and return the chassis.
FRIEND_TEST(ZhongyunControllerTest, SetDrivingMode)
class register implement
Definition arena_queue.h:37
The class of VehicleController