ifw-fcf  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
motorLcsIf.hpp
Go to the documentation of this file.
1 
9 #ifndef FCF_DEVMGR_DEVICE_MOTOR_IF_HPP
10 #define FCF_DEVMGR_DEVICE_MOTOR_IF_HPP
11 
12 // System headers
13 #include <unordered_map>
14 
15 // Third party headers
16 #include <yaml-cpp/yaml.h>
17 
21 
22 #include <Fcfif.hpp>
23 #include <rad/mal/publisher.hpp>
24 
25 namespace fcf::devmgr::motor {
26 
35  public:
37  virtual ~MotorControllerData();
38 
39  inline double GetActualPos() const;
40  inline void SetActualPos(double position);
41  inline double GetPosError() const;
42  inline void SetPosError(double pos_error);
43  inline double GetActualVel() const;
44  inline void SetActualVel(double velocity);
45  inline double GetTargetPos() const;
46  inline void SetTargetPos(double position);
47  inline double GetTargetVel() const;
48  inline void SetTargetVel(double velocity);
49  inline double GetScaleFactor() const;
50  inline void SetScaleFactor(double scale);
51 
52  inline bool GetBrakeFlag() const;
53  inline void SetBrakeFlag(bool flag);
54 
55  inline bool GetEnableFlag() const;
56  inline void SetEnableFlag(bool flag);
57 
58  inline bool GetLockFlag() const;
59  inline void SetLockFlag(bool flag);
60 
61  inline int GetMode() const;
62  inline void SetMode(int mode);
63 
64  inline bool GetReadyFlag() const;
65  inline void SetReadyFlag(bool flag);
66 
67  inline bool GetInPositionFlag() const;
68  inline void SetInPositionFlag(bool flag);
69 
70  inline short GetInfoData1() const;
71  inline void SetInfoData1(short info);
72 
73  inline short GetInfoData2() const;
74  inline void SetInfoData2(short info);
75 
76  inline bool GetSignalFlag(Signal signal) const;
77  inline void SetSignalFlag(Signal signal, bool flag);
78 
79  inline virtual std::string GetErrorText() const;
80  inline virtual std::string GetSubstateStr() const;
81 
82  void SetData(const MotorControllerData& data);
83 
84  protected:
85  double m_target_pos;
86  double m_actual_pos;
87  double m_pos_error;
88  double m_actual_vel;
89  double m_target_vel;
91  bool m_brake;
92  bool m_enabled;
93  bool m_locked;
94  int m_mode;
95  bool m_ready;
99  std::vector<bool> m_signals;
100  };
101 
115  template<typename TOPIC_TYPE>
117  {
118  public:
119  enum {
133  STAT_MODE = 14,
148  };
149 
150  public:
158  MotorLcsIf(std::shared_ptr<fcf::devmgr::common::IDeviceConfig> config,
159  fcf::devmgr::common::DataContext& data_ctx, bool initialise = true);
160 
164  virtual ~MotorLcsIf() {};
165 
172  void MoveAbs(double position, double velocity);
173 
180  void MoveRel(double position, double velocity);
181 
189  void MoveVel(double velocity);
190 
195  virtual bool IsDisabling();
196 
201  bool IsMoving();
202 
207  bool IsStandstill();
208 
218  virtual void ReadStatus(MotorControllerData& status);
219 
231  void Listener(fcf::common::VectorVariant& params);
232 
238  virtual std::string GetRpcError(const short error_code) const;
239 
240 
241  protected:
242 
254  void StoreAttribute(const std::string key,
255  const fcf::common::Variant& value,
256  bool publish,
257  int attribute);
258 
267  void PublishPosition(const fcf::common::Variant& value,
268  int attribute);
269 
270  private:
271  void MovePos(double position, double velocity, std::string move_type=RPC_MOVE_ABS);
272 
273  protected:
274 
275  std::unique_ptr<rad::cii::Publisher<fcfif::MotorPositionTopic>> m_motor_publisher;
276  std::unique_ptr<rad::cii::Publisher<TOPIC_TYPE>> m_publisher;
277 
278  private:
280  static std::timed_mutex m_mutex;
281  //std::unique_ptr<rad::cii::Publisher<fcfif::MotorTopicUnion>> m_publisher;
282 
283 
284 
285  };
286 
287 }
288 
289 #include "motorLcsIf.ipp"
290 
291 #endif //FCF_DEVMGR_DEVICE_MOTOR_IF_HPP
double m_target_pos
Definition: motorLcsIf.hpp:85
virtual ~MotorControllerData()
Definition: motorLcsIf.cpp:26
void PublishPosition(const fcf::common::Variant &value, int attribute)
Publish Position.
virtual std::string GetSubstateStr() const
int m_info_data2
Definition: motorLcsIf.hpp:98
void MoveVel(double velocity)
Executes the MoveVel RPC.
virtual bool IsDisabling()
Check if controller is disabling the motor.
MotorLcsIf(std::shared_ptr< fcf::devmgr::common::IDeviceConfig > config, fcf::devmgr::common::DataContext &data_ctx, bool initialise=true)
MotorLcsIf constructor.
bool IsMoving()
Check if motor is moving.
The DeviceControllerData struct.
Definition: deviceLcsIf.hpp:31
void MoveAbs(double position, double velocity)
Executes the MoveAbs RPC.
double m_pos_error
Definition: motorLcsIf.hpp:87
bool m_enabled
Definition: motorLcsIf.hpp:92
void StoreAttribute(const std::string key, const fcf::common::Variant &value, bool publish, int attribute)
Store the updated into the DB.
void SetSignalFlag(Signal signal, bool flag)
Definition: motorLcsIf.hpp:121
void MoveRel(double position, double velocity)
Executes the MoveRel RPC.
double m_target_vel
Definition: motorLcsIf.hpp:89
int m_info_data1
Definition: motorLcsIf.hpp:97
double m_scale_factor
Definition: motorLcsIf.hpp:90
bool GetSignalFlag(Signal signal) const
Signal
Definition: motorConfig.hpp:173
double m_actual_vel
Definition: motorLcsIf.hpp:88
void SetData(const MotorControllerData &data)
Definition: motorLcsIf.cpp:29
virtual std::string GetRpcError(const short error_code) const
constexpr auto RPC_MOVE_ABS
Definition: motorConfig.hpp:110
bool m_ready
Definition: motorLcsIf.hpp:95
Motor Local Control System (LCS) Interface (IF) class.
Definition: motorLcsIf.hpp:116
virtual void ReadStatus(MotorControllerData &status)
Read status from the controller.
DataContext class header file.
The MotorControllerData struct.
Definition: motorLcsIf.hpp:34
bool m_locked
Definition: motorLcsIf.hpp:93
bool IsStandstill()
Check if motor is on.
Definition: dataContext.hpp:81
virtual ~MotorLcsIf()
Default destructor.
Definition: motorLcsIf.hpp:164
void Listener(fcf::common::VectorVariant &params)
Callback to manage changes on the monitored items.
bool m_brake
Definition: motorLcsIf.hpp:91
deviceLcsIf class header file.
MotorControllerData()
Definition: motorLcsIf.cpp:4
bool m_in_position
Definition: motorLcsIf.hpp:96
double m_actual_pos
Definition: motorLcsIf.hpp:86
Definition: motorLcsIf.hpp:120
Definition: motorLcsIf.hpp:124
Definition: motorLcsIf.hpp:133
std::unique_ptr< rad::cii::Publisher< fcfif::MotorPositionTopic > > m_motor_publisher
Definition: motorLcsIf.hpp:275
MotorConfig class header file.
Definition: motorLcsIf.hpp:123
int m_mode
Definition: motorLcsIf.hpp:94
std::vector< bool > m_signals
Definition: motorLcsIf.hpp:99
virtual std::string GetErrorText() const
Definition: deviceLcsIf.hpp:72
std::unique_ptr< rad::cii::Publisher< TOPIC_TYPE > > m_publisher
Definition: motorLcsIf.hpp:276