Apollo 9.0
自动驾驶开放平台
lincoln_controller.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 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
22#pragma once
23
24#include <memory>
25#include <thread>
26
27#include "gtest/gtest_prod.h"
28
29#include "modules/canbus/proto/canbus_conf.pb.h"
30#include "modules/canbus/proto/vehicle_parameter.pb.h"
31#include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h"
32#include "modules/common_msgs/basic_msgs/error_code.pb.h"
33#include "modules/common_msgs/chassis_msgs/chassis.pb.h"
34#include "modules/common_msgs/control_msgs/control_cmd.pb.h"
35
36#include "cyber/common/macros.h"
43
48namespace apollo {
49namespace canbus {
50namespace lincoln {
51
58 : public VehicleController<::apollo::canbus::Lincoln> {
59 public:
65 CanSender<::apollo::canbus::Lincoln> *const can_sender,
66 MessageManager<::apollo::canbus::Lincoln>
67 *const message_manager) override;
68
73 bool Start() override;
74
78 void Stop() override;
79
84 Chassis chassis() override;
85
86 FRIEND_TEST(LincolnControllerTest, SetDrivingMode);
87 FRIEND_TEST(LincolnControllerTest, Status);
88 FRIEND_TEST(LincolnControllerTest, UpdateDrivingMode);
89
90 private:
91 // main logical function for operation the car enter or exit the auto driving
92 void Emergency() override;
93 common::ErrorCode EnableAutoMode() override;
94 common::ErrorCode DisableAutoMode() override;
95 common::ErrorCode EnableSteeringOnlyMode() override;
96 common::ErrorCode EnableSpeedOnlyMode() override;
97
98 // NEUTRAL, REVERSE, DRIVE
99 void Gear(Chassis::GearPosition state) override;
100
101 // brake with new acceleration
102 // acceleration:0.00~99.99, unit:%
103 // acceleration_spd: 60 ~ 100, suggest: 90
104 void Brake(double acceleration) override;
105
106 // drive with old acceleration
107 // gas:0.00~99.99 unit:%
108 void Throttle(double throttle) override;
109
110 // drive with acceleration/deceleration
111 // acc:-7.0~5.0 unit:m/s^2
112 void Acceleration(double acc) override;
113
114 // steering with old angle speed
115 // angle:-99.99~0.00~99.99, unit:%, left:+, right:-
116 void Steer(double angle) override;
117
118 // steering with new angle speed
119 // angle:-99.99~0.00~99.99, unit:%, left:+, right:-
120 // angle_spd:0.00~99.99, unit:deg/s
121 void Steer(double angle, double angle_spd) override;
122
123 // set Electrical Park Brake
124 void SetEpbBreak(const control::ControlCommand &command) override;
125 common::ErrorCode HandleCustomOperation(
126 const external_command::ChassisCommand &command) override;
127 void SetBeam(const common::VehicleSignal &signal) override;
128 void SetHorn(const common::VehicleSignal &signal) override;
129 void SetTurningSignal(const common::VehicleSignal &signal) override;
130
131 bool VerifyID() override;
132 void ResetProtocol();
133 bool CheckChassisError();
134 bool CheckSafetyError(const canbus::Lincoln &chassis);
135
136 private:
137 void SecurityDogThreadFunc();
138 virtual bool CheckResponse(const int32_t flags, bool need_wait);
139 void set_chassis_error_mask(const int32_t mask);
140 int32_t chassis_error_mask();
141 Chassis::ErrorCode chassis_error_code();
142 void set_chassis_error_code(const Chassis::ErrorCode &error_code);
143
144 private:
145 // control protocol
146 Brake60 *brake_60_ = nullptr;
147 Throttle62 *throttle_62_ = nullptr;
148 Steering64 *steering_64_ = nullptr;
149 Gear66 *gear_66_ = nullptr;
150 Turnsignal68 *turnsignal_68_ = nullptr;
151
152 Chassis chassis_;
153 std::unique_ptr<std::thread> thread_;
154 bool is_chassis_error_ = false;
155
156 std::mutex chassis_error_code_mutex_;
157 Chassis::ErrorCode chassis_error_code_ = Chassis::NO_ERROR;
158
159 std::mutex chassis_mask_mutex_;
160 int32_t chassis_error_mask_ = 0;
161
162 bool received_vin_ = false;
163
165};
166
167} // namespace lincoln
168} // namespace canbus
169} // namespace apollo
the class of Brake60 (for lincoln vehicle)
This is the interface class of vehicle controller.
virtual common::ErrorCode SetDrivingMode(const Chassis::DrivingMode &driving_mode)
set vehicle to appointed driving mode.
one of the protocol data of lincoln vehicle
Definition brake_60.h:41
one of the protocol data of lincoln vehicle
Definition gear_66.h:41
this class implements the vehicle controller for lincoln vehicle.
FRIEND_TEST(LincolnControllerTest, UpdateDrivingMode)
Chassis chassis() override
calculate and return the chassis.
void Stop() override
stop the vehicle controller.
FRIEND_TEST(LincolnControllerTest, Status)
common::ErrorCode Init(const VehicleParameter &params, CanSender<::apollo::canbus::Lincoln > *const can_sender, MessageManager<::apollo::canbus::Lincoln > *const message_manager) override
initialize the lincoln vehicle controller.
FRIEND_TEST(LincolnControllerTest, SetDrivingMode)
bool Start() override
start the vehicle controller.
one of the protocol data of lincoln vehicle
Definition steering_64.h:41
one of the protocol data of lincoln vehicle
Definition throttle_62.h:41
one of the protocol data of lincoln vehicle
the class of Gear66 (for lincoln vehicle)
class register implement
the class of Steering64 (for lincoln vehicle)
the class of Throttle62 (for lincoln vehicle)
the class of Turnsignal68 (for lincoln vehicle)
The class of VehicleController