$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 #ifndef CLOE_COMPONENT_LATLONG_ACTUATOR_HPP_
27 #define CLOE_COMPONENT_LATLONG_ACTUATOR_HPP_
28 
29 #include <boost/optional.hpp> // for optional<>
30 #include <fable/json/with_boost.hpp> // for to_json
31 
32 #include <cloe/component.hpp> // for Component, Json
33 #include <cloe/component/actuator.hpp> // for Actuator
34 #include <cloe/utility/actuation_level.hpp> // for ActuationLevel
35 
36 namespace cloe {
37 
38 class LatLongActuator : public Component {
39  public:
40  using Component::Component;
41  LatLongActuator() : Component("lat_long_actuator") {}
42  virtual ~LatLongActuator() noexcept = default;
43 
48  virtual void set_acceleration(double a) {
49  target_acceleration_ = a;
50  level_.set_long();
51  }
52 
53  virtual boost::optional<double> acceleration() { return target_acceleration_; }
54 
58  virtual bool is_acceleration() const { return static_cast<bool>(target_acceleration_); }
59 
66  virtual void set_steering_angle(double a) {
67  target_steering_angle_ = a;
68  level_.set_lat();
69  }
70 
71  virtual boost::optional<double> steering_angle() { return target_steering_angle_; }
72 
76  virtual bool is_steering_angle() const { return static_cast<bool>(target_steering_angle_); }
77 
83  utility::ActuationLevel actuation_level() const { return level_; }
84 
91  Json active_state() const override {
92  return Json{
93  {"target_acceleration", target_acceleration_},
94  {"target_steering_angle", target_steering_angle_},
95  {"actuation_label", level_.to_human_cstr()},
96  };
97  }
98 
99  Duration process(const Sync& sync) override {
100  auto t = Component::process(sync);
101  target_acceleration_.reset();
102  target_steering_angle_.reset();
103  level_.set_none();
104  return t;
105  }
106 
107  void reset() override {
109  target_acceleration_.reset();
110  target_steering_angle_.reset();
111  level_.set_none();
112  }
113 
114  protected:
116  boost::optional<double> target_acceleration_;
117  boost::optional<double> target_steering_angle_;
118 };
119 
120 class LongActuator : public Actuator<double> {
121  public:
122  using Actuator::Actuator;
123  LongActuator() : Actuator("long_actuator") {}
124  virtual ~LongActuator() noexcept = default;
125 };
126 
127 class LatActuator : public Actuator<double> {
128  public:
129  using Actuator::Actuator;
130  LatActuator() : Actuator("lat_actuator") {}
131  virtual ~LatActuator() noexcept = default;
132 };
133 
134 } // namespace cloe
135 
136 #endif // CLOE_COMPONENT_LATLONG_ACTUATOR_HPP_
Definition: actuator.hpp:33
virtual void set_steering_angle(double a)
Definition: latlong_actuator.hpp:66
Duration process(const Sync &sync) override
Definition: latlong_actuator.hpp:99
virtual void set_acceleration(double a)
Definition: latlong_actuator.hpp:48
Json active_state() const override
Definition: latlong_actuator.hpp:91
Definition: sync.hpp:35
Definition: coordinator.hpp:36
Definition: latlong_actuator.hpp:127
Definition: latlong_actuator.hpp:120
Duration process(const Sync &sync) override
Definition: component.hpp:182
std::chrono::nanoseconds Duration
Definition: duration.hpp:45
Definition: component.hpp:144
void reset() override
Definition: latlong_actuator.hpp:107
virtual bool is_acceleration() const
Definition: latlong_actuator.hpp:58
Definition: actuation_level.hpp:50
utility::ActuationLevel actuation_level() const
Definition: latlong_actuator.hpp:83
void reset() override
Definition: component.hpp:187
virtual bool is_steering_angle() const
Definition: latlong_actuator.hpp:76
Definition: latlong_actuator.hpp:38