Apollo 10.0
自动驾驶开放平台
gem_controller.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 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
28#include "cyber/common/macros.h"
36
37namespace apollo {
38namespace canbus {
39namespace gem {
40
41class GemController final : public VehicleController<::apollo::canbus::Gem> {
42 public:
44
45 virtual ~GemController();
46
48 const VehicleParameter& params,
49 CanSender<::apollo::canbus::Gem>* const can_sender,
50 MessageManager<::apollo::canbus::Gem>* const message_manager) override;
51
52 bool Start() override;
53
57 void Stop() override;
58
63 Chassis chassis() override;
64
65 FRIEND_TEST(GemControllerTest, SetDrivingMode);
66 FRIEND_TEST(GemControllerTest, Status);
67 FRIEND_TEST(GemControllerTest, UpdateDrivingMode);
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 // steering with old angle speed
94 // angle:-99.99~0.00~99.99, unit:, left:+, right:-
95 void Steer(double angle) override;
96
97 // steering with new angle speed
98 // angle:-99.99~0.00~99.99, unit:, left:+, right:-
99 // angle_spd:0.00~99.99, unit:deg/s
100 void Steer(double angle, double angle_spd) override;
101
102 // set Electrical Park Brake
103 void SetEpbBreak(const control::ControlCommand& command) override;
104 common::ErrorCode HandleCustomOperation(
105 const external_command::ChassisCommand& command) override;
106 void SetBeam(const common::VehicleSignal& signal) override;
107 void SetHorn(const common::VehicleSignal& signal) override;
108 void SetTurningSignal(const common::VehicleSignal& signal) override;
109
110 bool VerifyID() override;
111 void ResetProtocol();
112 bool CheckChassisError();
113
114 private:
115 void SecurityDogThreadFunc();
116 virtual bool CheckResponse(const int32_t flags, bool need_wait);
117 void set_chassis_error_mask(const int32_t mask);
118 int32_t chassis_error_mask();
119 Chassis::ErrorCode chassis_error_code();
120 void set_chassis_error_code(const Chassis::ErrorCode& error_code);
121
122 private:
123 // control protocol
124 Accelcmd67* accel_cmd_67_ = nullptr;
125 Brakecmd6b* brake_cmd_6b_ = nullptr;
126 Shiftcmd65* shift_cmd_65_ = nullptr;
127 Steeringcmd6d* steering_cmd_6d_ = nullptr;
128 Turncmd63* turn_cmd_63_ = nullptr;
129 Globalcmd69* global_cmd_69_ = nullptr;
130
131 Chassis chassis_;
132 std::unique_ptr<std::thread> thread_;
133 bool is_chassis_error_ = false;
134
135 std::mutex chassis_error_code_mutex_;
136 Chassis::ErrorCode chassis_error_code_ = Chassis::NO_ERROR;
137
138 std::mutex chassis_mask_mutex_;
139 int32_t chassis_error_mask_ = 0;
140};
141
142} // namespace gem
143} // namespace canbus
144} // 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.
void Stop() override
stop the vehicle controller.
FRIEND_TEST(GemControllerTest, Status)
FRIEND_TEST(GemControllerTest, UpdateDrivingMode)
bool Start() override
start the vehicle controller.
Chassis chassis() override
calculate and return the chassis.
::apollo::common::ErrorCode Init(const VehicleParameter &params, CanSender<::apollo::canbus::Gem > *const can_sender, MessageManager<::apollo::canbus::Gem > *const message_manager) override
FRIEND_TEST(GemControllerTest, SetDrivingMode)
class register implement
Definition arena_queue.h:37
The class of VehicleController