Commit 72e637f3 authored by 潘栩锋's avatar 潘栩锋 🚴

添加 下吹记录旋转总脉冲到文件。开机加载。当刚开机,在复位状态时, 直接写入 位置

parent a852e41a
......@@ -157,6 +157,12 @@
<Run FontSize="20" Text="{Binding RPosOfR,StringFormat={}{0:F0}}"/>p
</TextBlock>
</StackPanel>
<StackPanel Margin="4" >
<TextBlock Text="1圈时间" />
<TextBlock>
<Run FontSize="20" Text="{Binding MinuteOfR,StringFormat={}{0:F1}}"/>min
</TextBlock>
</StackPanel>
<Button Content="配置" Padding="20,5" Margin="5" HorizontalAlignment="Left" Click="btnRotaryClick"></Button>
</StackPanel>
</StackPanel>
......
......@@ -21,6 +21,13 @@ namespace FLY.DownBlowing.Server
/// 方向相反
/// </summary>
public bool IsReversed { get; set; } = true;
/// <summary>
/// 最小一圈脉冲
/// </summary>
const int MinRPosOfR = 8000;
#region 状态
/// <summary>
/// 正方向运行 (逆时针旋转 counter-clockwise)
......@@ -57,6 +64,11 @@ namespace FLY.DownBlowing.Server
/// </summary>
public double RSpeed { get; set; }
/// <summary>
/// 1圈分钟数 RPosOfR/RSpeed/60.0
/// </summary>
public double MinuteOfR { get; set; } = double.NaN;
/// <summary>
/// 旋转塔顺时针换向信号发生时, 旋转架脉冲 (小值)
/// </summary>
......@@ -81,8 +93,8 @@ namespace FLY.DownBlowing.Server
///旋转架全局脉冲, 当前旋转架脉冲 = GlobalRPos - OrgRPos;
/// </summary>
public double RPosGlobal { get; set; } = 0;
public double RPosOfR { get; set; } = 10000;
public double RPosOfR { get; set; } = MinRPosOfR;
public double Angle { get; set; }
/// <summary>
......@@ -103,7 +115,7 @@ namespace FLY.DownBlowing.Server
WinderAccessory winderAccessory;
DispatcherTimer dispatcherTimer;
Stopwatch stopwatch_rpos;
double rposOfRInFile;
public RotarySystem()
{
......@@ -115,6 +127,18 @@ namespace FLY.DownBlowing.Server
if (!Load())
Save();
rposOfRInFile = LoadRPosOfR();
if (double.IsNaN(rposOfRInFile))
{
rposOfRInFile = 14000;
SaveRPosOfR(rposOfRInFile);
}
if (!double.IsNaN(rposOfRInFile) && rposOfRInFile > MinRPosOfR)
RPosOfR = rposOfRInFile;
Misc.BindingOperations.SetBinding(winderAccessory, nameof(winderAccessory.T1Velocity), () =>
{
TractionVelocity = winderAccessory.T1Velocity;
......@@ -136,6 +160,7 @@ namespace FLY.DownBlowing.Server
Misc.BindingOperations.SetBinding(winderAccessory, nameof(winderAccessory.RotaryFreqSet), () =>
{
RotaryFreqSet = winderAccessory.RotaryFreqSet;
updateMinuteOfR();
});
Misc.BindingOperations.SetBinding(winderAccessory, nameof(winderAccessory.RotaryFreq), () =>
......@@ -182,6 +207,16 @@ namespace FLY.DownBlowing.Server
RSpeed = 0;
}
}
void updateMinuteOfR()
{
if (RotaryFreqSet > 0 && RPosOfR >= MinRPosOfR)
{
MinuteOfR = RPosOfR / RotaryFreqSet / 60;
}
else {
MinuteOfR = double.NaN;
}
}
private void DispatcherTimer_Tick(object sender, EventArgs e)
{
double totalSeconds = stopwatch_rpos.Elapsed.TotalSeconds;
......@@ -246,7 +281,22 @@ namespace FLY.DownBlowing.Server
if (IsTurnSign1)
{
RPosAtTurnSign1 = RPosGlobal;
RPosOfR = RPosAtTurnSign1 - RPosAtTurnSign0;
double rposOfR = RPosAtTurnSign1 - RPosAtTurnSign0;
if (!double.IsNaN(rposOfRInFile))
{
if (Math.Abs(rposOfRInFile - rposOfR) > rposOfRInFile / 360)
{
//变化量大于1°保存
rposOfRInFile = rposOfR;
SaveRPosOfR(rposOfRInFile);
}
}
else {
rposOfRInFile = rposOfR;
SaveRPosOfR(rposOfRInFile);
}
RPosOfR = rposOfR;
AddSign(1);
}
}
......@@ -278,6 +328,20 @@ namespace FLY.DownBlowing.Server
AddSign(20);
}
}
else
{
if (IsOrgSign)
{
//现在既不是正向,也不是反向
if (double.IsNaN(RPosAtOrgSign))
{
//刚开机
RPosAtTurnSign0 = RPosGlobal - RPosOfR / 2;
RPosAtOrgSign = RPosGlobal;
RPosAtTurnSign1 = RPosGlobal + RPosOfR / 2;
}
}
}
}
else if (e.PropertyName == nameof(IsForw))
{
......@@ -301,6 +365,42 @@ namespace FLY.DownBlowing.Server
{
return RotarySystemJsonDb.Load(this, filePath);
}
void SaveRPosOfR(double rposOfR)
{
string file_path = "RPosOfR.json";
try
{
string json = JsonConvert.SerializeObject(rposOfR, Formatting.Indented);
File.WriteAllText(file_path, json);
}
catch
{
//异常,没有json 编码失败
}
}
double LoadRPosOfR()
{
string file_path = "RPosOfR.json";
if (File.Exists(file_path))
{
try
{
string json = File.ReadAllText(file_path);
return JsonConvert.DeserializeObject<double>(json);
}
catch
{
//异常,没有json 解码失败
}
}
return double.NaN;
}
}
public class RotarySystemJsonDb
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment