Калибровка датчика тока. Корректно замеряем напряжение на аккуме.

This commit is contained in:
ftc
2024-04-01 22:15:06 +03:00
parent 74e269b563
commit dcaccbaaf2
12 changed files with 203 additions and 30 deletions
+1
View File
@@ -1,3 +1,4 @@
charger-gui/.vs/ charger-gui/.vs/
charger-gui/bin/ charger-gui/bin/
charger-gui/obj/ charger-gui/obj/
charger-gui/publish/
+19 -13
View File
@@ -36,21 +36,26 @@
<RowDefinition Height="30"/> <RowDefinition Height="30"/>
<RowDefinition Height="30"/> <RowDefinition Height="30"/>
<RowDefinition Height="30"/> <RowDefinition Height="30"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" FontSize="20" Text="I_acc"/> <TextBlock Grid.Row="0" Grid.Column="0" FontSize="20" Text="I_acc"/>
<TextBlock Grid.Row="0" Grid.Column="1" FontSize="20" Text="{Binding Path=IAcc,Mode=OneWay,StringFormat=F4}" /> <TextBlock Grid.Row="0" Grid.Column="1" FontSize="20" Text="{Binding Path=IReal,Mode=OneWay,StringFormat=F4}" />
<TextBlock Grid.Row="1" Grid.Column="0" FontSize="20" Text="U2"/> <TextBlock Grid.Row="1" Grid.Column="0" FontSize="20" Text="U_acc"/>
<TextBlock Grid.Row="1" Grid.Column="1" FontSize="20" Text="{Binding Path=U2,Mode=OneWay,StringFormat=F4}" /> <TextBlock Grid.Row="1" Grid.Column="1" FontSize="20" Text="{Binding Path=UAcc,Mode=OneWay,StringFormat=F4}" />
<TextBlock Grid.Row="2" Grid.Column="0" FontSize="20" Text="U3"/> <TextBlock Grid.Row="2" Grid.Column="0" FontSize="20" Text="I_raw"/>
<TextBlock Grid.Row="2" Grid.Column="1" FontSize="20" Text="{Binding Path=U3,Mode=OneWay,StringFormat=F4}" /> <TextBlock Grid.Row="2" Grid.Column="1" FontSize="20" Text="{Binding Path=IRaw,Mode=OneWay,StringFormat=F4}" />
<TextBlock Grid.Row="3" Grid.Column="0" FontSize="20" Text="U4"/> <TextBlock Grid.Row="3" Grid.Column="0" FontSize="20" Text="U2"/>
<TextBlock Grid.Row="3" Grid.Column="1" FontSize="20" Text="{Binding Path=U4,Mode=OneWay,StringFormat=F4}" /> <TextBlock Grid.Row="3" Grid.Column="1" FontSize="20" Text="{Binding Path=U2,Mode=OneWay,StringFormat=F4}" />
<TextBlock Grid.Row="4" Grid.Column="0" FontSize="20" Text="U5"/> <TextBlock Grid.Row="4" Grid.Column="0" FontSize="20" Text="U3"/>
<TextBlock Grid.Row="4" Grid.Column="1" FontSize="20" Text="{Binding Path=U5,Mode=OneWay,StringFormat=F4}" /> <TextBlock Grid.Row="4" Grid.Column="1" FontSize="20" Text="{Binding Path=U3,Mode=OneWay,StringFormat=F4}" />
<TextBlock Grid.Row="5" Grid.Column="0" FontSize="20" Text="CHARGE"/> <TextBlock Grid.Row="5" Grid.Column="0" FontSize="20" Text="U4"/>
<Ellipse Grid.Row="5" Grid.Column="1" Width="20" Height="20" Fill="{Binding Path=ChargeStatus,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}" /> <TextBlock Grid.Row="5" Grid.Column="1" FontSize="20" Text="{Binding Path=U4,Mode=OneWay,StringFormat=F4}" />
<TextBlock Grid.Row="6" Grid.Column="0" FontSize="20" Text="LAMP"/> <TextBlock Grid.Row="6" Grid.Column="0" FontSize="20" Text="U5"/>
<Ellipse Grid.Row="6" Grid.Column="1" Width="20" Height="20" Fill="{Binding Path=LampStatus,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}" /> <TextBlock Grid.Row="6" Grid.Column="1" FontSize="20" Text="{Binding Path=U5,Mode=OneWay,StringFormat=F4}" />
<TextBlock Grid.Row="7" Grid.Column="0" FontSize="20" Text="CHARGE"/>
<Ellipse Grid.Row="7" Grid.Column="1" Width="20" Height="20" Fill="{Binding Path=ChargeStatus,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Grid.Row="8" Grid.Column="0" FontSize="20" Text="LAMP"/>
<Ellipse Grid.Row="8" Grid.Column="1" Width="20" Height="20" Fill="{Binding Path=LampStatus,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}" />
</Grid> </Grid>
<StackPanel Grid.Row="1" Grid.Column="1"> <StackPanel Grid.Row="1" Grid.Column="1">
<TextBlock FontSize="24" Text="MANUAL"/> <TextBlock FontSize="24" Text="MANUAL"/>
@@ -61,6 +66,7 @@
<TextBlock FontSize="24" Text="AUTO"/> <TextBlock FontSize="24" Text="AUTO"/>
<Button Content="Discharge" Height="40" Click="DischargeButton_Click"/> <Button Content="Discharge" Height="40" Click="DischargeButton_Click"/>
<Button Content="Сharge" Height="40" Click="ChargeButton_Click"/> <Button Content="Сharge" Height="40" Click="ChargeButton_Click"/>
<Button Content="Calibrate I" Height="40" Click="CalibrateButton_Click"/>
</StackPanel> </StackPanel>
<StackPanel Grid.Row="1" Grid.Column="3"> <StackPanel Grid.Row="1" Grid.Column="3">
<TextBlock FontSize="24" Text="TRAIN"/> <TextBlock FontSize="24" Text="TRAIN"/>
+11 -1
View File
@@ -60,6 +60,16 @@ namespace charger_gui
model.IsCharging = !model.IsCharging; model.IsCharging = !model.IsCharging;
} }
private void CalibrateButton_Click(object sender, RoutedEventArgs e)
{
if (model.CurrentOperation != null)
{
model.CurrentOperation.Cancel();
}
model.CurrentOperation = new CalibrateOperation(log, model);
model.CurrentOperation.Start();
}
private void DischargeButton_Click(object sender, RoutedEventArgs e) private void DischargeButton_Click(object sender, RoutedEventArgs e)
{ {
if (model.CurrentOperation != null) if (model.CurrentOperation != null)
@@ -92,7 +102,7 @@ namespace charger_gui
protected override void OnClosed(EventArgs e) protected override void OnClosed(EventArgs e)
{ {
base.OnClosed(e); base.OnClosed(e);
Application.Current.Shutdown(); Environment.Exit(0);
} }
} }
} }
+25 -5
View File
@@ -21,17 +21,27 @@ namespace charger_gui
} }
} }
private float iAcc; private float iRaw;
public float IAcc public float IRaw
{ {
get get
{ {
return iAcc; return iRaw;
} }
set set
{ {
iAcc = value; iRaw = value;
OnPropertyChanged("IAcc"); OnPropertyChanged("IRaw");
OnPropertyChanged("IReal");
}
}
public float IZero { get; internal set; }
public float IReal
{
get
{
return IRaw - IZero;
} }
} }
@@ -60,6 +70,7 @@ namespace charger_gui
{ {
u3 = value; u3 = value;
OnPropertyChanged("U3"); OnPropertyChanged("U3");
OnPropertyChanged("UAcc");
} }
} }
@@ -88,6 +99,15 @@ namespace charger_gui
{ {
u5 = value; u5 = value;
OnPropertyChanged("U5"); OnPropertyChanged("U5");
OnPropertyChanged("UAcc");
}
}
public float UAcc
{
get
{
return U3 - U5;
} }
} }
+73
View File
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- Параметры манифеста UAC
Если вы хотите изменить уровень контроля учетных записей Windows, замените узел
requestedExecutionLevel на один из следующих.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
При указании элемента requestedExecutionLevel будет отключена виртуализация файлов и реестра.
Удалите этот элемент, если виртуализация требуется приложению для обратной
совместимости.
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<defaultAssemblyRequest permissionSetReference="Custom" />
<PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
</applicationRequestMinimum>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Список версий Windows, на которых это приложение было протестировано
и будет работать. Раскомментируйте соответствующие элементы, чтобы ОС Windows
автоматически выбрала наиболее совместимое окружение. -->
<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
</application>
</compatibility>
<!-- Указывает, что приложение поддерживает определение DPI и не будет автоматически масштабироваться Windows при более высоких
значениях DPI. Приложения Windows Presentation Foundation (WPF) по умолчанию поддерживают определение DPI, им не нужно
специально включать параметр для этого. Для приложений Windows Forms на платформе .NET Framework 4.6, для которых задан этот параметр, необходимо
также задать для "EnableWindowsFormsHighDpiAutoResizing" значение "true" в файле app.config.
При этом приложение начинает учитывать длинные пути. Дополнительные сведения см. на странице https://docs.microsoft.com/windows/win32/fileio/maximum-file-path-limitation.-->
<!--
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
</application>
-->
<!-- Включите темы для общих элементов управления и диалоговых окон Windows (Windows XP и более поздние версии) -->
<!--
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
-->
</assembly>
+1 -1
View File
@@ -68,7 +68,7 @@ namespace charger_gui
while (!shouldRestart) while (!shouldRestart)
{ {
var r1 = master.ReadHoldingRegisters(SLAVE_ADDRESS, 0, 2); var r1 = master.ReadHoldingRegisters(SLAVE_ADDRESS, 0, 2);
model.IAcc = ToFloat(r1[0], r1[1]); model.IRaw = ToFloat(r1[0], r1[1]);
var r2 = master.ReadHoldingRegisters(SLAVE_ADDRESS, 6, 8); var r2 = master.ReadHoldingRegisters(SLAVE_ADDRESS, 6, 8);
model.U2 = ToFloat(r2[0], r2[1]); model.U2 = ToFloat(r2[0], r2[1]);
model.U3 = ToFloat(r2[2], r2[3]); model.U3 = ToFloat(r2[2], r2[3]);
+13 -5
View File
@@ -13,7 +13,8 @@
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Deterministic>true</Deterministic> <Deterministic>true</Deterministic>
<PublishUrl>C:\Work\charger\charger-gui\publish\</PublishUrl> <IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>W:\temp\charger-gui\</PublishUrl>
<Install>true</Install> <Install>true</Install>
<InstallFrom>Disk</InstallFrom> <InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled> <UpdateEnabled>false</UpdateEnabled>
@@ -23,12 +24,11 @@
<UpdatePeriodically>false</UpdatePeriodically> <UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired> <UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions> <MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision> <ApplicationRevision>4</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion> <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust> <UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted> <PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled> <BootstrapperEnabled>false</BootstrapperEnabled>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
@@ -59,7 +59,13 @@
<GenerateManifests>true</GenerateManifests> <GenerateManifests>true</GenerateManifests>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<SignManifests>true</SignManifests> <SignManifests>false</SignManifests>
</PropertyGroup>
<PropertyGroup>
<TargetZone>LocalIntranet</TargetZone>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="NModbus4, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="NModbus4, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
@@ -86,6 +92,7 @@
</ApplicationDefinition> </ApplicationDefinition>
<Compile Include="Logger.cs" /> <Compile Include="Logger.cs" />
<Compile Include="operations\AutomaticOperation.cs" /> <Compile Include="operations\AutomaticOperation.cs" />
<Compile Include="operations\CalibrateOperation.cs" />
<Compile Include="operations\TrainOperation.cs" /> <Compile Include="operations\TrainOperation.cs" />
<Compile Include="operations\ChargeOperation.cs" /> <Compile Include="operations\ChargeOperation.cs" />
<Compile Include="operations\DischargeOperation.cs" /> <Compile Include="operations\DischargeOperation.cs" />
@@ -124,6 +131,7 @@
</EmbeddedResource> </EmbeddedResource>
<None Include="charger-gui_TemporaryKey.pfx" /> <None Include="charger-gui_TemporaryKey.pfx" />
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="Properties\app.manifest" />
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput> <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+4 -1
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<PublishUrlHistory /> <PublishUrlHistory>W:\temp\charger-gui\|C:\Work\charger\charger-gui\publish\</PublishUrlHistory>
<InstallUrlHistory /> <InstallUrlHistory />
<SupportUrlHistory /> <SupportUrlHistory />
<UpdateUrlHistory /> <UpdateUrlHistory />
@@ -10,4 +10,7 @@
<FallbackCulture>ru-RU</FallbackCulture> <FallbackCulture>ru-RU</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles> <VerifyUploadedFiles>false</VerifyUploadedFiles>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<EnableSecurityDebugging>false</EnableSecurityDebugging>
</PropertyGroup>
</Project> </Project>
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace charger_gui.operations
{
class CalibrateOperation : AutomaticOperation
{
const float SECONDS_TO_PASS = 10f;
private int passed;
private bool isComplete = false;
public override string Status
{
get
{
if (isComplete) return "Calibrating complete in " + passed + " seconds";
else return "Calibrating, passed " + passed + " seconds";
}
}
public CalibrateOperation(Logger log, MainWindowViewModel model) : base(log, model)
{
}
protected override void Work()
{
log.Log("Calibrating started");
var start = DateTime.Now;
model.IsCharging = false;
model.IsLampOn = false;
Thread.Sleep(500);
float sum = 0;
int cnt = 0;
while (passed < SECONDS_TO_PASS)
{
Thread.Sleep(20);
sum += model.IRaw;
cnt++;
passed = (int)((DateTime.Now - start).TotalSeconds);
OnStatusChanged();
}
model.IZero = sum / cnt;
log.Log("Calibrating complete in " + passed + " seconds");
model.IsLampOn = false;
isComplete = true;
OnStatusChanged();
}
}
}
+2 -2
View File
@@ -32,12 +32,12 @@ namespace charger_gui.operations
model.IsCharging = true; model.IsCharging = true;
model.IsLampOn = false; model.IsLampOn = false;
Thread.Sleep(500); Thread.Sleep(500);
while (model.U3 < MAX_VOLTAGE) while (model.UAcc < MAX_VOLTAGE)
{ {
Thread.Sleep(1000); Thread.Sleep(1000);
passed = (int)((DateTime.Now - start).TotalSeconds); passed = (int)((DateTime.Now - start).TotalSeconds);
OnStatusChanged(); OnStatusChanged();
log.Log("Charging " + passed + "s " + model.U3.ToString("F4")); log.Log("Charging " + passed + "s " + model.UAcc.ToString("F4"));
if (model.U2 < 10f) if (model.U2 < 10f)
{ {
log.Log("Charging error: NO POWER. " + model.U2.ToString("F4")); log.Log("Charging error: NO POWER. " + model.U2.ToString("F4"));
+1 -1
View File
@@ -32,7 +32,7 @@ namespace charger_gui.operations
model.IsCharging = false; model.IsCharging = false;
model.IsLampOn = true; model.IsLampOn = true;
Thread.Sleep(500); Thread.Sleep(500);
while (model.U3 > MIN_VOLTAGE) while (model.UAcc > MIN_VOLTAGE)
{ {
Thread.Sleep(1000); Thread.Sleep(1000);
passed = (int)((DateTime.Now - start).TotalSeconds); passed = (int)((DateTime.Now - start).TotalSeconds);
+1 -1
View File
@@ -47,7 +47,7 @@ namespace charger_gui.operations
Thread.Sleep(50); Thread.Sleep(50);
passed = (int)((DateTime.Now - start).TotalSeconds); passed = (int)((DateTime.Now - start).TotalSeconds);
OnStatusChanged(); OnStatusChanged();
log.Log("Training" + passed + "s " + model.U3.ToString("F4")); log.Log("Training" + passed + "s " + model.UAcc.ToString("F4"));
if (model.U2 < 10f) if (model.U2 < 10f)
{ {
log.Log("Training error: NO POWER. " + model.U2.ToString("F4")); log.Log("Training error: NO POWER. " + model.U2.ToString("F4"));