Types.cpp
Go to the documentation of this file.
1 #include "Types.h"
2 
3 
5 {
6  // LinearConfig
7 
8  LinearConfig::LinearConfig(float factor, float offset) :
9  factorAbs(std::abs(factor)), offset(offset), negativeFactor(factor < 0)
10  {
11  ;
12  }
13 
16  {
17  if (other.factorAbs.has_value())
18  {
19  factorAbs = other.factorAbs;
20  }
21 
22  if (other.negativeFactor.has_value())
23  {
24  negativeFactor = other.negativeFactor;
25  }
26 
27  if (other.offset.has_value())
28  {
29  offset = other.offset;
30  }
31  return *this;
32  }
33 
34  void
36  {
37  this->factorAbs = std::make_optional(factorAbs);
38  }
39 
40  void
42  {
43  this->offset = std::make_optional(offset);
44  }
45 
46  void
48  {
49  this->negativeFactor = isNegative;
50  }
51 
52  float
54  {
55  return (negativeFactor.value_or(false) ? -1 : 1) * factorAbs.value_or(1.f);
56  }
57 
58  float
60  {
61  return offset.value_or(0.f);
62  }
63 
64  // ModularConvertedValueConfig
65 
67  float discontinuityOffset,
68  float maxValue,
69  bool isInverted) :
70  zeroOffset(zeroOffset),
71  discontinuityOffset(discontinuityOffset),
72  maxValue(maxValue),
73  isInverted{isInverted}
74  {
75  ;
76  }
77 
78  ModularConvertedValueConfig
80  {
81  if (other.zeroOffset.has_value())
82  {
83  zeroOffset = other.zeroOffset;
84  }
85 
86  if (other.discontinuityOffset.has_value())
87  {
88  discontinuityOffset = other.discontinuityOffset;
89  }
90 
91  if (other.maxValue.has_value())
92  {
93  maxValue = other.maxValue;
94  }
95 
96  if (other.isInverted.has_value())
97  {
98  isInverted = other.isInverted;
99  }
100 
101  return *this;
102  }
103 
104  void
106  {
107  this->zeroOffset = zeroOffset;
108  }
109 
110  void
112  {
113  this->isInverted = isInverted;
114  }
115 
116  float
118  {
119  return zeroOffset.value_or(0.f);
120  }
121 
122  float
124  {
125  return discontinuityOffset.value_or(0.f);
126  }
127 
128  float
130  {
131  return maxValue.value_or(0.f);
132  }
133 
134  bool
136  {
137  return isInverted.value_or(false);
138  }
139 
140 
141 } // 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::abs
std::vector< T > abs(const std::vector< T > &v)
Definition: VectorHelpers.h:253
armarx::control::hardware_config::types::LinearConfig::LinearConfig
LinearConfig()=default
Types.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
std
Definition: Application.h:66
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