Apollo 10.0
自动驾驶开放平台
wey_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 wey {
38
39class WeyController final : public VehicleController<::apollo::canbus::Wey> {
40 public:
42
43 virtual ~WeyController();
44
46 const VehicleParameter& params,
47 CanSender<::apollo::canbus::Wey>* const can_sender,
48 MessageManager<::apollo::canbus::Wey>* const message_manager) override;
49
50 bool Start() override;
51
55 void Stop() override;
56
61 Chassis chassis() override;
62 FRIEND_TEST(WeyControllerTest, SetDrivingMode);
63 FRIEND_TEST(WeyControllerTest, Status);
64 FRIEND_TEST(WeyControllerTest, UpdateDrivingMode);
65
66 private:
67 // main logical function for operation the car enter or exit the auto driving
68 void Emergency() override;
69 ::apollo::common::ErrorCode EnableAutoMode() override;
70 ::apollo::common::ErrorCode DisableAutoMode() override;
71 ::apollo::common::ErrorCode EnableSteeringOnlyMode() override;
72 ::apollo::common::ErrorCode EnableSpeedOnlyMode() override;
73
74 // NEUTRAL, REVERSE, DRIVE
75 void Gear(Chassis::GearPosition state) override;
76
77 // brake with new acceleration
78 // acceleration:0.00~99.99, unit:
79 // acceleration_spd: 60 ~ 100, suggest: 90
80 void Brake(double acceleration) override;
81
82 // drive with old acceleration
83 // gas:0.00~99.99 unit:
84 void Throttle(double throttle) override;
85
86 // drive with acceleration/deceleration
87 // acc:-7.0~5.0 unit:m/s^2
88 void Acceleration(double acc) override;
89
90 // steering with old angle speed
91 // angle:-99.99~0.00~99.99, unit:, left:+, right:-
92 void Steer(double angle) override;
93
94 // steering with new angle speed
95 // angle:-99.99~0.00~99.99, unit:, left:+, right:-
96 // angle_spd:0.00~99.99, unit:deg/s
97 void Steer(double angle, double angle_spd) override;
98
99 // set Electrical Park Brake
100 void SetEpbBreak(const control::ControlCommand& command) override;
101 common::ErrorCode HandleCustomOperation(
102 const external_command::ChassisCommand& command) override;
103 void SetBeam(const common::VehicleSignal& signal) override;
104 void SetHorn(const common::VehicleSignal& signal) override;
105 void SetTurningSignal(const common::VehicleSignal& signal) override;
106
107 bool VerifyID() override;
108 void ResetProtocol();
109 bool CheckChassisError();
110
111 private:
112 void SecurityDogThreadFunc();
113 virtual bool CheckResponse(const int32_t flags, bool need_wait);
114 void set_chassis_error_mask(const int32_t mask);
115 int32_t chassis_error_mask();
116 Chassis::ErrorCode chassis_error_code();
117 void set_chassis_error_code(const Chassis::ErrorCode& error_code);
118
119 private:
120 // control protocol
121 Ads1111* ads1_111_ = nullptr;
122 Ads338e* ads3_38e_ = nullptr;
123 Adseps113* ads_eps_113_ = nullptr;
124 Adsreqvin390* ads_req_vin_390_ = nullptr;
125 Adsshifter115* ads_shifter_115_ = nullptr;
126
127 Chassis chassis_;
128 std::unique_ptr<std::thread> thread_;
129 bool is_chassis_error_ = false;
130
131 std::mutex chassis_error_code_mutex_;
132 Chassis::ErrorCode chassis_error_code_ = Chassis::NO_ERROR;
133
134 std::mutex chassis_mask_mutex_;
135 int32_t chassis_error_mask_ = 0;
136};
137
138} // namespace wey
139} // namespace canbus
140} // 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.
void Stop() override
stop the vehicle controller.
FRIEND_TEST(WeyControllerTest, UpdateDrivingMode)
Chassis chassis() override
calculate and return the chassis.
FRIEND_TEST(WeyControllerTest, Status)
FRIEND_TEST(WeyControllerTest, SetDrivingMode)
::apollo::common::ErrorCode Init(const VehicleParameter &params, CanSender<::apollo::canbus::Wey > *const can_sender, MessageManager<::apollo::canbus::Wey > *const message_manager) override
class register implement
Definition arena_queue.h:37
The class of VehicleController