ifw-fcf  5.0.0
motorBaseConfig.hpp
Go to the documentation of this file.
1 
10 #ifndef FCF_DEVMGR_DEVICE_MOTOR_BASE_CONFIG_HPP
11 #define FCF_DEVMGR_DEVICE_MOTOR_BASE_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>
24 
25 
26 
27 namespace fcf::devmgr::motor {
28 
29  // Constants for internal mapping
30  constexpr auto CI_DEF_VEL = "velocity";
31  constexpr auto CI_MAX_POS = "max_pos";
32  constexpr auto CI_MIN_POS = "min_pos";
33 
34 
35  constexpr auto CI_TIMEOUT_INIT = "tout_init";
36  constexpr auto CI_TIMEOUT_MOVE = "tout_move";
37  constexpr auto CI_TIMEOUT_SWITCH = "tout_switch";
38 
39 
40  // WS configuration keywords
41  // These configuration only matters for WS level
42  constexpr auto CI_POSITIONS = "positions";
43  constexpr auto CI_POS_NAME = "name";
44  constexpr auto CI_POS_VALUE = "value";
45  constexpr auto CI_NAME_POS_TOLERANCE = "tolerance";
46  constexpr auto CI_SCALE_FACTOR = "scale_factor";
47 
48 
49 
50 
51  constexpr auto RPC_MOVE_ABS = "rpcMoveAbs";
52  constexpr auto RPC_MOVE_REL = "rpcMoveRel";
53  constexpr auto RPC_MOVE_VEL = "rpcMoveVel";
54 
55  constexpr int SUBSTATE_ABORTING = 107;
56  constexpr int SUBSTATE_OP_STANDSTILL = 216;
57  constexpr int SUBSTATE_OP_MOVING = 217;
58  constexpr int SUBSTATE_OP_SETTING_POS = 218;
59  constexpr int SUBSTATE_OP_STOPPING = 219;
60 
61  constexpr auto SUBSTATE_READY_STR = "Ready";
62  constexpr auto SUBSTATE_ABORTING_STR = "Aborting";
63  constexpr auto SUBSTATE_OP_STANDSTILL_STR = "Standstill";
64  constexpr auto SUBSTATE_OP_MOVING_STR = "Moving";
65  constexpr auto SUBSTATE_OP_SETTING_POS_STR = "SettingPos";
66  constexpr auto SUBSTATE_OP_STOPPING_STR = "Stopping";
67 
68  const std::unordered_map<short, std::string> SubstateMap = {
79  };
80 
81  // encoders are used only at the WS level
82  constexpr auto CI_STAT_ENC_POS = "pos_enc";
83  constexpr auto CI_STAT_TARGET_ENC = "target_enc";
84  constexpr auto CI_STAT_TARGET_POSNAME = "pos_target_name";
85  constexpr auto CI_STAT_ACTUAL_POSNAME = "pos_actual_name";
86  constexpr auto CI_STAT_TARGET_POS = "pos_target";
87  constexpr auto CI_STAT_ACTUAL_POS = "pos_actual";
88  constexpr auto CI_STAT_POS_ERROR = "pos_error";
89  constexpr auto CI_STAT_ACTUAL_VEL = "vel_actual";
90  constexpr auto CI_STAT_TARGET_VEL = "vel_target";
91  constexpr auto CI_STAT_INITIALISED = "initialised";
92  constexpr auto CI_STAT_USER_UNIT = "user_unit";
93 
94  constexpr auto FITS_PARAM_POSNAME = "POSNAME";
95  constexpr auto FITS_PARAM_POS = "POS";
96 
97 
98  constexpr auto UndefinedNamedPos = "undefined";
99 
100 
101 
102 
103  // @TODO: replaced by boost bimaps
104  // Tried with boost bimap but I've got hundred of errors.
105  // I added temporaly two maps.
106 
107 
116  friend class Sensor;
117 
118 
119  public:
125  MotorBaseConfig(const std::string filename,
126  const std::string name);
127 
132  MotorBaseConfig(const std::string name);
133 
137  virtual ~MotorBaseConfig() = default;
138 
139 
147  virtual void Init();
148 
149 
150 
160  virtual void GetConfigList(utils::bat::DbVector& cfg_list,
161  std::string prefix) const override;
162 
163 
164 
169  inline int GetNumberOfNamedPositions() const noexcept {return m_num_named_pos;};
170 
171 
176  double GetVelocity() const ;
177 
182  virtual double GetScaleFactor() const;
183 
189  std::string GetNamedPosition(const int index) const;
190 
196  double GetNamedPositionValue(const int index) const;
197 
204  bool FindNamedPositionValue(const std::string named_pos,
205  double& position) const;
206 
213  bool FindNamedPositionValue(const double position,
214  std::string& name) const;
215 
220  double GetNpTolerance() const;
221 
222 
223  protected:
224 
225  // Map of motor named positions
226  std::unordered_map<std::string, double> m_named_positions;
228 
229  private:
230 
231  log4cplus::Logger m_logger;
232 
233  };
234 
235 }
236 
237 
238 #endif //FCF_DEVMGR_DEVICE_MOTOR_BASE_CONFIG_HPP
m_logger(log4cplus::Logger::getInstance(LOGGER_NAME))
Definition: {{cookiecutter.device_name}}.cpp:32
Device Configuration class.
Definition: deviceConfig.hpp:126
Motor Base Configuration class.
Definition: motorBaseConfig.hpp:115
virtual double GetScaleFactor() const
Definition: motorBaseConfig.cpp:70
double GetVelocity() const
Definition: motorBaseConfig.cpp:58
virtual ~MotorBaseConfig()=default
MotorConfig destructor.
MotorBaseConfig(const std::string filename, const std::string name)
MotorConfig constructor.
Definition: motorBaseConfig.cpp:25
int m_num_named_pos
Number of named positions.
Definition: motorBaseConfig.hpp:227
std::string GetNamedPosition(const int index) const
GetNamedPosition.
Definition: motorBaseConfig.cpp:83
virtual void GetConfigList(utils::bat::DbVector &cfg_list, std::string prefix) const override
Get configuration list.
Definition: motorBaseConfig.cpp:141
virtual void Init()
Read the configuration.
Definition: motorBaseConfig.cpp:41
double GetNpTolerance() const
Get named position tolerance.
Definition: motorBaseConfig.cpp:162
std::unordered_map< std::string, double > m_named_positions
Definition: motorBaseConfig.hpp:226
int GetNumberOfNamedPositions() const noexcept
Definition: motorBaseConfig.hpp:169
double GetNamedPositionValue(const int index) const
GetNamedPositionValue.
Definition: motorBaseConfig.cpp:97
friend class Sensor
Definition: motorBaseConfig.hpp:116
bool FindNamedPositionValue(const std::string named_pos, double &position) const
Find value associated to a named position.
Definition: motorBaseConfig.cpp:109
DataContext class header file.
DeviceConfig class header file.
LampRpcErrors header file.
constexpr int SUBSTATE_OP_ERROR
Definition: deviceConfig.hpp:108
constexpr int SUBSTATE_INITIALISING
Definition: deviceConfig.hpp:99
constexpr int SUBSTATE_READY
Definition: deviceConfig.hpp:98
constexpr auto SUBSTATE_OP_ERROR_STR
Definition: deviceConfig.hpp:111
constexpr auto SUBSTATE_ERROR_STR
Definition: deviceConfig.hpp:105
constexpr int SUBSTATE_ERROR
Definition: deviceConfig.hpp:100
constexpr int SUBSTATE_NOTREADY
Definition: deviceConfig.hpp:97
constexpr auto SUBSTATE_NOTREADY_STR
Definition: deviceConfig.hpp:102
constexpr auto SUBSTATE_READY_STR
Definition: deviceConfig.hpp:104
constexpr auto SUBSTATE_INITIALISING_STR
Definition: deviceConfig.hpp:103
Definition: motor.hpp:18
constexpr auto CI_POS_VALUE
Definition: motorBaseConfig.hpp:44
constexpr auto CI_MAX_POS
Definition: motorBaseConfig.hpp:31
constexpr auto CI_TIMEOUT_INIT
Definition: motorBaseConfig.hpp:35
constexpr auto CI_TIMEOUT_SWITCH
Definition: motorBaseConfig.hpp:37
constexpr auto CI_STAT_ENC_POS
Definition: motorBaseConfig.hpp:82
constexpr auto SUBSTATE_OP_MOVING_STR
Definition: motorBaseConfig.hpp:64
constexpr auto SUBSTATE_OP_STANDSTILL_STR
Definition: motorBaseConfig.hpp:63
constexpr auto CI_STAT_ACTUAL_POS
Definition: motorBaseConfig.hpp:87
constexpr auto CI_STAT_TARGET_POSNAME
Definition: motorBaseConfig.hpp:84
constexpr auto CI_POS_NAME
Definition: motorBaseConfig.hpp:43
constexpr auto FITS_PARAM_POSNAME
Definition: motorBaseConfig.hpp:94
constexpr auto CI_STAT_ACTUAL_POSNAME
Definition: motorBaseConfig.hpp:85
constexpr auto SUBSTATE_OP_STOPPING_STR
Definition: motorBaseConfig.hpp:66
constexpr auto RPC_MOVE_VEL
Definition: motorBaseConfig.hpp:53
constexpr auto RPC_MOVE_REL
Definition: motorBaseConfig.hpp:52
constexpr int SUBSTATE_OP_SETTING_POS
Definition: motorBaseConfig.hpp:58
constexpr auto UndefinedNamedPos
Definition: motorBaseConfig.hpp:98
constexpr auto CI_STAT_USER_UNIT
Definition: motorBaseConfig.hpp:92
constexpr auto CI_DEF_VEL
Definition: motorBaseConfig.hpp:30
constexpr auto SUBSTATE_ABORTING_STR
Definition: motorBaseConfig.hpp:62
constexpr auto CI_STAT_TARGET_VEL
Definition: motorBaseConfig.hpp:90
constexpr auto CI_SCALE_FACTOR
Definition: motorBaseConfig.hpp:46
constexpr auto SUBSTATE_READY_STR
Definition: motorBaseConfig.hpp:61
constexpr auto CI_STAT_TARGET_POS
Definition: motorBaseConfig.hpp:86
constexpr auto CI_POSITIONS
Definition: motorBaseConfig.hpp:42
constexpr auto FITS_PARAM_POS
Definition: motorBaseConfig.hpp:95
constexpr int SUBSTATE_OP_STANDSTILL
Definition: motorBaseConfig.hpp:56
constexpr int SUBSTATE_OP_STOPPING
Definition: motorBaseConfig.hpp:59
constexpr int SUBSTATE_ABORTING
Definition: motorBaseConfig.hpp:55
constexpr auto CI_MIN_POS
Definition: motorBaseConfig.hpp:32
constexpr auto CI_STAT_TARGET_ENC
Definition: motorBaseConfig.hpp:83
const std::unordered_map< short, std::string > SubstateMap
Definition: motorBaseConfig.hpp:68
constexpr auto SUBSTATE_OP_SETTING_POS_STR
Definition: motorBaseConfig.hpp:65
constexpr auto CI_NAME_POS_TOLERANCE
Definition: motorBaseConfig.hpp:45
constexpr auto CI_STAT_ACTUAL_VEL
Definition: motorBaseConfig.hpp:89
constexpr auto CI_TIMEOUT_MOVE
Definition: motorBaseConfig.hpp:36
constexpr auto CI_STAT_INITIALISED
Definition: motorBaseConfig.hpp:91
constexpr int SUBSTATE_OP_MOVING
Definition: motorBaseConfig.hpp:57
constexpr auto CI_STAT_POS_ERROR
Definition: motorBaseConfig.hpp:88
constexpr auto RPC_MOVE_ABS
Definition: motorBaseConfig.hpp:51
std::string const
Definition: test{{cookiecutter.device_name|capitalize()}}.cpp:161