Apollo  6.0
Open source self driving car software
lexus_controller.h
Go to the documentation of this file.
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 
25 
26 #include "modules/canbus/proto/canbus_conf.pb.h"
27 #include "modules/canbus/proto/chassis.pb.h"
28 #include "modules/canbus/proto/chassis_detail.pb.h"
29 #include "modules/canbus/proto/vehicle_parameter.pb.h"
30 #include "modules/common/proto/error_code.pb.h"
31 #include "modules/control/proto/control_cmd.pb.h"
32 
45 
46 namespace apollo {
47 namespace canbus {
48 namespace lexus {
49 
50 class LexusController final : public VehicleController {
51  public:
52  virtual ~LexusController();
53 
54  ::apollo::common::ErrorCode Init(
55  const VehicleParameter& params,
56  CanSender<::apollo::canbus::ChassisDetail>* const can_sender,
57  MessageManager<::apollo::canbus::ChassisDetail>* const message_manager)
58  override;
59 
60  bool Start() override;
61 
65  void Stop() override;
66 
71  Chassis chassis() override;
72 
73  FRIEND_TEST(LexusControllerTest, SetDrivingMode);
74  FRIEND_TEST(LexusControllerTest, Status);
75  FRIEND_TEST(LexusControllerTest, UpdateDrivingMode);
76 
77  private:
78  // main logical function for operation the car enter or exit the auto driving
79  void Emergency() override;
80  ::apollo::common::ErrorCode EnableAutoMode() override;
81  ::apollo::common::ErrorCode DisableAutoMode() override;
82  ::apollo::common::ErrorCode EnableSteeringOnlyMode() override;
83  ::apollo::common::ErrorCode EnableSpeedOnlyMode() override;
84 
85  // NEUTRAL, REVERSE, DRIVE
86  void Gear(Chassis::GearPosition state) override;
87 
88  // brake with new acceleration
89  // acceleration:0.00~99.99, unit:
90  // acceleration_spd: 60 ~ 100, suggest: 90
91  void Brake(double acceleration) override;
92 
93  // drive with old acceleration
94  // gas:0.00~99.99 unit:
95  void Throttle(double throttle) override;
96 
97  // drive with acceleration/deceleration
98  // acc:-7.0~5.0 unit:m/s^2
99  void Acceleration(double acc) override;
100 
101  // steering with old angle speed
102  // angle:-99.99~0.00~99.99, unit:, left:+, right:-
103  void Steer(double angle) override;
104 
105  // steering with new angle speed
106  // angle:-99.99~0.00~99.99, unit:, left:+, right:-
107  // angle_spd:0.00~99.99, unit:deg/s
108  void Steer(double angle, double angle_spd) override;
109 
110  // set Electrical Park Brake
111  void SetEpbBreak(const ::apollo::control::ControlCommand& command) override;
112  void SetBeam(const ::apollo::control::ControlCommand& command) override;
113  void SetHorn(const ::apollo::control::ControlCommand& command) override;
114  void SetTurningSignal(
115  const ::apollo::control::ControlCommand& command) override;
116 
117  void ResetProtocol();
118  bool CheckChassisError();
119 
120  private:
121  void SecurityDogThreadFunc();
122  virtual bool CheckResponse(const int32_t flags, bool need_wait);
123  void set_chassis_error_mask(const int32_t mask);
124  int32_t chassis_error_mask();
125  Chassis::ErrorCode chassis_error_code();
126  void set_chassis_error_code(const Chassis::ErrorCode& error_code);
127 
128  private:
129  // control protocol
130  Accelcmd100* accel_cmd_100_ = nullptr;
131  Brakecmd104* brake_cmd_104_ = nullptr;
132  Cruisecontrolbuttonscmd108* cruise_control_buttons_cmd_108_ = nullptr;
133  Dashcontrolsrightrpt210* dash_controls_right_rpt_210_ = nullptr;
134  Hazardlightscmd114* hazard_lights_cmd_114_ = nullptr;
135  Headlightcmd118* headlight_cmd_118_ = nullptr;
136  Horncmd11c* horn_cmd_11c_ = nullptr;
137  Parkingbrakecmd124* parking_brake_cmd_124_ = nullptr;
138  Shiftcmd128* shift_cmd_128_ = nullptr;
139  Steeringcmd12c* steering_cmd_12c_ = nullptr;
140  Turncmd130* turn_cmd_130_ = nullptr;
141  Wipercmd134* wiper_cmd_134_ = nullptr;
142 
143  Chassis chassis_;
144  std::unique_ptr<std::thread> thread_;
145  bool is_chassis_error_ = false;
146 
147  std::mutex chassis_error_code_mutex_;
148  Chassis::ErrorCode chassis_error_code_ = Chassis::NO_ERROR;
149 
150  std::mutex chassis_mask_mutex_;
151  int32_t chassis_error_mask_ = 0;
152 };
153 
154 } // namespace lexus
155 } // namespace canbus
156 } // namespace apollo
void Stop() override
stop the vehicle controller.
FRIEND_TEST(LexusControllerTest, SetDrivingMode)
Definition: brake_cmd_104.h:26
Definition: dash_controls_right_rpt_210.h:26
Definition: headlight_cmd_118.h:26
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Chassis chassis() override
calculate and return the chassis.
Definition: shift_cmd_128.h:26
Definition: steering_cmd_12c.h:26
Definition: parking_brake_cmd_124.h:26
Definition: lexus_controller.h:50
virtual common::ErrorCode SetDrivingMode(const Chassis::DrivingMode &driving_mode)
set vehicle to appointed driving mode.
Definition: turn_cmd_130.h:26
Definition: horn_cmd_11c.h:26
bool Start() override
start the vehicle controller.
Definition: cruise_control_buttons_cmd_108.h:26
The class of VehicleController.
Definition: wiper_cmd_134.h:26
This is the interface class of vehicle controller. It defines pure virtual functions, and also some implemented common functions.
Definition: vehicle_controller.h:53
::apollo::common::ErrorCode Init(const VehicleParameter &params, CanSender<::apollo::canbus::ChassisDetail > *const can_sender, MessageManager<::apollo::canbus::ChassisDetail > *const message_manager) override
Definition: accel_cmd_100.h:26
Definition: hazard_lights_cmd_114.h:26