feat: chart grid, pressure tolerance bands, QDelivery RPM normalization, pump page polish

Charts
- Add faint background grid (0.75px, #E0E0E0) to all live charts; matches PDF report style
- Show min/max tolerance bands on P1/P2 pressure charts during test runs (previously only Q-Delivery/Q-Over)
- Broaden BenchService.ToleranceUpdated to fire for every phase receive; UI routes by name
- Clear P1/P2 traces on PhaseChanged alongside Delivery/Over

CAN
- Normalize QDelivery flow rate to 1000 RPM reference before IIR filter so RPM spikes are low-pass filtered with flow-rate transients (matches old_source behavior)

Pump page
- Reorder columns: identification left, commands center, live data right
- PreIn control always visible; disabled when pump lacks pre-injection (rename IsPreInVisible -> IsPreInAvailable)
- Swap value/label order in command cards
- Remove redundant KlineErrors row from identification card

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-04-20 21:42:30 +02:00
parent 69bfda54e1
commit d9775b48be
8 changed files with 80 additions and 39 deletions

View File

@@ -44,6 +44,15 @@ namespace HC_APTBS.Infrastructure.Pcan
private Dictionary<uint, List<CanBusParameter>> _parameterMap = new();
private readonly object _mapLock = new();
// Cached reference to the bench RPM parameter, re-resolved on every SetParameters /
// AddParameters call. Used to normalize QDelivery (flow rate) against shaft speed
// before the IIR low-pass filter runs, so that RPM spikes are filtered alongside
// flow-rate transients rather than bleeding into the displayed value unfiltered.
// Matches old_source behavior (Herlic2.0/MainWindow.xaml.cs:656, 1874).
private CanBusParameter? _benchRpmParam;
private const double QDeliveryReferenceRpm = 1000.0;
private const double QDeliveryMinRpm = 1.0;
private Thread? _readThread;
private AutoResetEvent? _receiveEvent;
private volatile bool _stopRead = true;
@@ -228,6 +237,7 @@ namespace HC_APTBS.Infrastructure.Pcan
lock (_mapLock)
{
_parameterMap = parameters;
ResolveBenchRpmParam();
}
}
@@ -241,6 +251,24 @@ namespace HC_APTBS.Infrastructure.Pcan
if (!_parameterMap.ContainsKey(kv.Key))
_parameterMap.Add(kv.Key, kv.Value);
}
ResolveBenchRpmParam();
}
}
// Call under _mapLock.
private void ResolveBenchRpmParam()
{
_benchRpmParam = null;
foreach (var list in _parameterMap.Values)
{
foreach (var p in list)
{
if (p.Name == BenchParameterNames.BenchRpm)
{
_benchRpmParam = p;
return;
}
}
}
}
@@ -508,15 +536,27 @@ namespace HC_APTBS.Infrastructure.Pcan
}
// Spike rejection for QDelivery: discard values that are more than
// 100x the previous reading (caused by relay switching noise).
// 100x the previous raw reading (caused by relay switching noise).
// Compare against the previous raw-normalized value below.
if (param.Name == BenchParameterNames.QDelivery)
{
if (previousValue > 0.1 && param.Value > previousValue * 100)
// Normalize raw flow rate to a 1000 RPM reference BEFORE filtering,
// so that RPM spikes are low-pass filtered together with flow-rate
// transients rather than appearing as instantaneous jumps in the
// normalized output.
double rpm = _benchRpmParam?.Value ?? 0;
double normalized = rpm < QDeliveryMinRpm
? 0
: param.Value * (QDeliveryReferenceRpm / rpm);
if (previousValue > 0.1 && normalized > previousValue * 100)
{
_log.Warning(LogId,
$"QDelivery spike suppressed: prev={previousValue:F3}, new={param.Value:F3}");
param.Value = previousValue;
$"QDelivery spike suppressed: prev={previousValue:F3}, new={normalized:F3}");
normalized = previousValue;
}
param.Value = normalized;
}
// Apply single-pole IIR low-pass filter.

View File

