Apollo 10.0
自动驾驶开放平台
ge3_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#include "modules/canbus/proto/canbus_conf.pb.h"
22#include "modules/canbus/proto/vehicle_parameter.pb.h"
23#include "modules/common_msgs/basic_msgs/error_code.pb.h"
24#include "modules/common_msgs/chassis_msgs/chassis.pb.h"
25#include "modules/common_msgs/control_msgs/control_cmd.pb.h"
32
33namespace apollo {
34namespace canbus {
35namespace ge3 {
36
37class Ge3Controller final : public VehicleController<::apollo::canbus::Ge3> {
38 public:
40
41 virtual ~Ge3Controller();
42
44 const VehicleParameter& params,
45 CanSender<::apollo::canbus::Ge3>* const can_sender,
46 MessageManager<::apollo::canbus::Ge3>* const message_manager) override;
47
48 bool Start() override;
49
53 void Stop() override;
54
59 Chassis chassis() override;
60 FRIEND_TEST(Ge3ControllerTest, SetDrivingMode);
61 FRIEND_TEST(Ge3ControllerTest, Status);
62 FRIEND_TEST(Ge3ControllerTest, UpdateDrivingMode);
63
64 private:
65 // main logical function for operation the car enter or exit the auto driving
66 void Emergency() override;
67 ::apollo::common::ErrorCode EnableAutoMode() override;
68 ::apollo::common::ErrorCode DisableAutoMode() override;
69 ::apollo::common::ErrorCode EnableSteeringOnlyMode() override;
70 ::apollo::common::ErrorCode EnableSpeedOnlyMode() override;
71
72 // NEUTRAL, REVERSE, DRIVE
73 void Gear(Chassis::GearPosition state) override;
74
75 // brake with new acceleration
76 // acceleration:0.00~99.99, unit:
77 // acceleration_spd: 60 ~ 100, suggest: 90
78 void Brake(double acceleration) override;
79
80 // drive with old acceleration
81 // gas:0.00~99.99 unit:
82 void Throttle(double throttle) override;
83
84 // drive with acceleration/deceleration
85 // acc:-7.0~5.0 unit:m/s^2
86 void Acceleration(double acc) override;
87
88 // steering with old angle speed
89 // angle:-99.99~0.00~99.99, unit:, left:+, right:-
90 void Steer(double angle) override;
91
92 // steering with new angle speed
93 // angle:-99.99~0.00~99.99, unit:, left:+, right:-
94 // angle_spd:0.00~99.99, unit:deg/s
95 void Steer(double angle, double angle_spd) override;
96
97 // set Electrical Park Brake
98 void SetEpbBreak(const control::ControlCommand& command) override;
99 common::ErrorCode HandleCustomOperation(
100 const external_command::ChassisCommand& command) override;
101 void SetBeam(const common::VehicleSignal& signal) override;
102 void SetHorn(const common::VehicleSignal& signal) override;
103 void SetTurningSignal(const common::VehicleSignal& signal) override;
104
105 bool VerifyID() override;
106 void ResetProtocol();
107 bool CheckChassisError();
108 bool CheckSafetyError(const canbus::Ge3& chassis);
109
110 private:
111 void SecurityDogThreadFunc();
112 virtual bool CheckResponse(const int32_t flags, bool need_wait);
113 void set_chassis_error_mask(const int32_t mask);
114 int32_t chassis_error_mask();
115 Chassis::ErrorCode chassis_error_code();
116 void set_chassis_error_code(const Chassis::ErrorCode& error_code);
117
118 private:
119 // control protocol
120 Pcbcm201* pc_bcm_201_ = nullptr;
121 Pcbcs202* pc_bcs_202_ = nullptr;
122 Pcepb203* pc_epb_203_ = nullptr;
123 Pceps204* pc_eps_204_ = nullptr;
124 Pcvcu205* pc_vcu_205_ = nullptr;
125
126 Chassis chassis_;
127 std::unique_ptr<std::thread> thread_;
128 bool is_chassis_error_ = false;
129 bool received_vin_ = 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 ge3
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.
FRIEND_TEST(Ge3ControllerTest, Status)
::apollo::common::ErrorCode Init(const VehicleParameter &params, CanSender<::apollo::canbus::Ge3 > *const can_sender, MessageManager<::apollo::canbus::Ge3 > *const message_manager) override
FRIEND_TEST(Ge3ControllerTest, SetDrivingMode)
FRIEND_TEST(Ge3ControllerTest, UpdateDrivingMode)
Chassis chassis() override
calculate and return the chassis.
bool Start() override
start the vehicle controller.
void Stop() override
stop the vehicle controller.
class register implement
Definition arena_queue.h:37
The class of VehicleController