$darkmode
latlong_actuator.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  */
25 #pragma once
26 
27 #include <boost/optional.hpp> // for optional<>
28 #include <fable/json.hpp> // for Json
29 #include <fable/utility/boost_optional.hpp> // for to_json
30 
31 #include <cloe/component.hpp> // for Component
32 #include <cloe/component/actuator.hpp> // for Actuator
33 #include <cloe/utility/actuation_level.hpp> // for ActuationLevel
34 
35 namespace cloe {
36 
37 class LatLongActuator : public Component {
38  public:
39  using Component::Component;
40  LatLongActuator() : Component("lat_long_actuator") {}
41  virtual ~LatLongActuator() noexcept = default;
42 
47  virtual void set_acceleration(double a) {
48  target_acceleration_ = a;
49  level_.set_long();
50  }
51 
52  virtual boost::optional<double> acceleration() { return target_acceleration_; }
53 
57  virtual bool is_acceleration() const { return static_cast<bool>(target_acceleration_); }
58 
65  virtual void set_steering_angle(double a) {
66  target_steering_angle_ = a;
67  level_.set_lat();
68  }
69 
70  virtual boost::optional<double> steering_angle() { return target_steering_angle_; }
71 
75  virtual bool is_steering_angle() const { return static_cast<bool>(target_steering_angle_); }
76 
82  utility::ActuationLevel actuation_level() const { return level_; }
83 
90  fable::Json active_state() const override {
91  return fable::Json{
92  {"target_acceleration", target_acceleration_},
93  {"target_steering_angle", target_steering_angle_},
94  {"actuation_label", level_.to_human_cstr()},
95  };
96  }
97 
98  Duration process(const Sync& sync) override {
99  auto t = Component::process(sync);
100  target_acceleration_.reset();
101  target_steering_angle_.reset();
102  level_.set_none();
103  return t;
104  }
105 
106  void reset() override {
108  target_acceleration_.reset();
109  target_steering_angle_.reset();
110  level_.set_none();
111  }
112 
113  protected:
115  boost::optional<double> target_acceleration_;
116  boost::optional<double> target_steering_angle_;
117 };
118 
119 class LongActuator : public Actuator<double> {
120  public:
121  using Actuator::Actuator;
122  LongActuator() : Actuator("long_actuator") {}
123  virtual ~LongActuator() noexcept = default;
124 };
125 
126 class LatActuator : public Actuator<double> {
127  public:
128  using Actuator::Actuator;
129  LatActuator() : Actuator("lat_actuator") {}
130  virtual ~LatActuator() noexcept = default;
131 };
132 
133 } // namespace cloe
Definition: actuator.hpp:32
Definition: component.hpp:143
Duration process(const Sync &sync) override
Definition: component.hpp:181
void reset() override
Definition: component.hpp:186
Definition: latlong_actuator.hpp:126
Definition: latlong_actuator.hpp:37
virtual void set_steering_angle(double a)
Definition: latlong_actuator.hpp:65
virtual void set_acceleration(double a)
Definition: latlong_actuator.hpp:47
virtual bool is_acceleration() const
Definition: latlong_actuator.hpp:57
Duration process(const Sync &sync) override
Definition: latlong_actuator.hpp:98
void reset() override
Definition: latlong_actuator.hpp:106
virtual bool is_steering_angle() const
Definition: latlong_actuator.hpp:75
utility::ActuationLevel actuation_level() const
Definition: latlong_actuator.hpp:82
fable::Json active_state() const override
Definition: latlong_actuator.hpp:90
Definition: latlong_actuator.hpp:119
Definition: sync.hpp:34
Definition: actuation_level.hpp:48
std::chrono::nanoseconds Duration
Definition: cloe_fwd.hpp:36
nlohmann::json Json
Definition: fable_fwd.hpp:35