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