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