Apollo 10.0
自动驾驶开放平台
ch_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
35
36namespace apollo {
37namespace canbus {
38namespace ch {
39
40class ChController final : public VehicleController<::apollo::canbus::Ch> {
41 public:
43
44 virtual ~ChController();
45
47 const VehicleParameter& params,
48 CanSender<::apollo::canbus::Ch>* const can_sender,
49 MessageManager<::apollo::canbus::Ch>* const message_manager) override;
50
51 bool Start() override;
52
56 void Stop() override;
57
62 Chassis chassis() override;
63
64 FRIEND_TEST(ChControllerTest, SetDrivingMode);
65 FRIEND_TEST(ChControllerTest, Status);
66 FRIEND_TEST(ChControllerTest, 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 // response vid
110 bool VerifyID() override;
111 void ResetProtocol();
112 bool CheckChassisError();
113 bool CheckVin();
114 void GetVin();
115 void ResetVin();
116
117 private:
118 void SecurityDogThreadFunc();
119 virtual bool CheckResponse(const int32_t flags, bool need_wait);
120 void set_chassis_error_mask(const int32_t mask);
121 int32_t chassis_error_mask();
122 Chassis::ErrorCode chassis_error_code();
123 void set_chassis_error_code(const Chassis::ErrorCode& error_code);
124
125 private:
126 // control protocol
127 Brakecommand111* brake_command_111_ = nullptr;
128 Gearcommand114* gear_command_114_ = nullptr;
129 Steercommand112* steer_command_112_ = nullptr;
130 Throttlecommand110* throttle_command_110_ = nullptr;
131 Turnsignalcommand113* turnsignal_command_113_ = nullptr;
132 Vehiclemodecommand116* vehicle_mode_command_116_ = nullptr;
133
134 Chassis chassis_;
135 std::unique_ptr<std::thread> thread_;
136 bool is_chassis_error_ = false;
137
138 std::mutex chassis_error_code_mutex_;
139 Chassis::ErrorCode chassis_error_code_ = Chassis::NO_ERROR;
140
141 std::mutex chassis_mask_mutex_;
142 int32_t chassis_error_mask_ = 0;
143};
144
145} // namespace ch
146} // namespace canbus
147} // 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(ChControllerTest, SetDrivingMode)
FRIEND_TEST(ChControllerTest, UpdateDrivingMode)
::apollo::common::ErrorCode Init(const VehicleParameter &params, CanSender<::apollo::canbus::Ch > *const can_sender, MessageManager<::apollo::canbus::Ch > *const message_manager) override
Chassis chassis() override
calculate and return the chassis.
bool Start() override
start the vehicle controller.
FRIEND_TEST(ChControllerTest, Status)
void Stop() override
stop the vehicle controller.
class register implement
Definition arena_queue.h:37
The class of VehicleController