Types.cpp
Go to the documentation of this file.
1 #include "Types.h"
2 
4 {
5  // LinearConfig
6 
7  LinearConfig::LinearConfig(float factor, float offset) :
8  factorAbs(std::abs(factor)), offset(offset), negativeFactor(factor < 0)
9  {
10  ;
11  }
12 
15  {
16  if (other.factorAbs.has_value())
17  {
18  factorAbs = other.factorAbs;
19  }
20 
21  if (other.negativeFactor.has_value())
22  {
23  negativeFactor = other.negativeFactor;
24  }
25 
26  if (other.offset.has_value())
27  {
28  offset = other.offset;
29  }
30  return *this;
31  }
32 
33  void
35  {
36  this->factorAbs = std::make_optional(factorAbs);
37  }
38 
39  void
41  {
42  this->offset = std::make_optional(offset);
43  }
44 
45  void
47  {
48  this->negativeFactor = isNegative;
49  }
50 
51  float
53  {
54  return (negativeFactor.value_or(false) ? -1 : 1) * factorAbs.value_or(1.f);
55  }
56 
57  float
59  {
60  return offset.value_or(0.f);
61  }
62 
63  // ModularConvertedValueConfig
64 
66  float discontinuityOffset,
67  float maxValue,
68  bool isInverted) :
69  zeroOffset(zeroOffset),
70  discontinuityOffset(discontinuityOffset),
71  maxValue(maxValue),
72  isInverted{isInverted}
73  {
74  ;
75  }
76 
77  ModularConvertedValueConfig
79  {
80  if (other.zeroOffset.has_value())
81  {
82  zeroOffset = other.zeroOffset;
83  }
84 
85  if (other.discontinuityOffset.has_value())
86  {
87  discontinuityOffset = other.discontinuityOffset;
88  }
89 
90  if (other.maxValue.has_value())
91  {
92  maxValue = other.maxValue;
93  }
94 
95  if (other.isInverted.has_value())
96  {
97  isInverted = other.isInverted;
98  }
99 
100  return *this;
101  }
102 
103  void
105  {
106  this->zeroOffset = zeroOffset;
107  }
108 
109  void
111  {
112  this->isInverted = isInverted;
113  }
114 
115  float
117  {
118  return zeroOffset.value_or(0.f);
119  }
120 
121  float
123  {
124  return discontinuityOffset.value_or(0.f);
125  }
126 
127  float
129  {
130  return maxValue.value_or(0.f);
131  }
132 
133  bool
135  {
136  return isInverted.value_or(false);
137  }
138 
139 
140 } // 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:46
armarx::control::hardware_config::types::ModularConvertedValueConfig::getIsInverted
bool getIsInverted() const
Definition: Types.cpp:134
armarx::control::hardware_config::types::LinearConfig
The LinearConfig class represents a linear conversion and has a factor and offset.
Definition: Types.h:16
armarx::control::hardware_config::types::ModularConvertedValueConfig::ModularConvertedValueConfig
ModularConvertedValueConfig()=default
armarx::control::hardware_config::types::LinearConfig::getOffset
float getOffset() const
Definition: Types.cpp:58
armarx::control::hardware_config::types::ModularConvertedValueConfig::getDiscontinuityOffset
float getDiscontinuityOffset() const
Definition: Types.cpp:122
armarx::control::hardware_config::types::ModularConvertedValueConfig::overrideWith
ModularConvertedValueConfig overrideWith(const ModularConvertedValueConfig &)
Definition: Types.cpp:78
armarx::abs
std::vector< T > abs(const std::vector< T > &v)
Definition: VectorHelpers.h:281
armarx::control::hardware_config::types::LinearConfig::LinearConfig
LinearConfig()=default
Types.h
armarx::control::hardware_config::types::ModularConvertedValueConfig::getZeroOffset
float getZeroOffset() const
Definition: Types.cpp:116
armarx::control::hardware_config::types::ModularConvertedValueConfig
Definition: Types.h:66
armarx::control::hardware_config::types::LinearConfig::overrideWith
LinearConfig overrideWith(LinearConfig)
Perform partial override.
Definition: Types.cpp:14
armarx::control::hardware_config::types::LinearConfig::getFactor
float getFactor() const
Get the factor.
Definition: Types.cpp:52
armarx::control::hardware_config::types::ModularConvertedValueConfig::setIsInverted
void setIsInverted(bool isNegative)
Definition: Types.cpp:110
std
Definition: Application.h:66
armarx::control::hardware_config::types::LinearConfig::setOffset
void setOffset(float offset)
Set the offset.
Definition: Types.cpp:40
armarx::control::hardware_config::types::ModularConvertedValueConfig::getMaxValue
float getMaxValue() const
Definition: Types.cpp:128
armarx::control::hardware_config::types::ModularConvertedValueConfig::setZeroOffset
void setZeroOffset(float zeroOffset)
Definition: Types.cpp:104
armarx::control::hardware_config::types
Definition: Types.cpp:3
armarx::control::hardware_config::types::LinearConfig::setFactorAbsoluteValue
void setFactorAbsoluteValue(float factorAbs)
Set the absolute value for factor, keep sign unaffected.
Definition: Types.cpp:34