control: Modify target_from_group_max increasing case
In the action target_from_group_max, when the sensor's
value is increasing, it updates the previous sensor value
(_prevGroupValue = groupValue) without checking the hysteresis.
This causes the previous sensor value to "tightly" follow the
current sensor value. As a result, in case of a large negative
hysteresis (_negHysteresis >= 2), the sensor will never be able
to pass the hysteresis check which needs a large gap between
the previous and the current value.
This patch changes to update _prevGroupValue = groupValue only when
it passes the hysteresis check in the increasing case. This also
comments out the logging of group processing failure to avoid
massive logging (~ every 1s).
Signed-off-by: Chau Ly <chaul@amperecomputing.com>
Change-Id: Ic805ecac60359b6df695864823bc36c027d14805
diff --git a/control/json/actions/target_from_group_max.cpp b/control/json/actions/target_from_group_max.cpp
index 72c9ab0..40ed0f2 100644
--- a/control/json/actions/target_from_group_max.cpp
+++ b/control/json/actions/target_from_group_max.cpp
@@ -105,47 +105,44 @@
}
// Value is increasing from previous && greater than negative
// hysteresis
- else
+ else if ((groupValue > _prevGroupValue) &&
+ (groupValue - _prevGroupValue > _negHysteresis))
{
- if (groupValue - _prevGroupValue > _negHysteresis)
+ for (auto it = _valueToSpeedMap.begin();
+ it != _valueToSpeedMap.end(); ++it)
{
- for (auto it = _valueToSpeedMap.begin();
- it != _valueToSpeedMap.end(); ++it)
+ // Value is at/below the first map key, set speed to the
+ // first map key's value
+ if (it == _valueToSpeedMap.begin() &&
+ groupValue <= it->first)
{
- // Value is at/below the first map key, set speed to the
- // first map key's value
- if (it == _valueToSpeedMap.begin() &&
- groupValue <= it->first)
- {
- groupSpeed = it->second;
- break;
- }
- // Value is at/above last map key, set speed to the last
- // map key's value
- else if (std::next(it, 1) == _valueToSpeedMap.end() &&
- groupValue >= it->first)
- {
- groupSpeed = it->second;
- break;
- }
- // Value increased & transitioned across a map key,
- // update speed to the next map key's value when new
- // value is above map's key and the key is at/above the
- // previous value
- if (groupValue > it->first &&
- it->first >= _prevGroupValue)
- {
- groupSpeed = std::next(it, 1)->second;
- }
- // Value increased & transitioned across a map key,
- // update speed to the map key's value when new value is
- // at the map's key and the key is above the previous
- // value
- else if (groupValue == it->first &&
- it->first > _prevGroupValue)
- {
- groupSpeed = it->second;
- }
+ groupSpeed = it->second;
+ break;
+ }
+ // Value is at/above last map key, set speed to the last
+ // map key's value
+ else if (std::next(it, 1) == _valueToSpeedMap.end() &&
+ groupValue >= it->first)
+ {
+ groupSpeed = it->second;
+ break;
+ }
+ // Value increased & transitioned across a map key,
+ // update speed to the next map key's value when new
+ // value is above map's key and the key is at/above the
+ // previous value
+ if (groupValue > it->first && it->first >= _prevGroupValue)
+ {
+ groupSpeed = std::next(it, 1)->second;
+ }
+ // Value increased & transitioned across a map key,
+ // update speed to the map key's value when new value is
+ // at the map's key and the key is above the previous
+ // value
+ else if (groupValue == it->first &&
+ it->first > _prevGroupValue)
+ {
+ groupSpeed = it->second;
}
}
_prevGroupValue = groupValue;
@@ -165,8 +162,8 @@
}
else
{
- std::cerr << "Failed to process groups for " << ActionBase::getName()
- << ": Further processing will be skipped \n";
+ // std::cerr << "Failed to process groups for " << ActionBase::getName()
+ // << ": Further processing will be skipped \n";
}
}