ifw-fcf 8.0.2
 
Loading...
Searching...
No Matches
motorBaseConfig.hpp
Go to the documentation of this file.
1
7
8#ifndef FCF_DEVMGR_DEVICE_MOTOR_BASE_CONFIG_HPP
9#define FCF_DEVMGR_DEVICE_MOTOR_BASE_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>
20
21
23
24 // Constants for internal mapping
25 constexpr auto CI_DEF_VEL = "velocity";
26 constexpr auto CI_MAX_POS = "max_pos";
27 constexpr auto CI_MIN_POS = "min_pos";
28
29 constexpr auto CI_TIMEOUT_INIT = "tout_init";
30 constexpr auto CI_TIMEOUT_MOVE = "tout_move";
31 constexpr auto CI_TIMEOUT_SWITCH = "tout_switch";
32
33
34 // WS configuration keywords
35 // These configuration only matters for WS level
36 constexpr auto CI_POSITIONS = "positions";
37 constexpr auto CI_POS_NAME = "name";
38 constexpr auto CI_POS_VALUE = "value";
39 constexpr auto CI_POS_ID = "id";
40 constexpr auto CI_POS_TYPE = "type";
41 constexpr auto CI_POS_NO = "no";
42 constexpr auto CI_NAME_POS_TOLERANCE = "tolerance";
43 constexpr auto CI_SCALE_FACTOR = "scale_factor";
44
45 constexpr auto RPC_MOVE_ABS = "rpcMoveAbs";
46 constexpr auto RPC_MOVE_REL = "rpcMoveRel";
47 constexpr auto RPC_MOVE_VEL = "rpcMoveVel";
48
49 constexpr int SUBSTATE_ABORTING = 107;
50 constexpr int SUBSTATE_OP_STANDSTILL = 216;
51 constexpr int SUBSTATE_OP_MOVING = 217;
52 constexpr int SUBSTATE_OP_SETTING_POS = 218;
53 constexpr int SUBSTATE_OP_STOPPING = 219;
54
55 constexpr auto SUBSTATE_READY_STR = "Ready";
56 constexpr auto SUBSTATE_ABORTING_STR = "Aborting";
57 constexpr auto SUBSTATE_OP_STANDSTILL_STR = "Standstill";
58 constexpr auto SUBSTATE_OP_MOVING_STR = "Moving";
59 constexpr auto SUBSTATE_OP_SETTING_POS_STR = "SettingPos";
60 constexpr auto SUBSTATE_OP_STOPPING_STR = "Stopping";
61
74
75 // encoders are used only at the WS level
76 constexpr auto CI_STAT_ENC_POS = "pos_enc";
77 constexpr auto CI_STAT_TARGET_ENC = "target_enc";
78 constexpr auto CI_STAT_SI_POS = "pos_si";
79 constexpr auto CI_STAT_TARGET_SI = "target_si";
80 constexpr auto CI_STAT_TARGET_POSNAME = "pos_target_name";
81 constexpr auto CI_STAT_ACTUAL_POSNAME = "pos_actual_name";
82 constexpr auto CI_STAT_TARGET_POS = "pos_target";
83 constexpr auto CI_STAT_ACTUAL_POS = "pos_actual";
84 constexpr auto CI_STAT_POS_ERROR = "pos_error";
85 constexpr auto CI_STAT_ACTUAL_VEL = "vel_actual";
86 constexpr auto CI_STAT_TARGET_VEL = "vel_target";
87 constexpr auto CI_STAT_INITIALISED = "initialised";
88 constexpr auto CI_STAT_USER_UNIT = "user_unit";
89
90 constexpr auto FITS_PARAM_POSNAME = "NAME";
91 constexpr auto FITS_PARAM_POS = "POS";
92 constexpr auto FITS_PARAM_POSTYPE = "TYPE";
93 constexpr auto FITS_PARAM_POSNO = "NO";
94 constexpr auto FITS_PARAM_POSID = "ID";
95
96
97 constexpr auto UNDEFINED_NAMED_POS = "undefined";
98
99
100
109 inline std::optional<std::string> GetId() {
110 return m_pos_id;
111 }
112
113 inline std::optional<std::string> GetType() {
114 return m_pos_type;
115 }
116
117 inline std::optional<int> GetSlot() {
118 return m_slot;
119 }
120
121 std::optional<std::string> m_pos_id;
122 std::optional<std::string> m_pos_type;
123 std::optional<int> m_slot;
124
125 };
126
127 // @TODO: replaced by boost bimaps
128 // Tried with boost bimap but I've got hundred of errors.
129 // I added temporaly two maps.
130
131
140 friend class Sensor;
141
142
143 public:
149 MotorBaseConfig(const std::string filename,
150 const std::string name);
151
156 MotorBaseConfig(const std::string name);
157
161 virtual ~MotorBaseConfig() = default;
162
169 void Init();
170
180 virtual void GetConfigList(ifw::core::utils::bat::DbVector& cfg_list,
181 std::string prefix) const override;
182
187 inline int GetNumberOfNamedPositions() const noexcept {return m_num_named_pos;};
188
189
194 double GetVelocity() const ;
195
200 virtual double GetScaleFactor() const;
201
207 std::string GetNamedPosition(const int index) const;
208
214 double GetNamedPositionValue(const int index) const;
215
221 NamedPosConfig GetNamedPositionConfig(const std::string& named_pos) const;
228 bool FindNamedPositionValue(const std::string named_pos,
229 double& position) const;
230
237 bool FindNamedPositionValue(const double position,
238 std::string& name) const;
239
244 double GetNpTolerance() const;
245
246
247 private:
248
249 // Map of motor named positions
250 std::unordered_map<std::string, double> m_named_positions;
251 int m_num_named_pos{0};
252
253 private:
254
255 log4cplus::Logger m_logger;
256
257 };
258
259}
260
261
262#endif //FCF_DEVMGR_DEVICE_MOTOR_BASE_CONFIG_HPP
Device Configuration class.
Definition deviceConfig.hpp:124
virtual ~MotorBaseConfig()=default
MotorConfig destructor.
virtual double GetScaleFactor() const
Definition motorBaseConfig.cpp:64
std::string GetNamedPosition(const int index) const
GetNamedPosition.
Definition motorBaseConfig.cpp:77
double GetVelocity() const
Definition motorBaseConfig.cpp:52
double GetNamedPositionValue(const int index) const
GetNamedPositionValue.
Definition motorBaseConfig.cpp:91
MotorBaseConfig(const std::string filename, const std::string name)
MotorConfig constructor.
Definition motorBaseConfig.cpp:22
double GetNpTolerance() const
Get named position tolerance.
Definition motorBaseConfig.cpp:182
void Init()
Read the configuration.
Definition motorBaseConfig.cpp:35
virtual void GetConfigList(ifw::core::utils::bat::DbVector &cfg_list, std::string prefix) const override
Get configuration list.
Definition motorBaseConfig.cpp:161
NamedPosConfig GetNamedPositionConfig(const std::string &named_pos) const
GetNamedPositionType.
Definition motorBaseConfig.cpp:104
friend class Sensor
Definition motorBaseConfig.hpp:140
int GetNumberOfNamedPositions() const noexcept
Definition motorBaseConfig.hpp:187
bool FindNamedPositionValue(const std::string named_pos, double &position) const
Find value associated to a named position.
Definition motorBaseConfig.cpp:127
constexpr int SUBSTATE_ERROR
Definition deviceConfig.hpp:97
constexpr auto SUBSTATE_INITIALISING_STR
Definition deviceConfig.hpp:100
constexpr int SUBSTATE_READY
Definition deviceConfig.hpp:95
constexpr auto SUBSTATE_ERROR_STR
Definition deviceConfig.hpp:102
constexpr int SUBSTATE_INITIALISING
Definition deviceConfig.hpp:96
constexpr auto SUBSTATE_NOTREADY_STR
Definition deviceConfig.hpp:99
constexpr auto SUBSTATE_READY_STR
Definition deviceConfig.hpp:101
constexpr int SUBSTATE_OP_ERROR
Definition deviceConfig.hpp:105
constexpr int SUBSTATE_NOTREADY
Definition deviceConfig.hpp:94
constexpr auto SUBSTATE_OP_ERROR_STR
Definition deviceConfig.hpp:108
Motor class source file.
Definition motor.hpp:18
constexpr auto SUBSTATE_OP_STANDSTILL_STR
Definition motorBaseConfig.hpp:57
constexpr auto CI_DEF_VEL
Definition motorBaseConfig.hpp:25
constexpr auto CI_STAT_ACTUAL_POSNAME
Definition motorBaseConfig.hpp:81
constexpr auto CI_STAT_USER_UNIT
Definition motorBaseConfig.hpp:88
constexpr auto CI_SCALE_FACTOR
Definition motorBaseConfig.hpp:43
constexpr auto FITS_PARAM_POSID
Definition motorBaseConfig.hpp:94
constexpr auto SUBSTATE_ABORTING_STR
Definition motorBaseConfig.hpp:56
constexpr auto CI_TIMEOUT_MOVE
Definition motorBaseConfig.hpp:30
constexpr auto CI_TIMEOUT_SWITCH
Definition motorBaseConfig.hpp:31
constexpr int SUBSTATE_OP_STOPPING
Definition motorBaseConfig.hpp:53
constexpr auto CI_STAT_INITIALISED
Definition motorBaseConfig.hpp:87
constexpr auto CI_STAT_TARGET_POS
Definition motorBaseConfig.hpp:82
constexpr auto SUBSTATE_OP_MOVING_STR
Definition motorBaseConfig.hpp:58
constexpr auto CI_POS_ID
Definition motorBaseConfig.hpp:39
constexpr auto CI_MIN_POS
Definition motorBaseConfig.hpp:27
constexpr auto CI_MAX_POS
Definition motorBaseConfig.hpp:26
constexpr auto CI_STAT_POS_ERROR
Definition motorBaseConfig.hpp:84
constexpr auto SUBSTATE_OP_SETTING_POS_STR
Definition motorBaseConfig.hpp:59
constexpr auto SUBSTATE_OP_STOPPING_STR
Definition motorBaseConfig.hpp:60
constexpr auto FITS_PARAM_POSTYPE
Definition motorBaseConfig.hpp:92
constexpr auto CI_STAT_TARGET_POSNAME
Definition motorBaseConfig.hpp:80
constexpr auto FITS_PARAM_POS
Definition motorBaseConfig.hpp:91
constexpr auto CI_POS_VALUE
Definition motorBaseConfig.hpp:38
constexpr auto CI_POSITIONS
Definition motorBaseConfig.hpp:36
constexpr auto CI_POS_TYPE
Definition motorBaseConfig.hpp:40
constexpr auto CI_STAT_TARGET_ENC
Definition motorBaseConfig.hpp:77
constexpr auto CI_TIMEOUT_INIT
Definition motorBaseConfig.hpp:29
constexpr auto CI_STAT_ACTUAL_POS
Definition motorBaseConfig.hpp:83
constexpr auto RPC_MOVE_ABS
Definition motorBaseConfig.hpp:45
constexpr auto FITS_PARAM_POSNO
Definition motorBaseConfig.hpp:93
constexpr int SUBSTATE_OP_STANDSTILL
Definition motorBaseConfig.hpp:50
const std::unordered_map< short, std::string > SUBSTATE_MAP
Definition motorBaseConfig.hpp:62
constexpr auto CI_NAME_POS_TOLERANCE
Definition motorBaseConfig.hpp:42
constexpr auto CI_STAT_TARGET_SI
Definition motorBaseConfig.hpp:79
constexpr auto FITS_PARAM_POSNAME
Definition motorBaseConfig.hpp:90
constexpr auto RPC_MOVE_REL
Definition motorBaseConfig.hpp:46
constexpr auto CI_STAT_SI_POS
Definition motorBaseConfig.hpp:78
constexpr auto CI_STAT_ENC_POS
Definition motorBaseConfig.hpp:76
constexpr int SUBSTATE_ABORTING
Definition motorBaseConfig.hpp:49
constexpr auto SUBSTATE_READY_STR
Definition motorBaseConfig.hpp:55
constexpr int SUBSTATE_OP_SETTING_POS
Definition motorBaseConfig.hpp:52
constexpr auto RPC_MOVE_VEL
Definition motorBaseConfig.hpp:47
constexpr int SUBSTATE_OP_MOVING
Definition motorBaseConfig.hpp:51
constexpr auto CI_STAT_TARGET_VEL
Definition motorBaseConfig.hpp:86
constexpr auto CI_STAT_ACTUAL_VEL
Definition motorBaseConfig.hpp:85
constexpr auto CI_POS_NAME
Definition motorBaseConfig.hpp:37
constexpr auto UNDEFINED_NAMED_POS
Definition motorBaseConfig.hpp:97
constexpr auto CI_POS_NO
Definition motorBaseConfig.hpp:41
The NamedPositionConfig struct.
Definition motorBaseConfig.hpp:108
std::optional< std::string > m_pos_id
Definition motorBaseConfig.hpp:121
std::optional< std::string > GetType()
Definition motorBaseConfig.hpp:113
std::optional< int > GetSlot()
Definition motorBaseConfig.hpp:117
std::optional< std::string > GetId()
Definition motorBaseConfig.hpp:109
std::optional< int > m_slot
Definition motorBaseConfig.hpp:123
std::optional< std::string > m_pos_type
Definition motorBaseConfig.hpp:122
std::string const
Definition test{{cookiecutter.device_name|capitalize()}}.cpp:159