Selaa lähdekoodia

v2.1.2 加入自动曝光

MainC
CPL 1 vuosi sitten
vanhempi
commit
924cf71a67
5 muutettua tiedostoa jossa 255 lisäystä ja 19 poistoa
  1. +1
    -1
      halftoneproject-master/BanBoShi/BanBoShi.csproj
  2. +238
    -12
      halftoneproject-master/BanBoShi/SysCtrl/SysMgr.cs
  3. +5
    -2
      halftoneproject-master/BanBoShi/SysUI/ProcessStep/Prop/MarkProp.cs
  4. +6
    -2
      halftoneproject-master/BanBoShi/SysUI/ProcessStep/Prop/PointTestProp.cs
  5. +5
    -2
      halftoneproject-master/BanBoShi/SysUI/ProcessStep/Prop/SizeDefectProp.cs

+ 1
- 1
halftoneproject-master/BanBoShi/BanBoShi.csproj Näytä tiedosto

@@ -208,7 +208,7 @@
<Reference Include="System.Xml" />
<Reference Include="Yolo5, Version=1.0.0.0, Culture=neutral, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Dlls\Yolo5.dll</HintPath>
<HintPath>Dlls\Yolo5.dll</HintPath>
</Reference>
<Reference Include="ZstdSharp, Version=0.7.1.0, Culture=neutral, PublicKeyToken=8d151af33a4ad5cf, processorArchitecture=MSIL">
<HintPath>..\packages\ZstdSharp.Port.0.7.1\lib\net461\ZstdSharp.dll</HintPath>


+ 238
- 12
halftoneproject-master/BanBoShi/SysCtrl/SysMgr.cs Näytä tiedosto

