$darkmode
basic.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 Robert Bosch GmbH
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  * SPDX-License-Identifier: Apache-2.0
17  */
29 #pragma once
30 
31 #include <cloe/controller.hpp> // for Controller, ControllerFactory, ...
32 #include <cloe/models.hpp> // for CloeComponent
33 
34 namespace cloe {
35 namespace controller {
36 namespace basic {
37 
38 struct AccConfiguration : public Confable {
39  std::string ego_sensor = to_string(CloeComponent::DEFAULT_EGO_SENSOR);
40  std::string world_sensor = to_string(CloeComponent::DEFAULT_WORLD_SENSOR);
41  std::string latlong_actuator = to_string(CloeComponent::DEFAULT_LATLONG_ACTUATOR);
42 
43  double limit_deceleration = 5.0;
44  double limit_acceleration = 3.0;
45 
46  /*
47  * Controller Parameters
48  *
49  * These parameters are heavily connected to the used vehicle model. For
50  * example a VTD model has a very simple vehicle model and can follow
51  * commands directly. Other vehicles models on the other hand may be pretty
52  * slow in adapting to changes of the acceleration. Therefore the parameters
53  * need to be adapted to have a more sufficient controller.
54  *
55  * Hint: For a better VTD control set the integrator parts from the variable
56  * ki to 0.
57  *
58  * General Behaviour and Constraints:
59  *
60  * - ACC only works within one lane; the function cannot distinguish between
61  * lanes and does not take lane information into account.
62  * - AEB can prevent car crash but sometimes interferes with the ACC,
63  * which can be especially degrading to ACC performance.
64  * - ACC parameters are highly dependent on the vehicle dynamics and
65  * should be adapted accordingly. See the next two sections.
66  *
67  * VTD Behavior (with default control parameters):
68  * - works fine for timegap safe
69  * - works fine for timegap normal
70  * - not tested with timegap fifty
71  * - works fine for timegap crazy
72  */
73  double kd{5};
74  double ki{0};
75  double kp{0.8};
76 
77  /*
78  * Another possibility to improve the control is to use different controller
79  * parameters. One set for the speed control and one set for the distance
80  * control
81  */
82  double kd_m = kd;
83  double ki_m = ki;
84  double kp_m = kp;
85 
86  CONFABLE_SCHEMA(AccConfiguration) {
87  // clang-format off
88  return Schema{
89  {"ego_sensor", Schema(&ego_sensor, "ego sensor component to read from")},
90  {"world_sensor", Schema(&world_sensor, "world_sensor component to read from")},
91  {"latlong_actuator", Schema(&latlong_actuator, "actuator to write to")},
92  {"limit_acceleration", Schema(&limit_acceleration, "acceleration limit in [m/s^2]")},
93  {"limit_deceleration", Schema(&limit_deceleration, "how much deceleration is allowed, in [m/s^2]")},
94  {"derivative_factor_speed_control", Schema(&kd, "factor to tune the D term of the PID speed controller")},
95  {"proportional_factor_speed_control", Schema(&kp, "factor to tune the P term of the PID speed controller")},
96  {"integral_factor_speed_control", Schema(&ki, "factor to tune the I term of the PID speed controller")},
97  {"derivative_factor_dist_control", Schema(&kd_m, "factor to tune the D term of the PID distance controller")},
98  {"proportional_factor_dist_control", Schema(&kp_m, "factor to tune the P term of the PID distance controller")},
99  {"integral_factor_dist_control", Schema(&ki_m, "factor to tune the I term of the PID distance controller")},
100  };
101  // clang-format on
102  }
103 };
104 
105 struct AebConfiguration : public Confable {
106  bool enabled = true;
107  std::string ego_sensor = to_string(CloeComponent::DEFAULT_EGO_SENSOR);
108  std::string world_sensor = to_string(CloeComponent::DEFAULT_WORLD_SENSOR);
109  std::string latlong_actuator = to_string(CloeComponent::DEFAULT_LATLONG_ACTUATOR);
110  bool always_full_stop = false;
111  double limit_deceleration = 8.0;
112 
113  CONFABLE_SCHEMA(AebConfiguration) {
114  // clang-format off
115  return Schema{
116  {"enabled", Schema(&enabled, "whether automatic emergency braking is enabled")},
117  {"ego_sensor", Schema(&ego_sensor, "ego sensor component to read from")},
118  {"world_sensor", Schema(&world_sensor, "world_sensor component to read from")},
119  {"latlong_actuator", Schema(&latlong_actuator, "actuator to write to")},
120  {"always_full_stop", Schema(&always_full_stop, "whether to brake to a full-stop on activation")},
121  {"limit_deceleration", Schema(&limit_deceleration, "how much deceleration is allowed, in [m/s^2]")},
122  };
123  // clang-format on
124  }
125 };
126 
127 struct LkaConfiguration : public Confable {
128  bool enabled = false;
129  std::string world_sensor = to_string(CloeComponent::DEFAULT_WORLD_SENSOR);
130  std::string latlong_actuator = to_string(CloeComponent::DEFAULT_LATLONG_ACTUATOR);
131  double adjustment_rad = 0.02;
132  double tolerance = 0.1;
133  double lerp_factor = 0.1;
134 
135  CONFABLE_SCHEMA(LkaConfiguration) {
136  // clang-format off
137  return Schema{
138  {"enabled", Schema(&enabled, "whether lane keeping assist is enabled")},
139  {"world_sensor", Schema(&world_sensor, "world_sensor component to read from")},
140  {"latlong_actuator", Schema(&latlong_actuator, "actuator to write to")},
141  {"adjustment_rad", Schema(&adjustment_rad, "wheel angle adjustment in [rad]")},
142  {"tolerance", Schema(&tolerance, "absolute tolerance in [m]")},
143  {"lerp_factor", Schema(&lerp_factor, "linear interpolation factor with domain (0-1]")},
144  };
145  // clang-format on
146  }
147 };
148 
149 struct BasicConfiguration : public Confable {
150  AccConfiguration acc;
151  AebConfiguration aeb;
152  LkaConfiguration lka;
153  std::string driver_request;
154 
155  void to_json(Json& j) const override {
156  j = Json{
157  {"acc", acc},
158  {"aeb", aeb},
159  {"lka", lka},
160  };
161  }
162 
163  CONFABLE_SCHEMA(BasicConfiguration) {
164  // clang-format off
165  return Schema{
166  {"acc", Schema(&acc, "ACC configuration")},
167  {"aeb", Schema(&aeb, "AEB configuration")},
168  {"lka", Schema(&lka, "LKA configuration")},
169  {"driver_request", Schema(&driver_request, "component providing driver request")},
170  };
171  // clang-format on
172  }
173 };
174 
175 DEFINE_CONTROLLER_FACTORY(BasicFactory, BasicConfiguration, "basic",
176  "very basic vehicle controller")
177 
178 } // namespace basic
179 } // namespace controller
180 } // namespace cloe
Definition: confable.hpp:46
Definition: coordinator.hpp:36
Json to_json() const
Definition: confable.cpp:74
Definition: schema.hpp:178
#define DEFINE_CONTROLLER_FACTORY(xFactoryType, xConfigType, xName, xDescription)
Definition: controller.hpp:50