This commit is contained in:
2026-05-06 10:52:53 +08:00
parent d581fddb76
commit 07caa61a39
2 changed files with 43 additions and 28 deletions

View File

@@ -165,7 +165,8 @@ namespace 头罩视野.Services
{ {
int n = points.Count; int n = points.Count;
if (n < 5) if (n < 5)
throw new Exception("至少需要5个点来拟合椭圆"); //throw new Exception("至少需要5个点来拟合椭圆");
return new (0,0,0,0,0) ;
// 这里是正确写法 // 这里是正确写法
var M = MathNetMatrix.Build.Dense(n, 5); var M = MathNetMatrix.Build.Dense(n, 5);

View File

@@ -38,10 +38,15 @@ namespace 头罩视野.Views
// 保存上一条数据(用于去重) // 保存上一条数据(用于去重)
private TestDataStore.TestRecord? _lastRecord; private TestDataStore.TestRecord? _lastRecord;
#region
private double currentAngle;
#endregion
private double _leftTotalArea = 0; // 左目总视野面积 private double _leftTotalArea = 0; // 左目总视野面积
private double _rightTotalArea = 0; // 右目总视野面积 private double _rightTotalArea = 0; // 右目总视野面积
private double _binocularTotalArea = 0; // 双目总视野面积 private double _binocularTotalArea = 0; // 双目总视野面积
double maxBottomViewAngle = 0; //记录所有姿态里的最大下方视野
// 表跟数据存储列表 // 表跟数据存储列表
public List<dynamic> DataList = new List<dynamic>(); public List<dynamic> DataList = new List<dynamic>();
@@ -210,6 +215,8 @@ namespace 头罩视野.Views
private async void Button_Click_Test(object sender, RoutedEventArgs e) private async void Button_Click_Test(object sender, RoutedEventArgs e)
{ {
ma.BtnClickFunction(Function.ButtonType., 100); ma.BtnClickFunction(Function.ButtonType., 100);
ButtonTest.Content = "测试中...."; ButtonTest.Content = "测试中....";
testTimer.Start(); testTimer.Start();
@@ -234,7 +241,8 @@ namespace 头罩视野.Views
bool isRightOnly = btnRight.Content.ToString() == "右眼开" && btnLeft.Content.ToString() == "左眼关"; bool isRightOnly = btnRight.Content.ToString() == "右眼开" && btnLeft.Content.ToString() == "左眼关";
bool isBinocular = btnLeft.Content.ToString() == "左眼开" && btnRight.Content.ToString() == "右眼开"; bool isBinocular = btnLeft.Content.ToString() == "左眼开" && btnRight.Content.ToString() == "右眼开";
if (isLeftOnly) if (isLeftOnly)
{ _leftTotalArea = 0; {
_leftTotalArea = 0;
} }
else if (isRightOnly) else if (isRightOnly)
{ {
@@ -246,7 +254,7 @@ namespace 头罩视野.Views
_binocularTotalArea = 0; _binocularTotalArea = 0;
} }
double maxBottomViewAngle = 0; ;//记录所有姿态里的最大下方视野
// 2. 从0转到180每 stepAngle 执行一次 // 2. 从0转到180每 stepAngle 执行一次
for (double current = stepAngle; current <= 180; current += stepAngle) for (double current = stepAngle; current <= 180; current += stepAngle)
{ {
@@ -283,18 +291,14 @@ namespace 头罩视野.Views
{ {
maxBottomViewAngle = bottomViewAngle; maxBottomViewAngle = bottomViewAngle;
} }
// 如果你要取最小值,用下面这段 // 如果你要取最小值,用下面这段
// if (bottomViewAngle < minBottomViewAngle && bottomViewAngle > 0) // if (bottomViewAngle < minBottomViewAngle && bottomViewAngle > 0)
// { // {
// minBottomViewAngle = bottomViewAngle; // minBottomViewAngle = bottomViewAngle;
// } // }
} }
isFinished = _modbusMaster.ReadCoils(1, 102, 1)[0];
if (isFinished)
{
Button_Click_Stop(null, null);
UpdateVisionResults( maxBottomViewAngle);
}
} }
//页面渲染值 //页面渲染值
@@ -360,7 +364,7 @@ namespace 头罩视野.Views
private async void Timer_Tick(object sender, EventArgs e) private async void Timer_Tick(object sender, EventArgs e)
{ {
System.Diagnostics.Debug.WriteLine("定时器触发了!" + DateTime.Now); //System.Diagnostics.Debug.WriteLine("定时器触发了!" + DateTime.Now);
// 调用你原来的读取方 // 调用你原来的读取方
//await ReadAddr262DataAsync(); //await ReadAddr262DataAsync();
@@ -473,6 +477,16 @@ namespace 头罩视野.Views
}; };
isFinished = _modbusMaster.ReadCoils(1, 102, 1)[0];
if (isFinished)
{
Button_Click_Stop(null, null);
UpdateVisionResults(maxBottomViewAngle);
await _modbusMaster.WriteSingleCoilAsync(1, 102, false);
isFinished = false;
System.Diagnostics.Debug.WriteLine("start11111");
}
await Task.WhenAll(tasks); await Task.WhenAll(tasks);
} }
@@ -529,7 +543,7 @@ namespace 头罩视野.Views
//float value4 = c.UshortToFloat(registers[7], registers[6]); //float value4 = c.UshortToFloat(registers[7], registers[6]);
//float value5 = c.UshortToFloat(registers[9], registers[8]); //float value5 = c.UshortToFloat(registers[9], registers[8]);
//float value6 = c.UshortToFloat(registers[11], registers[10]); //float value6 = c.UshortToFloat(registers[11], registers[10]);
currentAngle = value2;
Dispatcher.Invoke(() => Dispatcher.Invoke(() =>