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

@@ -164,8 +164,9 @@ namespace 头罩视野.Services
public static (double cx, double cy, double a, double b, double area) FitEllipse(List<Point> points)
{
int n = points.Count;
if (n < 5)
throw new Exception("至少需要5个点来拟合椭圆");
if (n < 5)
//throw new Exception("至少需要5个点来拟合椭圆");
return new (0,0,0,0,0) ;
// 这里是正确写法
var M = MathNetMatrix.Build.Dense(n, 5);

View File

@@ -38,10 +38,15 @@ namespace 头罩视野.Views
// 保存上一条数据(用于去重)
private TestDataStore.TestRecord? _lastRecord;
#region
private double currentAngle;
#endregion
private double _leftTotalArea = 0; // 左目总视野面积
private double _rightTotalArea = 0; // 右目总视野面积
private double _binocularTotalArea = 0; // 双目总视野面积
double maxBottomViewAngle = 0; //记录所有姿态里的最大下方视野
// 表跟数据存储列表
public List<dynamic> DataList = new List<dynamic>();
@@ -210,6 +215,8 @@ namespace 头罩视野.Views
private async void Button_Click_Test(object sender, RoutedEventArgs e)
{
ma.BtnClickFunction(Function.ButtonType., 100);
ButtonTest.Content = "测试中....";
testTimer.Start();
@@ -228,25 +235,26 @@ namespace 头罩视野.Views
stepAngle = val; // 正常就用输入值
}
// 1. 读取输入框
// 分辨角度 例10
// 分辨角度 例10
bool isLeftOnly = btnLeft.Content.ToString() == "左眼开" && btnRight.Content.ToString() == "右眼关";
bool isRightOnly = btnRight.Content.ToString() == "右眼开" && btnLeft.Content.ToString() == "左眼关";
bool isBinocular = btnLeft.Content.ToString() == "左眼开" && btnRight.Content.ToString() == "右眼开";
if (isLeftOnly)
{ _leftTotalArea = 0;
}
{
_leftTotalArea = 0;
}
else if (isRightOnly)
{
_rightTotalArea = 0;
}
else if (isBinocular)
{
_binocularTotalArea = 0;
}
double maxBottomViewAngle = 0; ;//记录所有姿态里的最大下方视野
// 2. 从0转到180每 stepAngle 执行一次
for (double current = stepAngle; current <= 180; current += stepAngle)
{
@@ -261,18 +269,18 @@ namespace 头罩视野.Views
if (isLeftOnly)
{
_leftTotalArea += singleArea;
_leftTotalArea += singleArea;
}
else if (isRightOnly)
{
_rightTotalArea += singleArea;
_rightTotalArea += singleArea;
}
else if (isBinocular)
{
_binocularTotalArea += singleArea;
_binocularTotalArea += singleArea;
}
// 单次计算下方视野角度
@@ -283,26 +291,22 @@ namespace 头罩视野.Views
{
maxBottomViewAngle = bottomViewAngle;
}
// 如果你要取最小值,用下面这段
// if (bottomViewAngle < minBottomViewAngle && bottomViewAngle > 0)
// {
// minBottomViewAngle = bottomViewAngle;
// }
}
isFinished = _modbusMaster.ReadCoils(1, 102, 1)[0];
if (isFinished)
{
Button_Click_Stop(null, null);
UpdateVisionResults( maxBottomViewAngle);
}
}
//页面渲染值
public void UpdateVisionResults( double BotViAn)
public void UpdateVisionResults(double BotViAn)
{
zmsyarea.Text = _leftTotalArea.ToString("0.00"); // 左目
ymsyarea.Text = _rightTotalArea.ToString("0.00"); // 右目
smsyarea.Text = _binocularTotalArea.ToString("0.00"); // 双目
zmsyarea.Text = _leftTotalArea.ToString("0.00"); // 左目
ymsyarea.Text = _rightTotalArea.ToString("0.00"); // 右目
smsyarea.Text = _binocularTotalArea.ToString("0.00"); // 双目
// 3. 计算空白区视野面积(双目时才有效)
if (double.TryParse(smsyarea.Text, out double binocularTotalArea))
@@ -360,7 +364,7 @@ namespace 头罩视野.Views
private async void Timer_Tick(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("定时器触发了!" + DateTime.Now);
//System.Diagnostics.Debug.WriteLine("定时器触发了!" + DateTime.Now);
// 调用你原来的读取方
//await ReadAddr262DataAsync();
@@ -470,9 +474,19 @@ namespace 头罩视野.Views
//ReadAndUpdateFloatAsync(430 ,2, sybhl, "F2", " "),
//前1从站地址后1是长度
};
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);
}
@@ -529,7 +543,7 @@ namespace 头罩视野.Views
//float value4 = c.UshortToFloat(registers[7], registers[6]);
//float value5 = c.UshortToFloat(registers[9], registers[8]);
//float value6 = c.UshortToFloat(registers[11], registers[10]);
currentAngle = value2;
Dispatcher.Invoke(() =>
@@ -612,7 +626,7 @@ namespace 头罩视野.Views
}
}