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