Apollo 10.0
自动驾驶开放平台
transit_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
17#pragma once
18
19#include <memory>
20#include <thread>
21
23
24#include "modules/canbus/proto/canbus_conf.pb.h"
25#include "modules/canbus/proto/vehicle_parameter.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"
29
35
36namespace apollo {
37namespace canbus {
38namespace transit {
39
41 : public VehicleController<::apollo::canbus::Transit> {
42 public:
44
45 virtual ~TransitController();
46
48 const VehicleParameter& params,
49 CanSender<::apollo::canbus::Transit>* const can_sender,
50 MessageManager<::apollo::canbus::Transit>* const message_manager)
51 override;
52
53 bool Start() override;
54
58 void Stop() override;
59
64 Chassis chassis() override;
65 FRIEND_TEST(TransitControllerTest, SetDrivingMode);
66 FRIEND_TEST(TransitControllerTest, Status);
67 FRIEND_TEST(TransitControllerTest, 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 bool CheckSafetyError(const canbus::Transit& chassis);
114
115 void SetLimits() override;
116
117 private:
118 void SecurityDogThreadFunc();
119 virtual bool CheckResponse();
120 void set_chassis_error_mask(const int32_t mask);
121 int32_t chassis_error_mask();
122 Chassis::ErrorCode chassis_error_code();
123 void set_chassis_error_code(const Chassis::ErrorCode& error_code);
124
125 private:
126 // control protocol
127 Adcauxiliarycontrol110* adc_auxiliarycontrol_110_ = nullptr;
128 Adcmotioncontrol110* adc_motioncontrol1_10_ = nullptr;
129 Adcmotioncontrollimits112* adc_motioncontrollimits1_12_ = nullptr;
130 Llcdiagbrakecontrol721* llc_diag_brakecontrol_721_ = nullptr;
131 Llcdiagsteeringcontrol722* llc_diag_steeringcontrol_722_ = nullptr;
132
133 Chassis chassis_;
134 std::unique_ptr<std::thread> thread_;
135 bool is_chassis_error_ = false;
136
137 std::mutex chassis_error_code_mutex_;
138 Chassis::ErrorCode chassis_error_code_ = Chassis::NO_ERROR;
139
140 std::mutex chassis_mask_mutex_;
141 int32_t chassis_error_mask_ = 0;
142 bool received_vin_ = false;
143 bool button_pressed_ = false;
144};
145
146} // namespace transit
147} // namespace canbus
148} // 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(TransitControllerTest, SetDrivingMode)
Chassis chassis() override
calculate and return the chassis.
bool Start() override
start the vehicle controller.
FRIEND_TEST(TransitControllerTest, UpdateDrivingMode)
FRIEND_TEST(TransitControllerTest, Status)
::apollo::common::ErrorCode Init(const VehicleParameter &params, CanSender<::apollo::canbus::Transit > *const can_sender, MessageManager<::apollo::canbus::Transit > *const message_manager) override
void Stop() override
stop the vehicle controller.
class register implement
Definition arena_queue.h:37
The class of VehicleController