ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
turn_signal_observer.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2017-2021 German Aerospace Center (DLR).
3  * Eclipse ADORe, Automated Driving Open Research https://eclipse.org/adore
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License 2.0 which is available at
7  * http://www.eclipse.org/legal/epl-2.0.
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  * Matthias Nichting- initial API and implementation
13  ********************************************************************************/
14 #pragma once
15 #include <adore/fun/afactory.h>
16 
17 namespace adore
18 {
19  namespace fun
20  {
22  {
23  private:
35  double t0_;
39 
40  public:
42  : right_indicator_(false)
43  , left_indicator_(false)
44  , last_change_left_indicator_(std::numeric_limits<double>::lowest())
45  , last_change_right_indicator_(std::numeric_limits<double>::lowest())
46  , right_state_provided_(true)
47  , left_state_provided_(true)
50  , turned_on_automatically_left_(std::numeric_limits<double>::lowest())
51  , turned_on_automatically_right_(std::numeric_limits<double>::lowest())
52  , max_powerup_delay_(0.3)
53  , t0_(std::numeric_limits<double>::lowest())
54  {
55  extended_state_reader_ = adore::fun::FunFactoryInstance::get()->getVehicleExtendedStateReader();
56  indicator_command_reader_ = FunFactoryInstance::get()->getIndicatorCommandReader();
57  }
59  {
62  }
63  void update(double t)
64  {
66  {
67  return;
68  }
71  {
76  }
78  {
81  left_state_provided_ = false;
83  }
85  {
88  right_state_provided_ = false;
90  }
91  t0_ = t;
92  }
93  bool rightIndicatorTurnedOnWithinLastSecond(double current_time, double max_delay = 1.0)
94  {
95  if (bothIndicatorsOn(current_time))
96  {
97  return false;
98  }
99  if (right_indicator_ && (last_change_right_indicator_ + max_delay) > current_time)
100  {
101  right_state_provided_ = true;
102  return true;
103  }
104  return false;
105  }
106  bool rightIndicatorTurnedOnManuallyWithinLastSecond(double current_time, double max_delay = 1.0)
107  {
108  return rightIndicatorTurnedOnWithinLastSecond(current_time, max_delay) && turned_on_manually_right_;
109  }
110  bool leftIndicatorTurnedOnManuallyWithinLastSecond(double current_time, double max_delay = 1.0)
111  {
112  return leftIndicatorTurnedOnWithinLastSecond(current_time, max_delay) && turned_on_manually_left_;
113  }
114  bool leftIndicatorTurnedOnWithinLastSecond(double current_time, double max_delay = 1.0)
115  {
116  if (bothIndicatorsOn(current_time))
117  {
118  return false;
119  }
120  if(left_indicator_ && (last_change_left_indicator_ + max_delay) > current_time)
121  {
122  left_state_provided_ = true;
123  return true;
124  }
125  return false;
126  }
127  bool bothIndicatorsOn(double t = -1.0) const
128  {
129  if (t<0.0)t=t0_;
131  {
133  {
134  return true;
135  }
137  {
138  return true;
139  }
140  }
141  return false;
142  }
144  {
145  if (bothIndicatorsOn())
146  {
147  return false;
148  }
150  {
151  right_state_provided_ = true;
152  return true;
153  }
154  return false;
155  }
157  {
158  if (bothIndicatorsOn())
159  {
160  return false;
161  }
163  {
164  left_state_provided_ = true;
165  return true;
166  }
167  return false;
168  }
170  {
172  }
174  {
176  }
177  };
178  } // namespace fun
179 } // namespace adore
static adore::fun::AFactory * get()
Definition: afactory.h:170
Definition: turn_signal_observer.h:22
bool bothIndicatorsOn(double t=-1.0) const
Definition: turn_signal_observer.h:127
double last_change_right_indicator_
Definition: turn_signal_observer.h:27
bool newManualRightIndicatorOnEvent()
Definition: turn_signal_observer.h:173
bool left_state_provided_
Definition: turn_signal_observer.h:31
double turned_on_automatically_right_
Definition: turn_signal_observer.h:33
AFactory::TIndicatorCommandReader * indicator_command_reader_
Definition: turn_signal_observer.h:38
bool turned_on_manually_left_
Definition: turn_signal_observer.h:28
bool newRightIndicatorOnEvent()
Definition: turn_signal_observer.h:143
bool right_state_provided_
Definition: turn_signal_observer.h:30
double max_powerup_delay_
Definition: turn_signal_observer.h:34
bool rightIndicatorTurnedOnManuallyWithinLastSecond(double current_time, double max_delay=1.0)
Definition: turn_signal_observer.h:106
double turned_on_automatically_left_
Definition: turn_signal_observer.h:32
void update(double t)
Definition: turn_signal_observer.h:63
bool rightIndicatorTurnedOnWithinLastSecond(double current_time, double max_delay=1.0)
Definition: turn_signal_observer.h:93
bool leftIndicatorTurnedOnWithinLastSecond(double current_time, double max_delay=1.0)
Definition: turn_signal_observer.h:114
double last_change_left_indicator_
Definition: turn_signal_observer.h:26
bool newManualLeftIndicatorOnEvent()
Definition: turn_signal_observer.h:169
bool leftIndicatorTurnedOnManuallyWithinLastSecond(double current_time, double max_delay=1.0)
Definition: turn_signal_observer.h:110
bool right_indicator_
Definition: turn_signal_observer.h:24
~TurnSignalObserver()
Definition: turn_signal_observer.h:58
bool turned_on_manually_right_
Definition: turn_signal_observer.h:29
bool left_indicator_
Definition: turn_signal_observer.h:25
bool newLeftIndicatorOnEvent()
Definition: turn_signal_observer.h:156
double t0_
Definition: turn_signal_observer.h:35
adore::fun::AFactory::TVehicleExtendedStateReader * extended_state_reader_
Definition: turn_signal_observer.h:37
adore::fun::VehicleExtendedState extended_state_
Definition: turn_signal_observer.h:36
TurnSignalObserver()
Definition: turn_signal_observer.h:41
Definition: vehicleextendedstate.h:26
bool getIndicatorLeftOn() const
Definition: vehicleextendedstate.h:59
bool getIndicatorRightOn() const
Definition: vehicleextendedstate.h:67
Definition: com_patterns.h:68
virtual void getData(T &value)=0
virtual bool hasUpdate() const =0
Definition: areaofeffectconverter.h:20
Definition: indicatorcommand.h:25
bool getIndicatorLeftOn() const
Definition: indicatorcommand.h:35
bool getIndicatorRightOn() const
Definition: indicatorcommand.h:45