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