$darkmode
driver_request.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2022 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  */
22 #pragma once
23 #ifndef CLOE_COMPONENT_DRIVER_REQUEST_HPP_
24 #define CLOE_COMPONENT_DRIVER_REQUEST_HPP_
25 
26 #include <cloe/component.hpp> // for Component, Json
27 
28 namespace cloe {
29 
30 class DriverRequest : public Component {
31  public:
32  using Component::Component;
33  DriverRequest() : Component("driver_request") {}
34  virtual ~DriverRequest() noexcept = default;
35 
39  virtual boost::optional<double> acceleration() const = 0;
40 
44  virtual bool has_acceleration() const = 0;
45 
49  virtual boost::optional<double> steering_angle() const = 0;
50 
54  virtual bool has_steering_angle() const = 0;
55 
59  Json active_state() const override {
60  return Json{
61  {"acceleration", acceleration()},
62  {"steering_angle", steering_angle()},
63  };
64  }
65 };
66 
71  public:
72  using DriverRequest::DriverRequest;
73  NopDriverRequest() : DriverRequest("nop_driver_request") {}
74  virtual ~NopDriverRequest() noexcept {};
75 
76  boost::optional<double> acceleration() const override { return acceleration_; }
77  bool has_acceleration() const override { return static_cast<bool>(acceleration_); }
78 
79  boost::optional<double> steering_angle() const override { return steering_angle_; }
80  bool has_steering_angle() const override { return static_cast<bool>(steering_angle_); }
81 
82  Duration process(const Sync& sync) override {
83  auto t = DriverRequest::process(sync);
84  acceleration_.reset();
85  steering_angle_.reset();
86  return t;
87  }
88 
89  void reset() override {
91  acceleration_.reset();
92  steering_angle_.reset();
93  }
94 
95  protected:
96  boost::optional<double> acceleration_{0.0};
97  boost::optional<double> steering_angle_{0.0};
98 };
99 
100 } // namespace cloe
101 
102 #endif // CLOE_COMPONENT_DRIVER_REQUEST_HPP_
virtual boost::optional< double > acceleration() const =0
Duration process(const Sync &sync) override
Definition: driver_request.hpp:82
virtual bool has_steering_angle() const =0
virtual bool has_acceleration() const =0
bool has_acceleration() const override
Definition: driver_request.hpp:77
boost::optional< double > acceleration() const override
Definition: driver_request.hpp:76
Definition: driver_request.hpp:70
Definition: sync.hpp:35
void reset() override
Definition: driver_request.hpp:89
Definition: driver_request.hpp:30
Definition: coordinator.hpp:36
Duration process(const Sync &sync) override
Definition: component.hpp:182
std::chrono::nanoseconds Duration
Definition: duration.hpp:45
bool has_steering_angle() const override
Definition: driver_request.hpp:80
Definition: component.hpp:144
Json active_state() const override
Definition: driver_request.hpp:59
virtual boost::optional< double > steering_angle() const =0
boost::optional< double > steering_angle() const override
Definition: driver_request.hpp:79
void reset() override
Definition: component.hpp:187