31
31
32
32
#include < boost/optional.hpp> // for optional<>
33
33
34
+ #include < cloe/component/driver_request.hpp> // for DriverRequest
34
35
#include < cloe/component/latlong_actuator.hpp> // for LatLongActuator
35
36
#include < cloe/component/object_sensor.hpp> // for ObjectSensor
36
37
#include < cloe/component/utility/ego_sensor_canon.hpp> // for EgoSensor, EgoSensorCanon
@@ -81,6 +82,20 @@ const std::vector<std::pair<std::string, Algorithm>> ALGORITHMS{
81
82
82
83
} // namespace distance
83
84
85
+ double get_driver_request_acceleration (std::shared_ptr<DriverRequest> driver) {
86
+ if (!driver->has_acceleration ()) {
87
+ throw cloe::Error (" basic controller: {} has no acceleration data." , driver->name ());
88
+ }
89
+ return *driver->acceleration ();
90
+ }
91
+
92
+ double get_driver_request_steering_angle (std::shared_ptr<DriverRequest> driver) {
93
+ if (!driver->has_steering_angle ()) {
94
+ throw cloe::Error (" basic controller: {} has no steering_angle data." , driver->name ());
95
+ }
96
+ return *driver->steering_angle ();
97
+ }
98
+
84
99
struct AdaptiveCruiseControl {
85
100
AccConfiguration config;
86
101
std::shared_ptr<Vehicle> vehicle{nullptr };
@@ -194,12 +209,16 @@ struct AdaptiveCruiseControl {
194
209
/* *
195
210
* FIXME(ben): The HMI should not be manipulated while we are in this part.
196
211
*/
197
- void control (Vehicle& v, const Sync& sync) {
212
+ void control (Vehicle& v, const Sync& sync, const std::string& driver_request ) {
198
213
assert (distance_algorithm < distance::ALGORITHMS.size ());
199
214
200
215
if (!enabled || !active) {
201
216
// When not enabled, the function is disabled except for the HMI,
202
217
// which is controlled separately.
218
+ if (!driver_request.empty ()) {
219
+ double acc = get_driver_request_acceleration (v.get <DriverRequest>(driver_request));
220
+ v.get <LatLongActuator>(config.latlong_actuator )->set_acceleration (acc);
221
+ }
203
222
return ;
204
223
}
205
224
@@ -275,8 +294,12 @@ struct LaneKeepingAssistant {
275
294
public:
276
295
explicit LaneKeepingAssistant (const LkaConfiguration& c) : config(c) {}
277
296
278
- void control (Vehicle& v, const Sync&) {
297
+ void control (Vehicle& v, const Sync&, const std::string& driver_request ) {
279
298
if (!config.enabled ) {
299
+ if (!driver_request.empty ()) {
300
+ double rad = get_driver_request_steering_angle (v.get <DriverRequest>(driver_request));
301
+ v.get <LatLongActuator>(config.latlong_actuator )->set_steering_angle (rad);
302
+ }
280
303
return ;
281
304
}
282
305
@@ -305,8 +328,12 @@ struct AutoEmergencyBraking {
305
328
public:
306
329
explicit AutoEmergencyBraking (const AebConfiguration& c) : config(c) {}
307
330
308
- void control (Vehicle& v, const Sync&) {
331
+ void control (Vehicle& v, const Sync&, const std::string& driver_request ) {
309
332
if (!config.enabled ) {
333
+ if (!driver_request.empty ()) {
334
+ double acc = get_driver_request_acceleration (v.get <DriverRequest>(driver_request));
335
+ v.get <LatLongActuator>(config.latlong_actuator )->set_acceleration (acc);
336
+ }
310
337
return ;
311
338
}
312
339
auto world_sensor = v.get <ObjectSensor>(config.world_sensor );
@@ -352,7 +379,7 @@ struct AutoEmergencyBraking {
352
379
class BasicController : public Controller {
353
380
public:
354
381
BasicController (const std::string& name, const BasicConfiguration& c)
355
- : Controller(name), acc_(c.acc), aeb_(c.aeb), lka_(c.lka) {
382
+ : Controller(name), acc_(c.acc), aeb_(c.aeb), lka_(c.lka), driver_request_(c.driver_request) {
356
383
// Define the HMI of the basic controller:
357
384
namespace contact = utility::contact;
358
385
acc_.add_hmi (hmi_);
@@ -397,9 +424,9 @@ class BasicController : public Controller {
397
424
assert (veh_ != nullptr );
398
425
399
426
hmi_.update (sync .time ());
400
- acc_.control (*veh_, sync );
401
- lka_.control (*veh_, sync );
402
- aeb_.control (*veh_, sync );
427
+ acc_.control (*veh_, sync , driver_request_ );
428
+ lka_.control (*veh_, sync , driver_request_ );
429
+ aeb_.control (*veh_, sync , driver_request_ );
403
430
404
431
return sync .time ();
405
432
}
@@ -416,6 +443,7 @@ class BasicController : public Controller {
416
443
AdaptiveCruiseControl acc_;
417
444
AutoEmergencyBraking aeb_;
418
445
LaneKeepingAssistant lka_;
446
+ std::string driver_request_;
419
447
utility::ContactMap<Duration > hmi_;
420
448
};
421
449
0 commit comments