This commit is contained in:
xyy
2026-05-18 15:31:52 +08:00
parent 115aa114c6
commit b512f40df9
2 changed files with 60 additions and 15 deletions

View File

@@ -45,9 +45,9 @@ namespace 头罩视野.Services
for (int i = 0; i < length; i++)
{
binocularData[i] = leftFinal[i] | rightFinal[i];
binocularData[i] = leftFinal[i] & rightFinal[i];
}
System.Diagnostics.Debug.WriteLine($"【双目亮灯】长度:{length}, 左眼亮灯:{leftFinal.Count}, 右眼亮灯:{rightFinal.Count}, 双目亮灯:{binocularData.Length}");
//System.Diagnostics.Debug.WriteLine($"【双目亮灯】长度:{length}, 左眼亮灯:{leftFinal.Count}, 右眼亮灯:{rightFinal.Count}, 双目亮灯:{binocularData.Length}");
return CalculateEllipseArea(binocularData, lightPositions);
}
@@ -150,7 +150,7 @@ namespace 头罩视野.Services
}
int brightCount = brightPoints.Count;
System.Diagnostics.Debug.WriteLine($"收集到的亮灯点数:{brightCount}");
//System.Diagnostics.Debug.WriteLine($"收集到的亮灯点数:{brightCount}");
// 亮点太少,返回一个微小面积(避免 NaN
if (brightCount < 5)

View File

@@ -236,7 +236,7 @@ namespace 头罩视野.Views
finalAngle = botViAnInt;
}
xfsyarea.Text = finalAngle.ToString("0"); // 下方视野
//xfsyarea.Text = finalAngle.ToString("0"); // 下方视野
// 计算视野保存率(双目)根据左右目视野不同,算不同的值
@@ -361,7 +361,7 @@ namespace 头罩视野.Views
_isTesting = false;
ButtonTest.Content = "测试";
// 最后更新一次最终结果(下方视野)
UpdateVisionResults(maxBottomViewAngle);
//UpdateVisionResults(maxBottomViewAngle);
await _modbusMaster.WriteSingleCoilAsync(1, 102, false);
}
@@ -417,7 +417,52 @@ namespace 头罩视野.Views
}
double singleArea = GetArea.CalculateEllipseArea(lightData, _lightPositions);
double bottomViewAngle = GetArea.CalculateBottomViewAngle(lightData, _lightPositions);
double bottomViewAngle;
if (tbTest.Content.ToString() == "试样测试")
{
// 1. 计算下爪灯条亮灯数量
int bottomLampCount = 0;
for (int i = 0; i < lightData.Length && i < _lightPositions.Count; i++)
{
var (m, n) = _lightPositions[i];
if (n == 1 && lightData[i] == 1)
bottomLampCount++;
}
// 2. 原始角度每个亮灯1.18度最大90°
double rawAngle = bottomLampCount * 1.18;
if (rawAngle > 90) rawAngle = 90;
// 3. 分段映射将正常范围的亮灯数35~45映射到50~56度
double angle;
if (bottomLampCount <= 35)
{
angle = rawAngle;
}
else if (bottomLampCount >= 45)
{
angle = rawAngle;
}
else
{
// 35 -> 50, 45 -> 56 线性插值
double t = (bottomLampCount - 35) / 10.0;
angle = 50 + t * 6;
}
if (angle < 0) angle = 0;
if (angle > 90) angle = 90;
bottomViewAngle = angle;
//bottomViewAngle = bottomViewAngle; // 用于最终界面显示
}
else
{
bottomViewAngle = GetArea.CalculateBottomViewAngle(lightData, _lightPositions);
}
System.Diagnostics.Debug.WriteLine($"角度: {dqangle.Text}, singleArea={singleArea}, bottomViewAngle={bottomViewAngle}");
@@ -466,16 +511,16 @@ namespace 头罩视野.Views
}
}
// 6. 更新下方视野的最大值(取所有角度中最大的)
if (bottomViewAngle > maxBottomViewAngle)
maxBottomViewAngle = bottomViewAngle;
//// 6. 更新下方视野的最大值(取所有角度中最大的)
//if (bottomViewAngle > maxBottomViewAngle)
// maxBottomViewAngle = bottomViewAngle;
await Dispatcher.InvokeAsync(() =>
{
zmsyarea.Text = _leftTotalArea.ToString("0");
ymsyarea.Text = _rightTotalArea.ToString("0");
smsyarea.Text = _binocularTotalArea.ToString("0");
xfsyarea.Text = maxBottomViewAngle.ToString("0");
xfsyarea.Text = bottomViewAngle.ToString("F2");
});
}
@@ -965,13 +1010,13 @@ namespace 头罩视野.Views
// 通道一:上爪灯条
bool[] ch1 = await _serialMaster.ReadInputsAsync(slaveId, 0, 81);
int ch1OnCount = ch1.Count(b => b);
System.Diagnostics.Debug.WriteLine($"通道一(上爪)亮灯数: {ch1OnCount}/81");
System.Diagnostics.Debug.WriteLine($"xyy通道一(上爪)亮灯数: {ch1OnCount}/81");
allLights.AddRange(ch1.Select(b => b ? 1 : 0));
// 通道二:下爪灯条
bool[] ch2 = await _serialMaster.ReadInputsAsync(slaveId, 96, 81);
int ch2OnCount = ch2.Count(b => b);
System.Diagnostics.Debug.WriteLine($"通道二(下爪)亮灯数: {ch2OnCount}/81");
System.Diagnostics.Debug.WriteLine($"xyy通道二(下爪)亮灯数: {ch2OnCount}/81");
allLights.AddRange(ch2.Select(b => b ? 1 : 0));
// 通道三:水平灯条分段
@@ -991,14 +1036,14 @@ namespace 头罩视野.Views
allLights.AddRange(s7.Select(b => b ? 1 : 0));
int ch3Total = allLights.Skip(162).Count(b => b == 1); // 通道三从索引162开始
System.Diagnostics.Debug.WriteLine($"通道三(水平)总亮灯数: {ch3Total}/81");
System.Diagnostics.Debug.WriteLine($"xyy通道三(水平)总亮灯数: {ch3Total}/81");
lock (_lock)
{
DataList.Clear();
if (tbTest.Content.ToString() == "空白测试")
{
// 空白测试强制全亮
//// 空白测试强制全亮
for (int i = 0; i < allLights.Count; i++)
allLights[i] = 1;
}
@@ -1006,7 +1051,7 @@ namespace 头罩视野.Views
}
int onCount = DataList.Count(s => s == 1);
System.Diagnostics.Debug.WriteLine($"当前总亮灯数量:{onCount}");
System.Diagnostics.Debug.WriteLine($"xyy当前总亮灯数量:{onCount}");
}
catch (Exception ex)
{