$darkmode
actuator.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_ACTUATOR_HPP_
24 #define CLOE_COMPONENT_ACTUATOR_HPP_
25 
26 #include <boost/optional.hpp> // for optional
27 #include <cloe/component.hpp> // for Component
28 #include <fable/json.hpp> // for Json
29 
30 namespace cloe {
31 
32 template <typename T = double>
33 class Actuator : public Component {
34  public:
35  using Component::Component;
36  virtual ~Actuator() noexcept = default;
37 
38  virtual void set(T a) { target_ = a; }
39  virtual bool is_set() { return static_cast<bool>(target_); }
40  virtual T get() { return *target_; }
41 
42  Json active_state() const override { return Json{{"target", target_}}; }
43 
44  Duration process(const Sync& sync) override {
45  auto t = Component::process(sync);
46  target_.reset();
47  return t;
48  }
49 
50  void reset() override {
52  target_.reset();
53  }
54 
55  protected:
56  boost::optional<T> target_;
57 };
58 
59 } // namespace cloe
60 
61 #endif // CLOE_COMPONENT_ACTUATOR_HPP_
Definition: actuator.hpp:33
void reset() override
Definition: actuator.hpp:50
Definition: sync.hpp:35
Duration process(const Sync &sync) override
Definition: actuator.hpp:44
Definition: coordinator.hpp:36
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: component.hpp:187
Json active_state() const override
Definition: actuator.hpp:42