Types.h
Go to the documentation of this file.
1 #pragma once
2 
3 
4 #include <cmath>
5 #include <optional>
6 
8 
9 
11 {
12 
13  /**
14  * @brief The LinearConfig class represents a linear conversion and has a factor and offset.
15  * Partial overrides are possible for the offset, factor, factor sign and factor absolute value.
16  */
18  {
19  public:
20  /**
21  * @brief Create LinearConfig with factor and offset.
22  * Convenience constructor for this tag layout:
23  * <LinearConvertedValue name="..." factor="..." offset="..."/>
24  * @param factor
25  * @param offset
26  */
27  LinearConfig(float factor, float offset);
28  LinearConfig() = default;
29 
30  /**
31  * @brief Perform partial override
32  * @return resulting object (=*this)
33  */
35 
36  /**
37  * @brief Set the absolute value for factor, keep sign unaffected
38  * @param factorAbs new absolute value
39  */
40  void setFactorAbsoluteValue(float factorAbs);
41 
42  /**
43  * @brief Set the offset
44  * @param offset new offset
45  */
46  void setOffset(float offset);
47 
48  /**
49  * @brief Set the new factor sign, keep the factor absolute value unaffected
50  * @param isNegative
51  */
52  void setFactorIsNegative(bool isNegative);
53 
54  /**
55  * @brief Get the factor
56  * @return Get the offset
57  */
58  float getFactor() const;
59  float getOffset() const;
60 
61  private:
62  std::optional<float> factorAbs;
63  std::optional<float> offset;
64  std::optional<bool> negativeFactor;
65  };
66 
67 
69  {
70  public:
71  explicit ModularConvertedValueConfig(float zeroOffset,
72  float discontinuityOffset,
73  float maxValue,
74  bool isInverted);
75  ModularConvertedValueConfig() = default;
76 
78 
79  void setZeroOffset(float zeroOffset);
80  void setIsInverted(bool isNegative);
81 
82  float getZeroOffset() const;
83  float getDiscontinuityOffset() const;
84  float getMaxValue() const;
85  bool getIsInverted() const;
86 
87  private:
88  std::optional<float> zeroOffset;
89  std::optional<float> discontinuityOffset;
90  std::optional<float> maxValue;
91  std::optional<bool> isInverted;
92  };
93 
94 
95  /*
96  * Here additional complex types can be declared if they are needed.
97  * Do not forget to add the parser code.
98  * If partial overrides should be possible for a new type they can be handled in Config::set
99  */
100 
101 
102 } // namespace armarx::control::hardware_config::types
armarx::control::hardware_config::types::LinearConfig::setFactorIsNegative
void setFactorIsNegative(bool isNegative)
Set the new factor sign, keep the factor absolute value unaffected.
Definition: Types.cpp:47
armarx::control::hardware_config::types::ModularConvertedValueConfig::getIsInverted
bool getIsInverted() const
Definition: Types.cpp:135
armarx::control::hardware_config::types::LinearConfig
The LinearConfig class represents a linear conversion and has a factor and offset.
Definition: Types.h:17
armarx::control::hardware_config::types::ModularConvertedValueConfig::ModularConvertedValueConfig
ModularConvertedValueConfig()=default
armarx::control::hardware_config::types::LinearConfig::getOffset
float getOffset() const
Definition: Types.cpp:59
armarx::control::hardware_config::types::ModularConvertedValueConfig::getDiscontinuityOffset
float getDiscontinuityOffset() const
Definition: Types.cpp:123
armarx::control::hardware_config::types::ModularConvertedValueConfig::overrideWith
ModularConvertedValueConfig overrideWith(const ModularConvertedValueConfig &)
Definition: Types.cpp:79
armarx::control::hardware_config::types::LinearConfig::LinearConfig
LinearConfig()=default
Errors.h
armarx::control::hardware_config::types::ModularConvertedValueConfig::getZeroOffset
float getZeroOffset() const
Definition: Types.cpp:117
armarx::control::hardware_config::types::ModularConvertedValueConfig
Definition: Types.h:68
armarx::control::hardware_config::types::LinearConfig::overrideWith
LinearConfig overrideWith(LinearConfig)
Perform partial override.
Definition: Types.cpp:15
armarx::control::hardware_config::types::LinearConfig::getFactor
float getFactor() const
Get the factor.
Definition: Types.cpp:53
armarx::control::hardware_config::types::ModularConvertedValueConfig::setIsInverted
void setIsInverted(bool isNegative)
Definition: Types.cpp:111
armarx::control::hardware_config::types::LinearConfig::setOffset
void setOffset(float offset)
Set the offset.
Definition: Types.cpp:41
armarx::control::hardware_config::types::ModularConvertedValueConfig::getMaxValue
float getMaxValue() const
Definition: Types.cpp:129
armarx::control::hardware_config::types::ModularConvertedValueConfig::setZeroOffset
void setZeroOffset(float zeroOffset)
Definition: Types.cpp:105
armarx::control::hardware_config::types
Definition: Types.cpp:4
armarx::control::hardware_config::types::LinearConfig::setFactorAbsoluteValue
void setFactorAbsoluteValue(float factorAbs)
Set the absolute value for factor, keep sign unaffected.
Definition: Types.cpp:35