Apollo 10.0
自动驾驶开放平台
lexus_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 "gtest/gtest_prod.h"
23#include "modules/canbus/proto/canbus_conf.pb.h"
24#include "modules/canbus/proto/vehicle_parameter.pb.h"
25#include "modules/canbus_vehicle/lexus/proto/lexus.pb.h"
26#include "modules/common_msgs/basic_msgs/error_code.pb.h"
27#include "modules/common_msgs/chassis_msgs/chassis.pb.h"
28#include "modules/common_msgs/control_msgs/control_cmd.pb.h"
42
43namespace apollo {
44namespace canbus {
45namespace lexus {
46
47class LexusController final
48 : public VehicleController<::apollo::canbus::Lexus> {
49 public:
50 virtual ~LexusController();
51
53 const VehicleParameter& params,
54 CanSender<::apollo::canbus::Lexus>* const can_sender,
55 MessageManager<::apollo::canbus::Lexus>* const message_manager) override;
56
57 bool Start() override;
58
62 void Stop() override;
63
68 Chassis chassis() override;
69
70 FRIEND_TEST(LexusControllerTest, SetDrivingMode);
71 FRIEND_TEST(LexusControllerTest, Status);
72 FRIEND_TEST(LexusControllerTest, UpdateDrivingMode);
73
74 private:
75 // main logical function for operation the car enter or exit the auto driving
76 void Emergency() override;
77 ::apollo::common::ErrorCode EnableAutoMode() override;
78 ::apollo::common::ErrorCode DisableAutoMode() override;
79 ::apollo::common::ErrorCode EnableSteeringOnlyMode() override;
80 ::apollo::common::ErrorCode EnableSpeedOnlyMode() override;
81
82 // NEUTRAL, REVERSE, DRIVE
83 void Gear(Chassis::GearPosition state) override;
84
85 // brake with new acceleration
86 // acceleration:0.00~99.99, unit:
87 // acceleration_spd: 60 ~ 100, suggest: 90
88 void Brake(double acceleration) override;
89
90 // drive with old acceleration
91 // gas:0.00~99.99 unit:
92 void Throttle(double throttle) override;
93
94 // drive with acceleration/deceleration
95 // acc:-7.0~5.0 unit:m/s^2
96 void Acceleration(double acc) override;
97
98 // steering with old angle speed
99 // angle:-99.99~0.00~99.99, unit:, left:+, right:-
100 void Steer(double angle) override;
101
102 // steering with new angle speed
103 // angle:-99.99~0.00~99.99, unit:, left:+, right:-
104 // angle_spd:0.00~99.99, unit:deg/s
105 void Steer(double angle, double angle_spd) override;
106
107 // set Electrical Park Brake
108 void SetEpbBreak(const control::ControlCommand& command) override;
109 common::ErrorCode HandleCustomOperation(
110 const external_command::ChassisCommand& command) override;
111 void SetBeam(const common::VehicleSignal& signal) override;
112 void SetHorn(const common::VehicleSignal& signal) override;
113 void SetTurningSignal(const common::VehicleSignal& signal) override;
114
115 bool VerifyID() override;
116 void ResetProtocol();
117 bool CheckChassisError();
118
119 private:
120 void SecurityDogThreadFunc();
121 virtual bool CheckResponse(const int32_t flags, bool need_wait);
122 void set_chassis_error_mask(const int32_t mask);
123 int32_t chassis_error_mask();
124 Chassis::ErrorCode chassis_error_code();
125 void set_chassis_error_code(const Chassis::ErrorCode& error_code);
126
127 private:
128 // control protocol
129 Accelcmd100* accel_cmd_100_ = nullptr;
130 Brakecmd104* brake_cmd_104_ = nullptr;
131 Cruisecontrolbuttonscmd108* cruise_control_buttons_cmd_108_ = nullptr;
132 Dashcontrolsrightrpt210* dash_controls_right_rpt_210_ = nullptr;
133 Hazardlightscmd114* hazard_lights_cmd_114_ = nullptr;
134 Headlightcmd118* headlight_cmd_118_ = nullptr;
135 Horncmd11c* horn_cmd_11c_ = nullptr;
136 Parkingbrakecmd124* parking_brake_cmd_124_ = nullptr;
137 Shiftcmd128* shift_cmd_128_ = nullptr;
138 Steeringcmd12c* steering_cmd_12c_ = nullptr;
139 Turncmd130* turn_cmd_130_ = nullptr;
140 Wipercmd134* wiper_cmd_134_ = nullptr;
141
142 Chassis chassis_;
143 std::unique_ptr<std::thread> thread_;
144 bool is_chassis_error_ = false;
145
146 std::mutex chassis_error_code_mutex_;
147 Chassis::ErrorCode chassis_error_code_ = Chassis::NO_ERROR;
148
149 std::mutex chassis_mask_mutex_;
150 int32_t chassis_error_mask_ = 0;
151};
152
153} // namespace lexus
154} // namespace canbus
155} // 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(LexusControllerTest, UpdateDrivingMode)
bool Start() override
start the vehicle controller.
FRIEND_TEST(LexusControllerTest, SetDrivingMode)
Chassis chassis() override
calculate and return the chassis.
::apollo::common::ErrorCode Init(const VehicleParameter &params, CanSender<::apollo::canbus::Lexus > *const can_sender, MessageManager<::apollo::canbus::Lexus > *const message_manager) override
void Stop() override
stop the vehicle controller.
FRIEND_TEST(LexusControllerTest, Status)
class register implement
Definition arena_queue.h:37
The class of VehicleController