MotionLib  1.0.0
SamBuCa motion library
AxisPositionMonitor.hpp
1 /*
2 ** Copyright (C) 2023 CERN
3 **
4 ** This software is provided 'as-is', without any express or implied
5 ** warranty. In no event will the authors be held liable for any damages
6 ** arising from the use of this software.
7 **
8 ** Permission is granted to anyone to use this software for any purpose,
9 ** including commercial applications, and to alter it and redistribute it
10 ** freely, subject to the following restrictions:
11 **
12 ** 1. The origin of this software must not be misrepresented; you must not
13 ** claim that you wrote the original software. If you use this software
14 ** in a product, an acknowledgment in the product documentation would be
15 ** appreciated but is not required.
16 ** 2. Altered source versions must be plainly marked as such, and must not be
17 ** misrepresented as being the original software.
18 ** 3. This notice may not be removed or altered from any source distribution.
19 **
20 ** Created on: 2023-06-13T16:13:34
21 ** Author: Sylvain Fargier <sylvain.fargier@cern.ch>
22 */
23 
24 #ifndef AXISPOSITIONMONITOR_HPP__
25 #define AXISPOSITIONMONITOR_HPP__
26 
27 #include <memory>
28 
29 #include "../util/serialize.hpp"
30 #include "Axis.hpp"
31 #include "DeviceBase.hpp"
32 #include "PositionSensor.hpp"
33 
34 namespace smc {
35 
48 {
49 public:
50  typedef std::shared_ptr<AxisPositionMonitor> Shared;
51 
59  AxisPositionMonitor(const std::string &address,
60  const std::shared_ptr<Axis> &axis,
61  const std::shared_ptr<PositionSensor> &position);
62 
63  enum State
64  {
65  UNKNOWN,
66  ENABLED,
67  DISABLED,
68  TRIGGERED
69  };
70 
76  DeviceType type() const override;
77 
78  inline std::shared_ptr<Axis> axisDevice() const { return m_axis.lock(); }
79 
80  inline std::shared_ptr<PositionSensor> positionSensorDevice() const
81  {
82  return m_position.lock();
83  }
84 
88  virtual std::future<units::value_t> getDifference(
89  units::unit_t unit) const = 0;
90 
94  virtual std::future<units::value_t> getMaxDifference(
95  units::unit_t unit) const = 0;
96 
100  virtual std::future<State> getState() const = 0;
101 
109  virtual std::future<void> setEnabled(bool enabled) = 0;
110 
117  virtual units::value_t lastDifference(units::unit_t unit) const = 0;
118 
124  virtual State lastState() const = 0;
125 
126 protected:
127  std::weak_ptr<Axis> m_axis;
128  std::weak_ptr<PositionSensor> m_position;
129 };
130 
136 const std::string &to_string(AxisPositionMonitor::State state);
137 
144 template<>
145 AxisPositionMonitor::State from_string(const std::string &);
146 
149 } // namespace smc
150 
151 #endif
This object represent a link between an axis and a position sensor.
virtual std::future< State > getState() const =0
Get the current device state.
virtual std::future< units::value_t > getMaxDifference(units::unit_t unit) const =0
Get max difference since monitor was enabled.
virtual std::future< void > setEnabled(bool enabled)=0
Enable/disable the monitor.
DeviceType type() const override
Get device type.
virtual units::value_t lastDifference(units::unit_t unit) const =0
Get last known difference.
AxisPositionMonitor(const std::string &address, const std::shared_ptr< Axis > &axis, const std::shared_ptr< PositionSensor > &position)
Construct a new AxisPositionMonitor Device.
virtual std::future< units::value_t > getDifference(units::unit_t unit) const =0
Get current position difference between axis and positionSensor.
virtual State lastState() const =0
Get last known state.
AxisPositionMonitor::State from_string(const std::string &str)
convert string to state
const std::string & to_string(Axis::State state)
convert State to string
Definition: Axis.cpp:78
DeviceType
List of possible device types supported.
Definition: DeviceBase.hpp:52
main motion-lib namespace
Definition: Client.cpp:30