@@ -754,13 +754,10 @@ namespace HC_APTBS.Services.Impl
}
}
// Notify chart view of expected tolerance bands.
// Notify chart view of expected tolerance bands for every receive.
// The UI layer routes to the appropriate chart by parameter name.
foreach (var recv in phase.Receives)
{
if (recv.Name == BenchParameterNames.QDelivery ||
recv.Name == BenchParameterNames.QOver)
ToleranceUpdated?.Invoke(recv.Name, recv.Value, recv.Tolerance);
}
ToleranceUpdated?.Invoke(recv.Name, recv.Value, recv.Tolerance);
// ── Step 4: Conditioning time countdown ───────────────────────────
sw.Stop();

View File

@@ -252,6 +252,8 @@ namespace HC_APTBS.ViewModels
// Clear real-time plot traces at each new phase boundary.
FlowmeterChart.Delivery.Clear();
FlowmeterChart.Over.Clear();
BenchPage.PressureTrace.P1.Clear();
BenchPage.PressureTrace.P2.Clear();
});
_bench.PhaseTimerTick += (section, remaining, total) => App.Current.Dispatcher.Invoke(
() => TestPanel.ApplyPhaseTimerTick(section, remaining, total));
@@ -269,6 +271,10 @@ namespace HC_APTBS.ViewModels
{
TestPanel.UpdateLiveIndicator(paramName, value);
FlowmeterChart.SetTolerance(paramName, value, tolerance);
if (paramName == BenchParameterNames.Pressure)
BenchPage.PressureTrace.P1.SetTolerance(value, tolerance);
else if (paramName == BenchParameterNames.AnalogSensor2)
BenchPage.PressureTrace.P2.SetTolerance(value, tolerance);
});
_bench.MeasurementSampled += (name, value) => App.Current.Dispatcher.Invoke(() =>
@@ -277,6 +283,10 @@ namespace HC_APTBS.ViewModels
FlowmeterChart.Delivery.AddValue(value);
else if (name == BenchParameterNames.QOver)
FlowmeterChart.Over.AddValue(value);
else if (name == BenchParameterNames.Pressure)
BenchPage.PressureTrace.P1.AddValue(value);
else if (name == BenchParameterNames.AnalogSensor2)
BenchPage.PressureTrace.P2.AddValue(value);
});
_bench.EmergencyStopTriggered += reason => App.Current.Dispatcher.Invoke(() =>
{
@@ -329,7 +339,7 @@ namespace HC_APTBS.ViewModels
_can.RegisterPumpMessageIds(GetReceiveMessageIds(pump.ParametersById));
// Configure pump control sliders.
PumpControl.IsPreInVisible = pump.HasPreInjection;
PumpControl.IsPreInAvailable = pump.HasPreInjection;
PumpControl.IsEnabled = true;
PumpControl.Reset();

View File

@@ -64,7 +64,7 @@ namespace HC_APTBS.ViewModels
// ── Visibility / enablement ───────────────────────────────────────────────
/// <summary>True when the current pump supports pre-injection.</summary>
[ObservableProperty] private bool _isPreInVisible;
[ObservableProperty] private bool _isPreInAvailable;
/// <summary>True when a pump is selected and CAN is connected.</summary>
[ObservableProperty] private bool _isEnabled;

View File

@@ -79,7 +79,8 @@ namespace HC_APTBS.ViewModels
new Axis
{
AnimationsSpeed = TimeSpan.Zero,
MinLimit = 0
MinLimit = 0,
SeparatorsPaint = new SolidColorPaint(new SKColor(224, 224, 224), 0.75f)
}
};
}

View File

@@ -32,12 +32,12 @@
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" MinWidth="260"/>
<ColumnDefinition Width="1.5*"/>
<ColumnDefinition Width="1*" MinWidth="280"/>
<ColumnDefinition Width="1.5*" />
</Grid.ColumnDefinitions>
<!-- Col 0: Commands (top 2*) + Idling Calibration (bottom 1*) -->
<Grid Grid.Column="0">
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition Height="1*"/>
@@ -48,10 +48,10 @@
</Grid>
<!-- Col 1: Live Data (full height) -->
<uc:PumpLiveDataCard Grid.Column="1"/>
<uc:PumpLiveDataCard Grid.Column="2"/>
<!-- Col 2: Identification (Auto) + DTCs (*) -->
<Grid Grid.Column="2">
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>

