ifw  0.0.1-dev
 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 DEVMGR_DEVICE_MOTOR_IF_HPP
10 #define 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 
18 #include <devmgr/common/deviceLcsIf.hpp>
19 #include <devmgr/devices/motorConfig.hpp>
20 #include <devmgr/common/dataContext.hpp>
21 
22 namespace devmgr {
23  namespace motor {
24 
25 
33  struct MotorControllerData : devmgr::common::DeviceControllerData {
34  public:
36  virtual ~MotorControllerData();
37 
38  inline double GetActualPos() const;
39  inline void SetActualPos(double position);
40  inline double GetPosError() const;
41  inline void SetPosError(double pos_error);
42  inline double GetActualVel() const;
43  inline void SetActualVel(double velocity);
44  inline double GetTargetPos() const;
45  inline void SetTargetPos(double position);
46  inline double GetTargetVel() const;
47  inline void SetTargetVel(double velocity);
48  inline double GetScaleFactor() const;
49  inline void SetScaleFactor(double scale);
50 
51  inline bool GetBrakeFlag() const;
52  inline void SetBrakeFlag(bool flag);
53 
54  inline bool GetEnableFlag() const;
55  inline void SetEnableFlag(bool flag);
56 
57  inline bool GetLockFlag() const;
58  inline void SetLockFlag(bool flag);
59 
60  inline int GetMode() const;
61  inline void SetMode(int mode);
62 
63  inline bool GetReadyFlag() const;
64  inline void SetReadyFlag(bool flag);
65 
66  inline bool GetInPositionFlag() const;
67  inline void SetInPositionFlag(bool flag);
68 
69  inline short GetInfoData1() const;
70  inline void SetInfoData1(short info);
71 
72  inline short GetInfoData2() const;
73  inline void SetInfoData2(short info);
74 
75  inline bool GetSignalFlag(Signal signal) const;
76  inline void SetSignalFlag(Signal signal, bool flag);
77 
78  inline std::string GetErrorText() const;
79 
80  void SetData(const MotorControllerData& data);
81 
82  protected:
83  double m_target_pos;
84  double m_actual_pos;
85  double m_pos_error;
86  double m_actual_vel;
87  double m_target_vel;
88  double m_scale_factor;
89  bool m_brake;
90  bool m_enabled;
91  bool m_locked;
92  int m_mode;
93  bool m_ready;
94  bool m_in_position;
95  int m_info_data1;
96  int m_info_data2;
97  std::vector<bool> m_signals;
98  };
99 
113  class MotorLcsIf : public devmgr::common::DeviceLcsIf
114  {
115 
116  enum {
117  STAT_LOCAL = 1,
118  STAT_ERROR = 2,
119  STAT_HW_STATUS = 3,
120  STAT_STATE = 4,
121  STAT_SUBSTATE = 5,
122  STAT_ACTUAL_POS = 6,
123  STAT_TARGET_POS = 7,
124  STAT_POS_ERROR = 8,
125  STAT_ACTUAL_VEL = 9,
126  STAT_TARGET_VEL = 10,
127  STAT_AXIS_BRAKE = 11,
128  STAT_AXIS_ENABLE = 12,
129  STAT_AXIS_LOCK = 13,
130  STAT_MODE = 14,
131  STAT_AXIS_READY = 15,
132  STAT_AXIS_INPOS = 16,
133  STAT_AXIS_INFO1 = 17,
134  STAT_AXIS_INFO2 = 18,
135  STAT_INITIALISED = 19,
136  STAT_INIT_STEP = 20,
137  STAT_INIT_ACTION = 21,
138  STAT_SIGNAL_LSTOP = 22,
139  STAT_SIGNAL_LHW = 23,
140  STAT_SIGNAL_REF = 24,
141  STAT_SIGNAL_INDEX = 25,
142  STAT_SIGNAL_UHW = 26,
143  STAT_SIGNAL_USTOP = 27
144  };
145 
146  public:
152  MotorLcsIf(std::shared_ptr<devmgr::common::IDeviceConfig> config,
153  devmgr::common::DataContext& data_ctx);
154 
159  virtual bool IsReady();
160 
165  virtual bool IsNotReady() ;
166 
171  virtual bool IsOperational() ;
172 
179  void ReadConfig();
180 
187  void MoveAbs(double position, double velocity);
188 
195  void MoveRel(double position, double velocity);
196 
204  void MoveVel(double velocity);
205 
210  virtual bool IsDisabling() ;
211 
216  bool IsMoving() ;
217 
222  bool IsStandstill() ;
223 
228  bool IsHwFailure();
229 
239  virtual void ReadStatus(MotorControllerData& status);
240 
250  void StartMonitoring();
251 
259  void StopMonitoring();
260 
272  void Listener(fcf::common::VectorVariant& params);
273 
279  virtual std::string GetRpcError(const short error_code) const;
280 
285  virtual std::string GetHwError(int& error_code, const bool update = false);
286 
287  private:
288 
296  void PublishState(const fcf::common::Variant& value);
297 
305  void PublishSubstate(const fcf::common::Variant& value);
306 
318  void StoreAttribute(const std::string key,
319  const fcf::common::Variant& value,
320  bool publish,
321  int attribute);
322 
330  void PublishPosition(const fcf::common::Variant& value,
331  int attribute);
332 
333  protected:
337  std::unordered_map<std::string, short> m_status_map;
338 
341  std::vector<std::string> m_monitor_vector;
342  private:
343  devmgr::common::DataContext& m_data_ctx;
344  static std::timed_mutex m_mutex;
345 
346  std::shared_ptr<MotorConfig> m_motor_config;
347 
348 
349  void MovePos(double position, double velocity, std::string move_type=RPC_MOVE_ABS);
350  };
351  }
352 }
353 
354 #include "motorLcsIf.inline"
355 
356 #endif //DEVMGR_DEVICE_MOTOR_IF_HPP
std::vector< std::string > m_monitor_vector
Definition: motorLcsIf.hpp:341
double value
Definition: easylogging++.h:814
virtual bool IsReady()
Check if controller is in Standby/Ready state.
Definition: motorLcsIf.cpp:406
Device Local Control System (LCS) Interface (IF) class.
Definition: deviceLcsIf.hpp:69
const std::string RPC_MOVE_ABS
Definition: motorConfig.hpp:112
void StopMonitoring()
Stop monitoring of controller attributes.
Definition: motorLcsIf.cpp:601
virtual std::string GetHwError(int &error_code, const bool update=false)
Get error message.
Definition: motorLcsIf.cpp:770
std::string GetErrorText() const
void SetData(const MotorControllerData &data)
Definition: motorLcsIf.cpp:56
int m_mode
Definition: motorLcsIf.hpp:92
double m_target_vel
Definition: motorLcsIf.hpp:87
The DeviceControllerData struct.
Definition: deviceLcsIf.hpp:30
Signal
Definition: motorConfig.hpp:187
bool IsMoving()
Check if motor is moving.
Definition: motorLcsIf.cpp:442
virtual bool IsDisabling()
Check if controller is disabling the motor.
Definition: motorLcsIf.cpp:330
double m_scale_factor
Definition: motorLcsIf.hpp:88
bool m_ready
Definition: motorLcsIf.hpp:93
bool m_enabled
Definition: motorLcsIf.hpp:90
double m_actual_pos
Definition: motorLcsIf.hpp:84
void SetActualPos(double position)
void SetSignalFlag(Signal signal, bool flag)
optional double pos_error
Definition: topics.proto:64
bool IsHwFailure()
Check if motor is in hardware error.
Definition: motorLcsIf.cpp:479
double m_actual_vel
Definition: motorLcsIf.hpp:86
void MoveVel(double velocity)
Executes the MoveVel RPC.
Definition: motorLcsIf.cpp:339
bool m_in_position
Definition: motorLcsIf.hpp:94
bool IsStandstill()
Check if motor is on.
Definition: motorLcsIf.cpp:461
void SetActualVel(double velocity)
virtual ~MotorControllerData()
Definition: motorLcsIf.cpp:53
void Listener(fcf::common::VectorVariant &params)
Callback to manage changes on the monitored items.
Definition: motorLcsIf.cpp:612
bool m_brake
Definition: motorLcsIf.hpp:89
virtual void ReadStatus(MotorControllerData &status)
Read status from the controller.
Definition: motorLcsIf.cpp:497
Definition: dataContext.hpp:73
int m_info_data2
Definition: motorLcsIf.hpp:96
void SetPosError(double pos_error)
int m_info_data1
Definition: motorLcsIf.hpp:95
std::vector< bool > m_signals
Definition: motorLcsIf.hpp:97
virtual std::string GetRpcError(const short error_code) const
Definition: motorLcsIf.cpp:741
virtual bool IsNotReady()
Check if controller is in Standby/NotReady state.
Definition: motorLcsIf.cpp:386
void SetTargetVel(double velocity)
virtual bool IsOperational()
Check if controller is in Operational.
Definition: motorLcsIf.cpp:426
optional int32 error_code
Definition: topics.proto:14
bool GetSignalFlag(Signal signal) const
double m_pos_error
Definition: motorLcsIf.hpp:85
void ReadConfig()
Read the configuration.
Definition: motorLcsIf.cpp:220
void MoveAbs(double position, double velocity)
Executes the MoveAbs RPC.
Definition: motorLcsIf.cpp:268
void StartMonitoring()
Start monitoring of controller attributes.
Definition: motorLcsIf.cpp:590
double m_target_pos
Definition: motorLcsIf.hpp:83
MotorLcsIf(std::shared_ptr< devmgr::common::IDeviceConfig > config, devmgr::common::DataContext &data_ctx)
MotorLcsIf constructor.
void MoveRel(double position, double velocity)
Executes the MoveRel RPC.
Definition: motorLcsIf.cpp:273
void SetTargetPos(double position)
MotorControllerData()
Definition: motorLcsIf.cpp:33
std::unordered_map< std::string, short > m_status_map
Definition: motorLcsIf.hpp:337
bool m_locked
Definition: motorLcsIf.hpp:91