Apollo 10.0
自动驾驶开放平台
demo_controller.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 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 demo {
39
40class DemoController final : public VehicleController<::apollo::canbus::Demo> {
41 public:
43
44 virtual ~DemoController();
45
47 const VehicleParameter& params,
48 CanSender<::apollo::canbus::Demo>* const can_sender,
49 MessageManager<::apollo::canbus::Demo>* const message_manager) override;
50
51 bool Start() override;
52
56 void Stop() override;
57
62 Chassis chassis() override;
63
67 void AddSendMessage() override;
68
69 private:
70 // main logical function for operation the car enter or exit the auto driving
71 void Emergency() override;
72 ::apollo::common::ErrorCode EnableAutoMode() override;
73 ::apollo::common::ErrorCode DisableAutoMode() override;
74 ::apollo::common::ErrorCode EnableSteeringOnlyMode() override;
75 ::apollo::common::ErrorCode EnableSpeedOnlyMode() override;
76
77 // NEUTRAL, REVERSE, DRIVE
78 void Gear(Chassis::GearPosition state) override;
79
80 // brake with new acceleration
81 // acceleration:0.00~99.99, unit:
82 // acceleration_spd: 60 ~ 100, suggest: 90
83 void Brake(double acceleration) override;
84
85 // drive with old acceleration
86 // gas:0.00~99.99 unit:
87 void Throttle(double throttle) override;
88
89 // drive with acceleration/deceleration
90 // acc:-7.0~5.0 unit:m/s^2
91 void Acceleration(double acc) override;
92
93 // drive with speed
94 // speed:-xx.0~xx.0 unit:m/s
95 void Speed(double speed);
96
97 // steering with old angle speed
98 // angle:-99.99~0.00~99.99, unit:, left:+, right:-
99 void Steer(double angle) override;
100
101 // steering with new angle speed
102 // angle:-99.99~0.00~99.99, unit:, left:+, right:-
103 // angle_spd:0.00~99.99, unit:deg/s
104 void Steer(double angle, double angle_spd) override;
105
106 // set Electrical Park Brake
107 void SetEpbBreak(const control::ControlCommand& command) override;
108 void SetBeam(const common::VehicleSignal& vehicle_signal) override;
109 void SetHorn(const common::VehicleSignal& vehicle_signal) override;
110 void SetTurningSignal(const common::VehicleSignal& vehicle_signal) override;
111
112 // set Chassis Command
113 common::ErrorCode HandleCustomOperation(
114 const external_command::ChassisCommand& command) override;
115
116 // response vid
117 bool VerifyID() override;
118 bool CheckVin();
119 void GetVin();
120 void ResetVin();
121 void ResetProtocol();
122 bool CheckChassisError();
123
124 private:
125 void SecurityDogThreadFunc();
126 virtual bool CheckResponse(const int32_t flags, bool need_wait);
127 void set_chassis_error_mask(const int32_t mask);
128 int32_t chassis_error_mask();
129 Chassis::ErrorCode chassis_error_code();
130 void set_chassis_error_code(const Chassis::ErrorCode& error_code);
131
132 private:
133 // control protocol
134 Brakecommand101* brake_command_101_ = nullptr;
135 Gearcommand103* gear_command_103_ = nullptr;
136 Parkcommand104* park_command_104_ = nullptr;
137 Steeringcommand102* steering_command_102_ = nullptr;
138 Throttlecommand100* throttle_command_100_ = nullptr;
139 Vehiclemodecommand105* vehicle_mode_command_105_ = nullptr;
140
141 Chassis chassis_;
142 std::unique_ptr<std::thread> thread_;
143 bool is_chassis_error_ = false;
144
145 std::mutex chassis_error_code_mutex_;
146 Chassis::ErrorCode chassis_error_code_ = Chassis::NO_ERROR;
147
148 std::mutex chassis_mask_mutex_;
149 int32_t chassis_error_mask_ = 0;
150};
151
152} // namespace demo
153} // namespace canbus
154} // namespace apollo
This is the interface class of vehicle controller.
::apollo::common::ErrorCode Init(const VehicleParameter &params, CanSender<::apollo::canbus::Demo > *const can_sender, MessageManager<::apollo::canbus::Demo > *const message_manager) override
void AddSendMessage() override
add the sender message.
bool Start() override
start the vehicle controller.
Chassis chassis() override
calculate and return the chassis.
void Stop() override
stop the vehicle controller.
class register implement
Definition arena_queue.h:37
The class of VehicleController