ifw-fcf 7.1.4
Loading...
Searching...
No Matches
motorConfig.hpp
Go to the documentation of this file.
1
8#ifndef FCF_DEVMGR_DEVICE_MOTOR_CONFIG_HPP
9#define FCF_DEVMGR_DEVICE_MOTOR_CONFIG_HPP
10
11#include <string>
12#include <unordered_map>
13
14#include <yaml-cpp/yaml.h>
15
16#include <ifw/core/utils/bat/logger.hpp>
17
22
23
25
26 constexpr auto LOGGER_NAME = "motor";
27
28 // Constants for internal mapping
29 constexpr auto CI_BRAKE = "brake";
30 constexpr auto CI_BACKLASH = "backlash";
31 constexpr auto CI_AXIS_TYPE = "axis_type";
32
33 constexpr auto CI_CHECK_INPOS = "check_inpos";
34 constexpr auto CI_LOCK = "lock";
35 constexpr auto CI_LOCK_POS = "lock_pos";
36 constexpr auto CI_LOCK_TOLERANCE = "lock_tolerance";
37 constexpr auto CI_DISABLE = "disable";
38
39 constexpr auto CI_ACTIVE_LOW_BRAKE = "low_brake";
40 constexpr auto CI_ACTIVE_LOW_INPOS = "low_inpos";
41 constexpr auto CI_ACTIVE_LOW_STOP = "active_low_lstop";
42 constexpr auto CI_ACTIVE_LOW_LHW = "active_low_lhw";
43 constexpr auto CI_ACTIVE_LOW_REF = "active_low_ref";
44 constexpr auto CI_ACTIVE_LOW_INDEX = "active_low_index";
45 constexpr auto CI_ACTIVE_LOW_UHW = "active_low_uhw";
46 constexpr auto CI_ACTIVE_LOW_USTOP = "active_low_ustop";
47
48 constexpr auto CI_EXEC_PRE_INIT = "exec_pre_init";
49 constexpr auto CI_EXEC_POST_INIT = "exec_post_init";
50 constexpr auto CI_EXEC_PRE_MOVE = "exec_pre_move";
51 constexpr auto CI_EXEC_POST_MOVE = "exec_post_move";
52
53 constexpr auto CI_INITIALISATION = "initialisation";
54 constexpr auto CI_INIT_SEQUENCE = "sequence";
55 constexpr auto CI_INIT_ACTION = "step";
56 constexpr auto CI_INIT_VALUE_1 = "value1";
57 constexpr auto CI_INIT_VALUE_2 = "value2";
58
59
60 // WS configuration keywords
61 // These configuration only matters for WS level
62
63 constexpr int CI_AXIS_TYPE_LINEAR = 1;
64 constexpr int CI_AXIS_TYPE_CIRCULAR = 2;
65 constexpr int CI_AXIS_TYPE_CIRCULAR_OPT = 3;
66
67 constexpr auto CI_AXIS_TYPE_LINEAR_STR = "LINEAR";
68 constexpr auto CI_AXIS_TYPE_CIRCULAR_STR = "CIRCULAR";
69 constexpr auto CI_AXIS_TYPE_CIRCULAR_OPT_STR = "CIRCULAR_OPT";
70
71 constexpr int CI_AXIS_MODE_INPOS = 0;
72 constexpr int CI_AXIS_MODE_INVEL = 1;
73
74 constexpr auto CI_AXIS_MODE_INPOS_STR = "InPosition";
75 constexpr auto CI_AXIS_MODE_INVEL_STR = "InVelocity";
76
77 const std::unordered_map<int, std::string> AXIS_MODE_MAP = {
80 };
81
82 constexpr int CI_MAX_INIT_STEPS = 10;
83
84 constexpr auto CI_INIT_ACTION_END = "END";
85 constexpr auto CI_INIT_ACTION_FIND_INDEX = "FIND_INDEX";
86 constexpr auto CI_INIT_ACTION_FIND_REF_LE = "FIND_REF_LE";
87 constexpr auto CI_INIT_ACTION_FIND_REF_UE = "FIND_REF_UE";
88 constexpr auto CI_INIT_ACTION_FIND_LHW = "FIND_LHW";
89 constexpr auto CI_INIT_ACTION_FIND_UHW = "FIND_UHW";
90 constexpr auto CI_INIT_ACTION_DELAY = "DELAY";
91 constexpr auto CI_INIT_ACTION_MOVE_ABS = "MOVE_ABS";
92 constexpr auto CI_INIT_ACTION_MOVE_REL = "MOVE_REL";
93 constexpr auto CI_INIT_ACTION_CALIB_ABS = "CALIB_ABS";
94 constexpr auto CI_INIT_ACTION_CALIB_REL = "CALIB_REL";
95 constexpr auto CI_INIT_ACTION_CALIB_SWITCH = "CALIB_SWITCH";
96
97
98 // encoders are used only at the WS level
99
100 constexpr auto CI_STAT_SCALE_FACTOR = "scale_factor";
101 constexpr auto CI_STAT_BACKLASH_STEP = "backlash_step";
102 constexpr auto CI_STAT_MODE = "mode";
103 constexpr auto CI_STAT_INIT_STEP = "init_step";
104 constexpr auto CI_STAT_INIT_ACTION = "init_action";
105 constexpr auto CI_STAT_AXIS_READY = "axis_ready";
106 constexpr auto CI_STAT_AXIS_ENABLE = "axis_enable";
107 constexpr auto CI_STAT_AXIS_INPOS = "axis_inposition";
108 constexpr auto CI_STAT_AXIS_LOCK = "axis_lock";
109 constexpr auto CI_STAT_AXIS_BRAKE = "axis_brake";
110 constexpr auto CI_STAT_AXIS_STOP_NEG = "axis_stop_pos";
111 constexpr auto CI_STAT_AXIS_STOP_POS = "axis_stop_neg";
112 constexpr auto CI_STAT_AXIS_INFO_DATA_1 = "axis_info_data1";
113 constexpr auto CI_STAT_AXIS_INFO_DATA_2 = "axis_info_data2";
114
115 constexpr auto CI_STAT_SIGNAL_LSTOP = "signal_lstop";
116 constexpr auto CI_STAT_SIGNAL_LHW = "signal_lhw";
117 constexpr auto CI_STAT_SIGNAL_REF = "signal_ref";
118 constexpr auto CI_STAT_SIGNAL_INDEX = "signal_index";
119 constexpr auto CI_STAT_SIGNAL_UHW = "signal_uhw";
120 constexpr auto CI_STAT_SIGNAL_USTOP = "signal_ustop";
121
122 enum class Signal : short {LSTOP = 0,
123 LHW = 1,
124 REF = 2,
125 INDEX = 3,
126 UHW = 4,
127 USTOP = 5};
128
129 constexpr auto FITS_PARAM_BRAKE = "BRAKE";
130 constexpr auto FITS_PARAM_LOCK = "LOCK";
131
132 // Map of Axis type to do the converstion between strings to numbers
138
139 enum {
152 };
153
154 // @TODO: replaced by boost bimaps
155 // Tried with boost bimap but I've got hundred of errors.
156 // I added temporaly two maps.
157
158 // Map of motor initialisation steps
173
174 // Map of motor initialisation steps
189
190 struct InitAction {
191
192
193 InitAction():m_id(0), m_value1(0.0), m_value2(0.0) {}
194 int GetId() const;
195 void SetId(int id);
196 double GetValue1() const;
197 void SetValue1(double value);
198 double GetValue2() const;
199 void SetValue2(double value);
200
201 private:
202 int m_id;
203 double m_value1;
204 double m_value2;
205 };
206
207 class Sensor;
216 {
217 friend class Sensor;
218
219
220 public:
226 MotorConfig(const std::string filename,
227 const std::string name);
228
233 MotorConfig(const std::string name);
234
238 virtual ~MotorConfig() = default;
239
240
248 void Init();
262 virtual void GetConfig(ifw::core::protocol::base::VectorVariant& params) const override;
263
264
274 virtual void GetConfigList(ifw::core::utils::bat::DbVector& cfg_list,
275 std::string prefix) const override;
276
277
282 inline int GetNumberOfInitSteps() const noexcept {return m_init_sequence.size();};
283
284
289 double GetScaleFactor() const override;
290
298 void SetScaleFactor(double scale);
299
300 private:
301 // Map of motor init step to do the conversion between strings to numbers
302 std::vector<InitAction> m_init_sequence;
303 double m_scale_factor{1.0};
304
305 private:
306
307 log4cplus::Logger m_logger;
308
309 };
310
311}
312
313
314#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:138
Motor Configuration class.
Definition motorConfig.hpp:216
virtual ~MotorConfig()=default
MotorConfig destructor.
double GetScaleFactor() const override
Definition motorConfig.cpp:179
void Init()
Read the configuration.
Definition motorConfig.cpp:61
void SetScaleFactor(double scale)
Set Scale Factor.
Definition motorConfig.cpp:184
virtual void GetConfigList(ifw::core::utils::bat::DbVector &cfg_list, std::string prefix) const override
Get configuration list.
Definition motorConfig.cpp:149
int GetNumberOfInitSteps() const noexcept
Get number of initialisations steps.
Definition motorConfig.hpp:282
MotorConfig(const std::string filename, const std::string name)
MotorConfig constructor.
Definition motorConfig.cpp:45
virtual void GetConfig(ifw::core::protocol::base::VectorVariant &params) const override
Obtain the list of configuration parameters.
Definition motorConfig.cpp:105
friend class Sensor
Definition motorConfig.hpp:217
Motor class source file.
Definition motor.hpp:17
constexpr auto CI_ACTIVE_LOW_INPOS
Definition motorConfig.hpp:40
constexpr int CI_AXIS_MODE_INVEL
Definition motorConfig.hpp:72
constexpr auto CI_INIT_ACTION_FIND_REF_LE
Definition motorConfig.hpp:86
constexpr auto CI_AXIS_MODE_INPOS_STR
Definition motorConfig.hpp:74
constexpr auto CI_STAT_INIT_ACTION
Definition motorConfig.hpp:104
constexpr int CI_AXIS_TYPE_CIRCULAR
Definition motorConfig.hpp:64
constexpr auto CI_INIT_SEQUENCE
Definition motorConfig.hpp:54
constexpr auto CI_STAT_AXIS_STOP_NEG
Definition motorConfig.hpp:110
constexpr auto CI_AXIS_TYPE_CIRCULAR_STR
Definition motorConfig.hpp:68
constexpr auto CI_INITIALISATION
Definition motorConfig.hpp:53
constexpr auto CI_ACTIVE_LOW_BRAKE
Definition motorConfig.hpp:39
constexpr auto CI_STAT_SIGNAL_INDEX
Definition motorConfig.hpp:118
constexpr auto CI_STAT_AXIS_STOP_POS
Definition motorConfig.hpp:111
constexpr auto CI_STAT_INIT_STEP
Definition motorConfig.hpp:103
constexpr auto CI_INIT_ACTION_MOVE_REL
Definition motorConfig.hpp:92
constexpr auto CI_LOCK_POS
Definition motorConfig.hpp:35
const std::unordered_map< std::string, int > INIT_ACTIONS_MAP
Definition motorConfig.hpp:159
@ INIT_ACTION_END
Definition motorConfig.hpp:140
@ INIT_ACTION_CALIB_ABS
Definition motorConfig.hpp:149
@ INIT_ACTION_FIND_REF_LE
Definition motorConfig.hpp:142
@ INIT_ACTION_CALIB_REL
Definition motorConfig.hpp:150
@ INIT_ACTION_FIND_UHW
Definition motorConfig.hpp:145
@ INIT_ACTION_MOVE_ABS
Definition motorConfig.hpp:147
@ INIT_ACTION_CALIB_SWITCH
Definition motorConfig.hpp:151
@ INIT_ACTION_FIND_LHW
Definition motorConfig.hpp:144
@ INIT_ACTION_MOVE_REL
Definition motorConfig.hpp:148
@ INIT_ACTION_DELAY
Definition motorConfig.hpp:146
@ INIT_ACTION_FIND_REF_UE
Definition motorConfig.hpp:143
@ INIT_ACTION_FIND_INDEX
Definition motorConfig.hpp:141
constexpr auto CI_STAT_AXIS_INPOS
Definition motorConfig.hpp:107
constexpr auto CI_INIT_ACTION_FIND_INDEX
Definition motorConfig.hpp:85
constexpr auto CI_INIT_ACTION_CALIB_REL
Definition motorConfig.hpp:94
constexpr auto CI_ACTIVE_LOW_INDEX
Definition motorConfig.hpp:44
constexpr auto CI_INIT_VALUE_1
Definition motorConfig.hpp:56
constexpr auto CI_INIT_ACTION_FIND_LHW
Definition motorConfig.hpp:88
constexpr auto CI_ACTIVE_LOW_USTOP
Definition motorConfig.hpp:46
constexpr auto CI_LOCK_TOLERANCE
Definition motorConfig.hpp:36
constexpr auto CI_LOCK
Definition motorConfig.hpp:34
constexpr auto CI_INIT_ACTION_END
Definition motorConfig.hpp:84
constexpr auto CI_INIT_ACTION_FIND_UHW
Definition motorConfig.hpp:89
constexpr auto CI_AXIS_TYPE_LINEAR_STR
Definition motorConfig.hpp:67
constexpr auto CI_STAT_AXIS_INFO_DATA_2
Definition motorConfig.hpp:113
constexpr int CI_AXIS_MODE_INPOS
Definition motorConfig.hpp:71
constexpr auto CI_ACTIVE_LOW_REF
Definition motorConfig.hpp:43
const std::unordered_map< int, std::string > INIT_ACTIONS2_MAP
Definition motorConfig.hpp:175
constexpr auto CI_BRAKE
Definition motorConfig.hpp:29
constexpr int CI_AXIS_TYPE_LINEAR
Definition motorConfig.hpp:63
constexpr auto CI_AXIS_MODE_INVEL_STR
Definition motorConfig.hpp:75
constexpr auto CI_INIT_ACTION_DELAY
Definition motorConfig.hpp:90
constexpr auto CI_ACTIVE_LOW_STOP
Definition motorConfig.hpp:41
constexpr auto CI_EXEC_POST_INIT
Definition motorConfig.hpp:49
constexpr auto CI_INIT_ACTION_CALIB_SWITCH
Definition motorConfig.hpp:95
constexpr auto CI_STAT_SIGNAL_LHW
Definition motorConfig.hpp:116
constexpr auto CI_INIT_ACTION_MOVE_ABS
Definition motorConfig.hpp:91
constexpr auto CI_STAT_SIGNAL_USTOP
Definition motorConfig.hpp:120
constexpr auto CI_BACKLASH
Definition motorConfig.hpp:30
constexpr auto CI_INIT_VALUE_2
Definition motorConfig.hpp:57
constexpr auto CI_STAT_SIGNAL_UHW
Definition motorConfig.hpp:119
constexpr auto CI_EXEC_PRE_MOVE
Definition motorConfig.hpp:50
Signal
Definition motorConfig.hpp:122
constexpr auto CI_STAT_AXIS_INFO_DATA_1
Definition motorConfig.hpp:112
constexpr auto CI_DISABLE
Definition motorConfig.hpp:37
constexpr auto CI_STAT_AXIS_ENABLE
Definition motorConfig.hpp:106
constexpr auto CI_STAT_SIGNAL_REF
Definition motorConfig.hpp:117
const std::unordered_map< std::string, int > AXIS_TYPE_MAP
Definition motorConfig.hpp:133
constexpr auto CI_CHECK_INPOS
Definition motorConfig.hpp:33
constexpr auto CI_INIT_ACTION_FIND_REF_UE
Definition motorConfig.hpp:87
constexpr auto CI_STAT_SIGNAL_LSTOP
Definition motorConfig.hpp:115
constexpr int CI_AXIS_TYPE_CIRCULAR_OPT
Definition motorConfig.hpp:65
constexpr auto FITS_PARAM_BRAKE
Definition motorConfig.hpp:129
constexpr auto CI_STAT_AXIS_BRAKE
Definition motorConfig.hpp:109
constexpr auto CI_EXEC_PRE_INIT
Definition motorConfig.hpp:48
constexpr auto CI_INIT_ACTION_CALIB_ABS
Definition motorConfig.hpp:93
constexpr auto CI_AXIS_TYPE_CIRCULAR_OPT_STR
Definition motorConfig.hpp:69
constexpr auto CI_STAT_SCALE_FACTOR
Definition motorConfig.hpp:100
constexpr auto CI_ACTIVE_LOW_UHW
Definition motorConfig.hpp:45
constexpr auto CI_STAT_BACKLASH_STEP
Definition motorConfig.hpp:101
constexpr auto CI_STAT_AXIS_LOCK
Definition motorConfig.hpp:108
constexpr auto CI_EXEC_POST_MOVE
Definition motorConfig.hpp:51
constexpr auto CI_AXIS_TYPE
Definition motorConfig.hpp:31
constexpr auto CI_STAT_AXIS_READY
Definition motorConfig.hpp:105
constexpr int CI_MAX_INIT_STEPS
Definition motorConfig.hpp:82
constexpr auto CI_STAT_MODE
Definition motorConfig.hpp:102
constexpr auto FITS_PARAM_LOCK
Definition motorConfig.hpp:130
constexpr auto CI_INIT_ACTION
Definition motorConfig.hpp:55
const std::unordered_map< int, std::string > AXIS_MODE_MAP
Definition motorConfig.hpp:77
constexpr auto LOGGER_NAME
Definition motorConfig.hpp:26
constexpr auto CI_ACTIVE_LOW_LHW
Definition motorConfig.hpp:42
Definition motorConfig.hpp:190
void SetId(int id)
Definition motorConfig.cpp:26
InitAction()
Definition motorConfig.hpp:193
int GetId() const
Definition motorConfig.cpp:22
double GetValue1() const
Definition motorConfig.cpp:30
double GetValue2() const
Definition motorConfig.cpp:37
void SetValue1(double value)
Definition motorConfig.cpp:33
void SetValue2(double value)
Definition motorConfig.cpp:41
std::string const
Definition test{{cookiecutter.device_name|capitalize()}}.cpp:161