@@ -98,6 +98,10 @@ namespace MaiMuAOI.SysCtrl
/// </summary>
private int CurrPoinntCount = 0;
/// <summary>
/// 尺寸检测是否自动曝光完成
/// </summary>
private bool HaveAutoExp = false;
/// <summary>
/// 总计时
/// </summary>
private Stopwatch stopWatch;
@@ -2069,6 +2073,7 @@ namespace MaiMuAOI.SysCtrl
_isAuto = false;
CurrProcessIndex = -1;
CurrPoinntCount = 0;
HaveAutoExp = false;
CurrStepResult = 0;
IsGetStartSig = false;
@@ -2276,7 +2281,7 @@ namespace MaiMuAOI.SysCtrl
{
return;
}
string[] array = Directory.GetFiles(dirPath, "(*.bmp|*.jpg|*.log|*.json)");
string[] array = Directory.GetFiles(dirPath, "*.bmp;*.jpg;*.log;*.json");
foreach (string text in array)
{
try
@@ -2296,7 +2301,7 @@ namespace MaiMuAOI.SysCtrl
{
return;
}
array = Directory.GetFiles(dirPath, "(*.bmp|*.jpg|*.log|*.json)");
array = Directory.GetFiles(dirPath, "(*.bmp;*.jpg;*.log;*.json)");
foreach (string text in array)
{
try
@@ -2615,6 +2620,7 @@ namespace MaiMuAOI.SysCtrl
IsGetStartSig = false;
CurrProcessIndex = 0;
CurrPoinntCount = 0;
HaveAutoExp = false;
CurrStepResult = 0;
LedRun();
stopWatch = new Stopwatch();
@@ -5746,13 +5752,11 @@ namespace MaiMuAOI.SysCtrl
Log($"{stepIndex + 1}-{processName}", $"轴组运行完成");
Thread.Sleep(markParam.WaitTime);
//自动聚焦?
if (markParam.MarkType == MarkCam.尺寸检测Mark)
if ((this.CurrPoinntCount == 0)&&(IsAutoFocus)&& (markParam.MarkType == MarkCam.尺寸检测Mark))
{
//尺寸在自动聚焦之前需要现使用曝光值
CamDevFront.SetExposure(markParam.ExposureTime);
CamDevFront.SetGain(markParam.Gain);
}
if ((this.CurrPoinntCount == 0)&&(IsAutoFocus)&& (markParam.MarkType == MarkCam.尺寸检测Mark))
{
Log($"{stepIndex + 1}-{processName}", $"自动聚焦...");
if(!AutoFocus(FocusStep, DirStep, DirWaitTime, FocusTimeOut))
{
@@ -5766,6 +5770,22 @@ namespace MaiMuAOI.SysCtrl
Log($"{stepIndex + 1}-{processName}", $"相机开始采集照片...");
if (markParam.MarkType == MarkCam.尺寸检测Mark)
{
//完成聚焦之后使用自动曝光
if(markParam.AutoExposure)
{
if (AutoExposureF())
Log($"{stepIndex + 1}-{processName}", $"自动曝光完成");
else
{
Log($"{stepIndex + 1}-{processName}", $"自动曝光失败!", WarningEnum.High);
return stepIndex;
}
}
else
{
CamDevFront.SetExposure(markParam.ExposureTime);
CamDevFront.SetGain(markParam.Gain);
}
//CamDevFront.SetExposure(markParam.ExposureTime);
//CamDevFront.SetGain(markParam.Gain);
Log($"{stepIndex + 1}-{processName}", $"相机参数设置完成。");
@@ -5805,8 +5825,23 @@ namespace MaiMuAOI.SysCtrl
}
else
{
CamDevBack.SetExposure(markParam.ExposureTime);
CamDevBack.SetGain(markParam.Gain);
//完成聚焦之后使用自动曝光
if (markParam.AutoExposure)
{
if (AutoExposureB())
Log($"{stepIndex + 1}-{processName}", $"自动曝光完成");
else
{
Log($"{stepIndex + 1}-{processName}", $"自动曝光失败!", WarningEnum.High);
return stepIndex;
}
}
else
{
CamDevBack.SetExposure(markParam.ExposureTime);
CamDevBack.SetGain(markParam.Gain);
}
for (int snapi = 0; snapi < snapCnt; snapi++)
{
DateTime dt = DateTime.Now;
@@ -6154,11 +6189,16 @@ namespace MaiMuAOI.SysCtrl
Log($"{stepIndex + 1}-{processName}", $"轴组运行完成");
Thread.Sleep(testParam.WaitTime);
camDevFront.SetExposure(testParam.ExposureTime);
camDevFront.SetGain(testParam.Gain);
//自动聚焦?
if ((this.CurrPoinntCount == 0) && (IsAutoFocus)&& (i == 0))//第一次拍照才聚焦
{
//判断是否已经自动曝光
if (!HaveAutoExp)
{
camDevFront.SetExposure(testParam.ExposureTime);
camDevFront.SetGain(testParam.Gain);
}
Log($"{stepIndex + 1}-{processName}", $"自动聚焦...");
if (!AutoFocus(FocusStep, DirStep, DirWaitTime, FocusTimeOut))
{
@@ -6169,6 +6209,12 @@ namespace MaiMuAOI.SysCtrl
}
else if (testParam.AutoFocus)//每次都聚焦
{
//判断是否已经自动曝光
if (!HaveAutoExp)
{
camDevFront.SetExposure(testParam.ExposureTime);
camDevFront.SetGain(testParam.Gain);
}
Log($"{stepIndex + 1}-{processName}", $"拍照前自动聚焦...");
if (!AutoFocus(testParam.FocusStep, testParam.DirStep, testParam.WaitDoneTime, testParam.TimeOut))
{
@@ -6177,6 +6223,26 @@ namespace MaiMuAOI.SysCtrl
}
Log($"{stepIndex + 1}-{processName}", $"拍照前自动聚焦完成");
}
//完成聚焦之后使用自动曝光
if (testParam.AutoExposure && !HaveAutoExp)
{
if (AutoExposureF())
{
HaveAutoExp = true;
Log($"{stepIndex + 1}-{processName}", $"自动曝光完成");
}
else
{
Log($"{stepIndex + 1}-{processName}", $"自动曝光失败!", WarningEnum.High);
return stepIndex;
}
}
else if(!testParam.AutoExposure)
{
camDevFront.SetExposure(testParam.ExposureTime);
camDevFront.SetGain(testParam.Gain);
}
//拍照
Log($"{stepIndex + 1}-{processName}", $"相机开始采集照片...");
@@ -6452,8 +6518,23 @@ namespace MaiMuAOI.SysCtrl
//拍照
Log($"{stepIndex + 1}-{processName}", $"相机开始采集照片...");
CamDevBack.SetExposure(defectParam.ExposureTime);
CamDevBack.SetGain(defectParam.Gain);
//完成聚焦之后使用自动曝光
if (defectParam.AutoExposure)
{
if (AutoExposureB())
Log($"{stepIndex + 1}-{processName}", $"自动曝光完成");
else
{
Log($"{stepIndex + 1}-{processName}", $"自动曝光失败!", WarningEnum.High);
return stepIndex;
}
}
else
{
CamDevBack.SetExposure(defectParam.ExposureTime);
CamDevBack.SetGain(defectParam.Gain);
}
double px = GetAxisPosValueMM((int)AxisName.Axis1);
double py = GetAxisPosValueMM((int)AxisName.Axis2);
@@ -10908,6 +10989,151 @@ namespace MaiMuAOI.SysCtrl
}
}
#endregion
#region 自动曝光
/// <summary>
/// 自动曝光功能前相机
/// </summary>
/// <param name="exp"></param>
/// <returns></returns>
private bool AutoExposureF()
{
bool ret = true;
Yolo_Class yolo = new Yolo_Class();
int exp = 0;
double mean = 0;
int cnt = 0;
DateTime alldt = DateTime.Now;
bool breakW = false;
//获取当前曝光
double exp2;
camDevFront.GetExposure(out exp2);
exp = (int)exp2;
while (true)
{
for (int i = 0; i < snapCnt; i++)
{
camDevFront.ClearImageQueue();
Acquisition acq = camDevFront.Snap(1, 5000);
if (acq.GrabStatus == "GrabPass")
{
//显示
OnAutoRuning(new RunEventArgs(0, acq.Image));
yolo.Exposure(acq.Image.CopyObj(1, -1), ref exp, ref mean);
cnt++;
Log("自动曝光", $"步进次数:{cnt},曝光:{exp}, Mean:{mean}");
if (mean == 9999)
{
breakW = true;
break;
}
else
{
if (!camDevFront.SetExposure(exp))
{
Log("自动曝光", $"曝光设置失败!");
return false;
}
}
}
else
{
Log($"自动曝光{i}", $"拍照失败{acq.GrabStatus}!");
if (i < snapCnt - 1)
{
Thread.Sleep(100);
continue;
}
else
return false;
}
}
if (breakW)
break;
if ((DateTime.Now - alldt).TotalMilliseconds > 10000)
{
Log("自动曝光", $"自动曝光超时-10ms!");
return false;
}
}
return ret;
}
/// <summary>
/// 自动曝光功能后相机
/// </summary>
/// <param name="exp"></param>
/// <returns></returns>
private bool AutoExposureB()
{
bool ret = true;
Yolo_Class yolo = new Yolo_Class();
int exp = 0;
double mean = 0;
int cnt = 0;
DateTime alldt = DateTime.Now;
bool breakW = false;
//获取当前曝光
double exp2;
camDevBack.GetExposure(out exp2);
exp = (int)exp2;
while (true)
{
for (int i = 0; i < snapCnt; i++)
{
camDevBack.ClearImageQueue();
Acquisition acq = camDevBack.Snap(1, 5000);
if (acq.GrabStatus == "GrabPass")
{
//显示
OnAutoRuning(new RunEventArgs(1, acq.Image));
yolo.Exposure(acq.Image.CopyObj(1, -1), ref exp, ref mean);
cnt++;
Log("自动曝光", $"步进次数:{cnt},曝光:{exp}, Mean:{mean}");
if (mean == 9999)
{
breakW = true;
break;
}
else
{
if (!camDevBack.SetExposure(exp))
{
Log("自动曝光", $"曝光设置失败!");
return false;
}
}
}
else
{
Log($"自动曝光{i}", $"拍照失败{acq.GrabStatus}!");
if (i < snapCnt - 1)
{
Thread.Sleep(100);
continue;
}
else
return false;
}
}
if (breakW)
break;
if ((DateTime.Now - alldt).TotalMilliseconds > 10000)
{
Log("自动曝光", $"自动曝光超时-10s!");
return false;
}
}
return ret;
}
#endregion
}
#region 系统事件


+ 5
- 2
halftoneproject-master/BanBoShi/SysUI/ProcessStep/Prop/MarkProp.cs Näytä tiedosto

@@ -27,9 +27,11 @@ namespace MaiMuAOI.SysUI.ProcessStep.Prop
[PropertyOrder(14), Browsable(true), Category("2 Mark"), DisplayName("2.4 手动Mark位置列表"), Description("当自动寻找Mark False时,需要手动输入Mark点位")]
public List<PointF> Points { get; set; }
[PropertyOrder(21), Browsable(true), Category("3 相机"), DisplayName("3.1 曝光"), Description("曝光时长(us)")]
[PropertyOrder(21), Browsable(true), Category("3 相机"), DisplayName("3.1 自动曝光"), Description("开启自动曝光")]
public bool AutoExposure { get; set; }
[PropertyOrder(21), Browsable(true), Category("3 相机"), DisplayName("3.2 曝光"), Description("曝光时长(us)")]
public float ExposureTime { get; set; }
[PropertyOrder(22), Browsable(true), Category("3 相机"), DisplayName("3.2 增益"), Description("增益")]
[PropertyOrder(22), Browsable(true), Category("3 相机"), DisplayName("3.3 增益"), Description("增益")]
public float Gain { get; set; }
[PropertyOrder(31), Browsable(true), Category("4 动作"), DisplayName("4.1 起始速度(mm/s)"), Description("起始速度")]
@@ -54,6 +56,7 @@ namespace MaiMuAOI.SysUI.ProcessStep.Prop
AutoMark = true;
Points = new List<PointF>();
AutoExposure = false;
ExposureTime = 30000;
Gain = 0;


+ 6
- 2
halftoneproject-master/BanBoShi/SysUI/ProcessStep/Prop/PointTestProp.cs Näytä tiedosto

@@ -35,9 +35,12 @@ namespace MaiMuAOI.SysUI.ProcessStep.Prop
[PropertyOrder(17), Browsable(true), Category("2 检测"), DisplayName("2.6 数据判定方式"), Description("对采集数据进行判定处理的方式")]
public DataJudgment JudgmentData { get; set; }
[PropertyOrder(21), Browsable(true), Category("3 相机"), DisplayName("3.1 曝光"), Description("曝光时长(us)")]
[PropertyOrder(21), Browsable(true), Category("3 相机"), DisplayName("3.1 自动曝光"), Description("开启自动曝光")]
public bool AutoExposure { get; set; }
[PropertyOrder(21), Browsable(true), Category("3 相机"), DisplayName("3.2 曝光"), Description("曝光时长(us)")]
public float ExposureTime { get; set; }
[PropertyOrder(22), Browsable(true), Category("3 相机"), DisplayName("3.2 增益"), Description("增益")]
[PropertyOrder(22), Browsable(true), Category("3 相机"), DisplayName("3.3 增益"), Description("增益")]
public float Gain { get; set; }
[PropertyOrder(31), Browsable(true), Category("4 动作"), DisplayName("4.1 起始速度(mm/s)"), Description("起始速度")]
@@ -115,6 +118,7 @@ namespace MaiMuAOI.SysUI.ProcessStep.Prop
Points = new List<PointF>();
JudgmentData = DataJudgment.均值;
AutoExposure = false;
ExposureTime = 30000;
Gain = 0;


+ 5
- 2
halftoneproject-master/BanBoShi/SysUI/ProcessStep/Prop/SizeDefectProp.cs Näytä tiedosto

@@ -31,9 +31,11 @@ namespace MaiMuAOI.SysUI.ProcessStep.Prop
[PropertyOrder(17), Browsable(true), Category("02 缺陷检测"), DisplayName("2.7 异步运行"), Description("非阻塞后续流程运行(True-是;False-否)")]
public bool AsynDefectRun { get; set; } = true;
[PropertyOrder(21), Browsable(true), Category("03 相机"), DisplayName("3.1 曝光"), Description("曝光时长(us)")]
[PropertyOrder(21), Browsable(true), Category("03 相机"), DisplayName("3.1 自动曝光"), Description("开启自动曝光")]
public bool AutoExposure { get; set; }
[PropertyOrder(21), Browsable(true), Category("03 相机"), DisplayName("3.2 曝光"), Description("曝光时长(us)")]
public float ExposureTime { get; set; }
[PropertyOrder(22), Browsable(true), Category("03 相机"), DisplayName("3.2 增益"), Description("增益")]
[PropertyOrder(22), Browsable(true), Category("03 相机"), DisplayName("3.3 增益"), Description("增益")]
public float Gain { get; set; }
[PropertyOrder(31), Browsable(true), Category("04 动作"), DisplayName("4.1 起始速度(mm/s)"), Description("起始速度")]
@@ -117,6 +119,7 @@ namespace MaiMuAOI.SysUI.ProcessStep.Prop
Thresholds = ConfMgr.Instance.SysConfigParams.Defect_Thresholds;
AsynDefectRun = true;
AutoExposure = false;
ExposureTime = 30000;
Gain = 0;


Ladataan…
Peruuta
Tallenna