$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 
24 #include <fable/json.hpp> // for Json
26 
27 #include <cloe/component.hpp> // for Component
28 
29 namespace cloe {
30 
31 class DriverRequest : public Component {
32  public:
33  using Component::Component;
34  DriverRequest() : Component("driver_request") {}
35  virtual ~DriverRequest() noexcept = default;
36 
40  virtual boost::optional<double> acceleration() const = 0;
41 
45  virtual bool has_acceleration() const = 0;
46 
50  virtual boost::optional<double> steering_angle() const = 0;
51 
55  virtual bool has_steering_angle() const = 0;
56 
60  fable::Json active_state() const override {
61  return fable::Json{
62  {"acceleration", acceleration()},
63  {"steering_angle", steering_angle()},
64  };
65  }
66 };
67 
72  public:
73  using DriverRequest::DriverRequest;
74  NopDriverRequest() : DriverRequest("nop_driver_request") {}
75  virtual ~NopDriverRequest() noexcept {};
76 
77  boost::optional<double> acceleration() const override { return acceleration_; }
78  bool has_acceleration() const override { return static_cast<bool>(acceleration_); }
79 
80  boost::optional<double> steering_angle() const override { return steering_angle_; }
81  bool has_steering_angle() const override { return static_cast<bool>(steering_angle_); }
82 
83  Duration process(const Sync& sync) override {
84  auto t = DriverRequest::process(sync);
85  acceleration_.reset();
86  steering_angle_.reset();
87  return t;
88  }
89 
90  void reset() override {
92  acceleration_.reset();
93  steering_angle_.reset();
94  }
95 
96  protected:
97  boost::optional<double> acceleration_{0.0};
98  boost::optional<double> steering_angle_{0.0};
99 };
100 
101 } // namespace cloe
Definition: component.hpp:143
Duration process(const Sync &sync) override
Definition: component.hpp:181
void reset() override
Definition: component.hpp:186
Definition: driver_request.hpp:31
virtual bool has_steering_angle() const =0
virtual boost::optional< double > acceleration() const =0
virtual bool has_acceleration() const =0
fable::Json active_state() const override
Definition: driver_request.hpp:60
virtual boost::optional< double > steering_angle() const =0
Definition: driver_request.hpp:71
bool has_steering_angle() const override
Definition: driver_request.hpp:81
bool has_acceleration() const override
Definition: driver_request.hpp:78
Duration process(const Sync &sync) override
Definition: driver_request.hpp:83
boost::optional< double > steering_angle() const override
Definition: driver_request.hpp:80
boost::optional< double > acceleration() const override
Definition: driver_request.hpp:77
void reset() override
Definition: driver_request.hpp:90
Definition: sync.hpp:34
std::chrono::nanoseconds Duration
Definition: cloe_fwd.hpp:36
nlohmann::json Json
Definition: fable_fwd.hpp:35