ifw-fcf  5.0.0-pre2
motorConfig.hpp
Go to the documentation of this file.
1 
10 #ifndef FCF_DEVMGR_DEVICE_MOTOR_CONFIG_HPP
11 #define FCF_DEVMGR_DEVICE_MOTOR_CONFIG_HPP
12 
13 // System headers
14 #include <string>
15 #include <unordered_map>
16 
17 // Third party headers
18 #include <yaml-cpp/yaml.h>
19 
20 #include <utils/bat/logger.hpp>
21 
26 
27 
28 namespace fcf::devmgr::motor {
29 
30  constexpr auto LOGGER_NAME = "motor";
31 
32  // Constants for internal mapping
33  constexpr auto CI_BRAKE = "brake";
34  constexpr auto CI_BACKLASH = "backlash";
35  constexpr auto CI_AXIS_TYPE = "axis_type";
36 
37  constexpr auto CI_CHECK_INPOS = "check_inpos";
38  constexpr auto CI_LOCK = "lock";
39  constexpr auto CI_LOCK_POS = "lock_pos";
40  constexpr auto CI_LOCK_TOLERANCE = "lock_tolerance";
41  constexpr auto CI_DISABLE = "disable";
42 
43  constexpr auto CI_ACTIVE_LOW_BRAKE = "low_brake";
44  constexpr auto CI_ACTIVE_LOW_INPOS = "low_inpos";
45  constexpr auto CI_ACTIVE_LOW_STOP = "active_low_lstop";
46  constexpr auto CI_ACTIVE_LOW_LHW = "active_low_lhw";
47  constexpr auto CI_ACTIVE_LOW_REF = "active_low_ref";
48  constexpr auto CI_ACTIVE_LOW_INDEX = "active_low_index";
49  constexpr auto CI_ACTIVE_LOW_UHW = "active_low_uhw";
50  constexpr auto CI_ACTIVE_LOW_USTOP = "active_low_ustop";
51 
52  constexpr auto CI_EXEC_PRE_INIT = "exec_pre_init";
53  constexpr auto CI_EXEC_POST_INIT = "exec_post_init";
54  constexpr auto CI_EXEC_PRE_MOVE = "exec_pre_move";
55  constexpr auto CI_EXEC_POST_MOVE = "exec_post_move";
56 
57  constexpr auto CI_INITIALISATION = "initialisation";
58  constexpr auto CI_INIT_SEQUENCE = "sequence";
59  constexpr auto CI_INIT_ACTION = "step";
60  constexpr auto CI_INIT_VALUE_1 = "value1";
61  constexpr auto CI_INIT_VALUE_2 = "value2";
62 
63 
64  // WS configuration keywords
65  // These configuration only matters for WS level
66 
67  constexpr int CI_AXIS_TYPE_LINEAR = 1;
68  constexpr int CI_AXIS_TYPE_CIRCULAR = 2;
69  constexpr int CI_AXIS_TYPE_CIRCULAR_OPT = 3;
70 
71  constexpr auto CI_AXIS_TYPE_LINEAR_STR = "LINEAR";
72  constexpr auto CI_AXIS_TYPE_CIRCULAR_STR = "CIRCULAR";
73  constexpr auto CI_AXIS_TYPE_CIRCULAR_OPT_STR = "CIRCULAR_OPT";
74 
75  constexpr int CI_AXIS_MODE_INPOS = 0;
76  constexpr int CI_AXIS_MODE_INVEL = 1;
77 
78  constexpr auto CI_AXIS_MODE_INPOS_STR = "InPosition";
79  constexpr auto CI_AXIS_MODE_INVEL_STR = "InVelocity";
80 
81  const std::unordered_map<int, std::string> AxisModeMap = {
84  };
85 
86  constexpr int CI_MAX_INIT_STEPS = 10;
87 
88  constexpr auto CI_INIT_ACTION_END = "END";
89  constexpr auto CI_INIT_ACTION_FIND_INDEX = "FIND_INDEX";
90  constexpr auto CI_INIT_ACTION_FIND_REF_LE = "FIND_REF_LE";
91  constexpr auto CI_INIT_ACTION_FIND_REF_UE = "FIND_REF_UE";
92  constexpr auto CI_INIT_ACTION_FIND_LHW = "FIND_LHW";
93  constexpr auto CI_INIT_ACTION_FIND_UHW = "FIND_UHW";
94  constexpr auto CI_INIT_ACTION_DELAY = "DELAY";
95  constexpr auto CI_INIT_ACTION_MOVE_ABS = "MOVE_ABS";
96  constexpr auto CI_INIT_ACTION_MOVE_REL = "MOVE_REL";
97  constexpr auto CI_INIT_ACTION_CALIB_ABS = "CALIB_ABS";
98  constexpr auto CI_INIT_ACTION_CALIB_REL = "CALIB_REL";
99  constexpr auto CI_INIT_ACTION_CALIB_SWITCH = "CALIB_SWITCH";
100 
101 
102  // encoders are used only at the WS level
103 
104  constexpr auto CI_STAT_SCALE_FACTOR = "scale_factor";
105  constexpr auto CI_STAT_BACKLASH_STEP = "backlash_step";
106  constexpr auto CI_STAT_MODE = "mode";
107  constexpr auto CI_STAT_INIT_STEP = "init_step";
108  constexpr auto CI_STAT_INIT_ACTION = "init_action";
109  constexpr auto CI_STAT_AXIS_READY = "axis_ready";
110  constexpr auto CI_STAT_AXIS_ENABLE = "axis_enable";
111  constexpr auto CI_STAT_AXIS_INPOS = "axis_inposition";
112  constexpr auto CI_STAT_AXIS_LOCK = "axis_lock";
113  constexpr auto CI_STAT_AXIS_BRAKE = "axis_brake";
114  constexpr auto CI_STAT_AXIS_STOP_NEG = "axis_stop_pos";
115  constexpr auto CI_STAT_AXIS_STOP_POS = "axis_stop_neg";
116  constexpr auto CI_STAT_AXIS_INFO_DATA_1 = "axis_info_data1";
117  constexpr auto CI_STAT_AXIS_INFO_DATA_2 = "axis_info_data2";
118 
119  constexpr auto CI_STAT_SIGNAL_LSTOP = "signal_lstop";
120  constexpr auto CI_STAT_SIGNAL_LHW = "signal_lhw";
121  constexpr auto CI_STAT_SIGNAL_REF = "signal_ref";
122  constexpr auto CI_STAT_SIGNAL_INDEX = "signal_index";
123  constexpr auto CI_STAT_SIGNAL_UHW = "signal_uhw";
124  constexpr auto CI_STAT_SIGNAL_USTOP = "signal_ustop";
125 
126  enum class Signal : short {LSTOP = 0,
127  LHW = 1,
128  REF = 2,
129  INDEX = 3,
130  UHW = 4,
131  USTOP = 5};
132 
133  constexpr auto FITS_PARAM_BRAKE = "BRAKE";
134  constexpr auto FITS_PARAM_LOCK = "LOCK";
135 
136  // Map of Axis type to do the converstion between strings to numbers
137  const std::unordered_map<std::string, int> AxisTypeMap = {
141  };
142 
143  enum {
156  };
157 
158  // @TODO: replaced by boost bimaps
159  // Tried with boost bimap but I've got hundred of errors.
160  // I added temporaly two maps.
161 
162  // Map of motor initialisation steps
163  const std::unordered_map<std::string, int> InitActionsMap = {
176  };
177 
178  // Map of motor initialisation steps
179  const std::unordered_map<int, std::string> InitActions2Map = {
192  };
193 
194  struct InitAction {
195  int id;
196  double value1;
197  double value2;
198 
199  InitAction():id(0), value1(0.0), value2(0.0) {}
200  };
201 
202  class Sensor;
211  {
212  friend class Sensor;
213 
214 
215  public:
221  MotorConfig(const std::string filename,
222  const std::string name);
223 
228  MotorConfig(const std::string name);
229 
233  virtual ~MotorConfig() = default;
234 
235 
243  virtual void Init();
257  virtual void GetConfig(protocol::base::VectorVariant& params) const override;
258 
259 
269  virtual void GetConfigList(utils::bat::DbVector& cfg_list,
270  std::string prefix) const override;
271 
272 
277  inline int GetNumberOfInitSteps() const noexcept {return m_init_sequence.size();};
278 
279 
284  double GetScaleFactor() const override;
285 
293  void SetScaleFactor(double scale);
294 
295  protected:
296  // Map of motor init step to do the conversion between strings to numbers
297  std::vector<InitAction> m_init_sequence;
298  double m_scale_factor{1.0};
299 
300  private:
301 
302  log4cplus::Logger m_logger;
303 
304  };
305 
306 }
307 
308 
309 #endif //FCF_DEVMGR_DEVICE_MOTOR_CONFIG_H
m_logger(log4cplus::Logger::getInstance(LOGGER_NAME))
Definition: {{cookiecutter.device_name}}.cpp:32
Motor Base Configuration class.
Definition: motorBaseConfig.hpp:114
Motor Configuration class.
Definition: motorConfig.hpp:211
virtual void Init()
Read the configuration.
Definition: motorConfig.cpp:41
int GetNumberOfInitSteps() const noexcept
Get number of initialisations steps.
Definition: motorConfig.hpp:277
void SetScaleFactor(double scale)
Set Scale Factor.
Definition: motorConfig.cpp:164
MotorConfig(const std::string filename, const std::string name)
MotorConfig constructor.
Definition: motorConfig.cpp:25
virtual void GetConfig(protocol::base::VectorVariant &params) const override
Obtain the list of configuration parameters.
Definition: motorConfig.cpp:85
double m_scale_factor
Definition: motorConfig.hpp:298
virtual void GetConfigList(utils::bat::DbVector &cfg_list, std::string prefix) const override
Get configuration list.
Definition: motorConfig.cpp:129
std::vector< InitAction > m_init_sequence
Definition: motorConfig.hpp:297
friend class Sensor
Definition: motorConfig.hpp:212
double GetScaleFactor() const override
Definition: motorConfig.cpp:159
virtual ~MotorConfig()=default
MotorConfig destructor.
DataContext class header file.
MotorConfig class header file.
MotorHwErrors header file.
LampRpcErrors header file.
Definition: motor.hpp:18
constexpr auto CI_AXIS_TYPE
Definition: motorConfig.hpp:35
constexpr auto CI_STAT_INIT_STEP
Definition: motorConfig.hpp:107
constexpr auto CI_AXIS_TYPE_LINEAR_STR
Definition: motorConfig.hpp:71
constexpr auto CI_STAT_AXIS_STOP_POS
Definition: motorConfig.hpp:115
constexpr auto CI_INIT_VALUE_2
Definition: motorConfig.hpp:61
constexpr auto CI_AXIS_TYPE_CIRCULAR_STR
Definition: motorConfig.hpp:72
constexpr auto CI_STAT_INIT_ACTION
Definition: motorConfig.hpp:108
constexpr int CI_AXIS_MODE_INPOS
Definition: motorConfig.hpp:75
constexpr auto CI_INIT_ACTION_FIND_REF_UE
Definition: motorConfig.hpp:91
constexpr auto CI_STAT_SCALE_FACTOR
Definition: motorConfig.hpp:104
constexpr auto CI_INIT_VALUE_1
Definition: motorConfig.hpp:60
constexpr int CI_MAX_INIT_STEPS
Definition: motorConfig.hpp:86
constexpr auto CI_STAT_BACKLASH_STEP
Definition: motorConfig.hpp:105
const std::unordered_map< int, std::string > InitActions2Map
Definition: motorConfig.hpp:179
constexpr auto CI_INIT_ACTION_CALIB_SWITCH
Definition: motorConfig.hpp:99
constexpr auto CI_ACTIVE_LOW_USTOP
Definition: motorConfig.hpp:50
constexpr auto CI_STAT_SIGNAL_REF
Definition: motorConfig.hpp:121
constexpr auto CI_CHECK_INPOS
Definition: motorConfig.hpp:37
Signal
Definition: motorConfig.hpp:126
constexpr auto CI_STAT_SIGNAL_LSTOP
Definition: motorConfig.hpp:119
constexpr auto LOGGER_NAME
Definition: motorConfig.hpp:30
constexpr auto FITS_PARAM_LOCK
Definition: motorConfig.hpp:134
constexpr auto CI_INIT_ACTION_DELAY
Definition: motorConfig.hpp:94
constexpr auto CI_LOCK
Definition: motorConfig.hpp:38
constexpr auto CI_BACKLASH
Definition: motorConfig.hpp:34
constexpr auto CI_LOCK_POS
Definition: motorConfig.hpp:39
constexpr auto CI_AXIS_TYPE_CIRCULAR_OPT_STR
Definition: motorConfig.hpp:73
constexpr auto FITS_PARAM_BRAKE
Definition: motorConfig.hpp:133
constexpr auto CI_ACTIVE_LOW_LHW
Definition: motorConfig.hpp:46
constexpr auto CI_EXEC_PRE_INIT
Definition: motorConfig.hpp:52
constexpr auto CI_STAT_SIGNAL_USTOP
Definition: motorConfig.hpp:124
constexpr auto CI_STAT_AXIS_BRAKE
Definition: motorConfig.hpp:113
constexpr auto CI_AXIS_MODE_INVEL_STR
Definition: motorConfig.hpp:79
constexpr int CI_AXIS_TYPE_CIRCULAR_OPT
Definition: motorConfig.hpp:69
constexpr auto CI_ACTIVE_LOW_UHW
Definition: motorConfig.hpp:49
constexpr auto CI_ACTIVE_LOW_BRAKE
Definition: motorConfig.hpp:43
constexpr int CI_AXIS_MODE_INVEL
Definition: motorConfig.hpp:76
constexpr auto CI_LOCK_TOLERANCE
Definition: motorConfig.hpp:40
constexpr auto CI_INIT_ACTION_FIND_INDEX
Definition: motorConfig.hpp:89
constexpr auto CI_STAT_AXIS_INFO_DATA_1
Definition: motorConfig.hpp:116
constexpr auto CI_ACTIVE_LOW_INPOS
Definition: motorConfig.hpp:44
constexpr auto CI_INIT_ACTION_MOVE_ABS
Definition: motorConfig.hpp:95
constexpr auto CI_STAT_AXIS_ENABLE
Definition: motorConfig.hpp:110
constexpr auto CI_AXIS_MODE_INPOS_STR
Definition: motorConfig.hpp:78
const std::unordered_map< std::string, int > InitActionsMap
Definition: motorConfig.hpp:163
constexpr auto CI_DISABLE
Definition: motorConfig.hpp:41
constexpr auto CI_STAT_MODE
Definition: motorConfig.hpp:106
constexpr auto CI_INIT_ACTION_CALIB_REL
Definition: motorConfig.hpp:98
constexpr auto CI_STAT_AXIS_READY
Definition: motorConfig.hpp:109
const std::unordered_map< int, std::string > AxisModeMap
Definition: motorConfig.hpp:81
constexpr auto CI_STAT_AXIS_INFO_DATA_2
Definition: motorConfig.hpp:117
@ INIT_ACTION_FIND_REF_UE
Definition: motorConfig.hpp:147
@ INIT_ACTION_FIND_REF_LE
Definition: motorConfig.hpp:146
@ INIT_ACTION_MOVE_ABS
Definition: motorConfig.hpp:151
@ INIT_ACTION_END
Definition: motorConfig.hpp:144
@ INIT_ACTION_FIND_INDEX
Definition: motorConfig.hpp:145
@ INIT_ACTION_CALIB_REL
Definition: motorConfig.hpp:154
@ INIT_ACTION_MOVE_REL
Definition: motorConfig.hpp:152
@ INIT_ACTION_FIND_LHW
Definition: motorConfig.hpp:148
@ INIT_ACTION_CALIB_SWITCH
Definition: motorConfig.hpp:155
@ INIT_ACTION_CALIB_ABS
Definition: motorConfig.hpp:153
@ INIT_ACTION_DELAY
Definition: motorConfig.hpp:150
@ INIT_ACTION_FIND_UHW
Definition: motorConfig.hpp:149
constexpr auto CI_ACTIVE_LOW_INDEX
Definition: motorConfig.hpp:48
const std::unordered_map< std::string, int > AxisTypeMap
Definition: motorConfig.hpp:137
constexpr auto CI_INIT_ACTION_FIND_LHW
Definition: motorConfig.hpp:92
constexpr auto CI_STAT_SIGNAL_INDEX
Definition: motorConfig.hpp:122
constexpr auto CI_EXEC_PRE_MOVE
Definition: motorConfig.hpp:54
constexpr auto CI_STAT_AXIS_INPOS
Definition: motorConfig.hpp:111
constexpr auto CI_INITIALISATION
Definition: motorConfig.hpp:57
constexpr auto CI_EXEC_POST_MOVE
Definition: motorConfig.hpp:55
constexpr auto CI_ACTIVE_LOW_STOP
Definition: motorConfig.hpp:45
constexpr auto CI_BRAKE
Definition: motorConfig.hpp:33
constexpr auto CI_STAT_SIGNAL_LHW
Definition: motorConfig.hpp:120
constexpr auto CI_INIT_ACTION_MOVE_REL
Definition: motorConfig.hpp:96
constexpr auto CI_STAT_AXIS_STOP_NEG
Definition: motorConfig.hpp:114
constexpr auto CI_INIT_ACTION_FIND_REF_LE
Definition: motorConfig.hpp:90
constexpr auto CI_INIT_ACTION
Definition: motorConfig.hpp:59
constexpr auto CI_ACTIVE_LOW_REF
Definition: motorConfig.hpp:47
constexpr auto CI_STAT_SIGNAL_UHW
Definition: motorConfig.hpp:123
constexpr auto CI_STAT_AXIS_LOCK
Definition: motorConfig.hpp:112
constexpr int CI_AXIS_TYPE_CIRCULAR
Definition: motorConfig.hpp:68
constexpr auto CI_EXEC_POST_INIT
Definition: motorConfig.hpp:53
constexpr auto CI_INIT_SEQUENCE
Definition: motorConfig.hpp:58
constexpr auto CI_INIT_ACTION_END
Definition: motorConfig.hpp:88
constexpr auto CI_INIT_ACTION_CALIB_ABS
Definition: motorConfig.hpp:97
constexpr int CI_AXIS_TYPE_LINEAR
Definition: motorConfig.hpp:67
constexpr auto CI_INIT_ACTION_FIND_UHW
Definition: motorConfig.hpp:93
Definition: motorConfig.hpp:194
InitAction()
Definition: motorConfig.hpp:199
double value1
Definition: motorConfig.hpp:196
int id
Definition: motorConfig.hpp:195
double value2
Definition: motorConfig.hpp:197
std::string const
Definition: test{{cookiecutter.device_name|capitalize()}}.cpp:161