View File

@@ -10,8 +10,6 @@
<!-- DataContext = PumpControlViewModel (via {Binding PumpControl}) -->
<UserControl.Resources>
<BooleanToVisibilityConverter x:Key="BoolToVis"/>
<Style x:Key="SettingsTextBox" TargetType="TextBox">
<Setter Property="Width" Value="44"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
@@ -81,15 +79,15 @@
Style="{StaticResource PumpCommandLabel}"
Margin="0,2,0,6"/>
<!-- Parameter name (above current value) -->
<TextBlock Text="{DynamicResource Pump.Commands.Fbkw}"
Style="{StaticResource PumpCommandLabel}"
Margin="0,0,0,2"/>
<!-- Editable value box -->
<TextBox Text="{Binding FbkwValue, UpdateSourceTrigger=PropertyChanged, StringFormat=F2}"
Style="{StaticResource PumpCommandValue}"/>
<!-- Parameter name -->
<TextBlock Text="{DynamicResource Pump.Commands.Fbkw}"
Style="{StaticResource PumpCommandLabel}"
Margin="0,6,0,0"/>
<!-- Settings popup -->
<Popup IsOpen="{Binding IsChecked, ElementName=FbkwToggle}"
StaysOpen="False" Placement="Bottom" AllowsTransparency="True">
@@ -140,12 +138,12 @@
Style="{StaticResource PumpCommandLabel}"
Margin="0,2,0,6"/>
<TextBox Text="{Binding MeValue, UpdateSourceTrigger=PropertyChanged, StringFormat=F2}"
Style="{StaticResource PumpCommandValue}"/>
<TextBlock Text="{DynamicResource Pump.Commands.Me}"
Style="{StaticResource PumpCommandLabel}"
Margin="0,6,0,0"/>
Margin="0,0,0,2"/>
<TextBox Text="{Binding MeValue, UpdateSourceTrigger=PropertyChanged, StringFormat=F2}"
Style="{StaticResource PumpCommandValue}"/>
<Popup IsOpen="{Binding IsChecked, ElementName=MeToggle}"
StaysOpen="False" Placement="Bottom" AllowsTransparency="True">
@@ -168,9 +166,9 @@
</Popup>
</StackPanel>
<!-- ── PreIn (conditional) ─────────────────────────────── -->
<!-- ── PreIn (always visible; disabled when pump lacks pre-injection) ── -->
<StackPanel Grid.Column="2" HorizontalAlignment="Center"
Visibility="{Binding IsPreInVisible, Converter={StaticResource BoolToVis}}">
IsEnabled="{Binding IsPreInAvailable}">
<ToggleButton x:Name="PreInToggle"
Width="28" Height="22"
HorizontalAlignment="Center"
@@ -197,12 +195,12 @@
Style="{StaticResource PumpCommandLabel}"
Margin="0,2,0,6"/>
<TextBox Text="{Binding PreInValue, UpdateSourceTrigger=PropertyChanged, StringFormat=F2}"
Style="{StaticResource PumpCommandValue}"/>
<TextBlock Text="{DynamicResource Pump.Commands.PreIn}"
Style="{StaticResource PumpCommandLabel}"
Margin="0,6,0,0"/>
Margin="0,0,0,2"/>
<TextBox Text="{Binding PreInValue, UpdateSourceTrigger=PropertyChanged, StringFormat=F2}"
Style="{StaticResource PumpCommandValue}"/>
<Popup IsOpen="{Binding IsChecked, ElementName=PreInToggle}"
StaysOpen="False" Placement="Bottom" AllowsTransparency="True">

View File

@@ -122,11 +122,6 @@
<TextBlock Text="{DynamicResource PumpId.Dfi}" Style="{StaticResource IdLabel}"/>
<TextBlock Text="{Binding KlineDfi}" Style="{StaticResource IdValue}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,2">
<TextBlock Text="{DynamicResource PumpId.Errors}" Style="{StaticResource IdLabel}"/>
<TextBlock Text="{Binding KlineErrors}" Style="{StaticResource IdValue}"
Foreground="{DynamicResource SystemFillColorCriticalBrush}"/>
</StackPanel>
</StackPanel>
</Grid>