mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-03 11:24:10 +01:00
GCS/Scope: Make smooth interpolation (and internal sum) be long term correct despite limited floating point accuracy, but keep constant overhead
This commit is contained in:
parent
dfd18d43b5
commit
5af9a2558c
@ -55,6 +55,8 @@ PlotData::PlotData(QString p_uavObject, QString p_uavField)
|
|||||||
scalePower = 0;
|
scalePower = 0;
|
||||||
interpolationSamples = 1;
|
interpolationSamples = 1;
|
||||||
interpolationSum = 0.0f;
|
interpolationSum = 0.0f;
|
||||||
|
correctionSum = 0.0f;
|
||||||
|
correctionCount = 0;
|
||||||
yMinimum = 0;
|
yMinimum = 0;
|
||||||
yMaximum = 0;
|
yMaximum = 0;
|
||||||
|
|
||||||
@ -95,12 +97,23 @@ bool SequencialPlotData::append(UAVObject* obj)
|
|||||||
if (field) {
|
if (field) {
|
||||||
|
|
||||||
//Shift data forward and put the new value at the front
|
//Shift data forward and put the new value at the front
|
||||||
yDataHistory->append( valueAsDouble(obj, field) * pow(10, scalePower));
|
|
||||||
interpolationSum += valueAsDouble(obj, field) * pow(10, scalePower);
|
// calculate interpolated (smoothed) value
|
||||||
|
double currentValue = valueAsDouble(obj, field) * pow(10, scalePower);
|
||||||
|
yDataHistory->append( currentValue );
|
||||||
|
interpolationSum += currentValue;
|
||||||
if(yDataHistory->size() > interpolationSamples) {
|
if(yDataHistory->size() > interpolationSamples) {
|
||||||
interpolationSum -= yDataHistory->first();
|
interpolationSum -= yDataHistory->first();
|
||||||
yDataHistory->pop_front();
|
yDataHistory->pop_front();
|
||||||
}
|
}
|
||||||
|
// make sure to correct the sum every interpolationSamples steps to prevent it
|
||||||
|
// from running away due to flouting point rounding errors
|
||||||
|
correctionSum += currentValue;
|
||||||
|
if (++correctionCount >= interpolationSamples) {
|
||||||
|
interpolationSum = correctionSum;
|
||||||
|
correctionSum = 0.0f;
|
||||||
|
correctionCount = 0;
|
||||||
|
}
|
||||||
yData->append(interpolationSum/yDataHistory->size());
|
yData->append(interpolationSum/yDataHistory->size());
|
||||||
if (yData->size() > m_xWindowSize) {
|
if (yData->size() > m_xWindowSize) {
|
||||||
yData->pop_front();
|
yData->pop_front();
|
||||||
@ -127,12 +140,22 @@ bool ChronoPlotData::append(UAVObject* obj)
|
|||||||
//Put the new value at the front
|
//Put the new value at the front
|
||||||
QDateTime NOW = QDateTime::currentDateTime();
|
QDateTime NOW = QDateTime::currentDateTime();
|
||||||
|
|
||||||
yDataHistory->append( valueAsDouble(obj, field) * pow(10, scalePower));
|
// calculate interpolated (smoothed) value
|
||||||
interpolationSum += valueAsDouble(obj, field) * pow(10, scalePower);
|
double currentValue = valueAsDouble(obj, field) * pow(10, scalePower);
|
||||||
|
yDataHistory->append( currentValue );
|
||||||
|
interpolationSum += currentValue;
|
||||||
if(yDataHistory->size() > interpolationSamples) {
|
if(yDataHistory->size() > interpolationSamples) {
|
||||||
interpolationSum -= yDataHistory->first();
|
interpolationSum -= yDataHistory->first();
|
||||||
yDataHistory->pop_front();
|
yDataHistory->pop_front();
|
||||||
}
|
}
|
||||||
|
// make sure to correct the sum every interpolationSamples steps to prevent it
|
||||||
|
// from running away due to flouting point rounding errors
|
||||||
|
correctionSum += currentValue;
|
||||||
|
if (++correctionCount >= interpolationSamples) {
|
||||||
|
interpolationSum = correctionSum;
|
||||||
|
correctionSum = 0.0f;
|
||||||
|
correctionCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
double valueX = NOW.toTime_t() + NOW.time().msec() / 1000.0;
|
double valueX = NOW.toTime_t() + NOW.time().msec() / 1000.0;
|
||||||
double valueY = interpolationSum/yDataHistory->size();
|
double valueY = interpolationSum/yDataHistory->size();
|
||||||
|
@ -74,6 +74,8 @@ public:
|
|||||||
int scalePower; //This is the power to which each value must be raised
|
int scalePower; //This is the power to which each value must be raised
|
||||||
int interpolationSamples;
|
int interpolationSamples;
|
||||||
double interpolationSum;
|
double interpolationSum;
|
||||||
|
double correctionSum;
|
||||||
|
int correctionCount;
|
||||||
double yMinimum;
|
double yMinimum;
|
||||||
double yMaximum;
|
double yMaximum;
|
||||||
double m_xWindowSize;
|
double m_xWindowSize;
|
||||||
|
@ -162,7 +162,7 @@
|
|||||||
<item row="9" column="0">
|
<item row="9" column="0">
|
||||||
<widget class="QLabel" name="label_10">
|
<widget class="QLabel" name="label_10">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Smooth Interpolation:</string>
|
<string>Display smoothed interpolation:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -294,7 +294,7 @@ Update</string>
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="LoggingEnable">
|
<widget class="QCheckBox" name="LoggingEnable">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Log data to csv file</string>
|
<string>Log data to csv file (not interpolated)</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Loading…
Reference in New Issue
Block a user