|
|
@@ -25,7 +25,7 @@ namespace OTSMeasureApp._1_OTSMeasure.Measure._3_MeasureFlow
|
|
|
|
|
|
protected CMeasure m_pMsrThread;
|
|
|
|
|
|
- double curbrightness = 0, curcontrast = 0;
|
|
|
+ private bool brightnessContrastAdjustRuning = false;
|
|
|
|
|
|
protected ISemController m_SemHardwareMgr;
|
|
|
protected IScanController m_ScanHardwareMgr;
|
|
|
@@ -180,6 +180,10 @@ namespace OTSMeasureApp._1_OTSMeasure.Measure._3_MeasureFlow
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
+ public void StopBrightnessContrastAdjust()
|
|
|
+ {
|
|
|
+ brightnessContrastAdjustRuning = false;
|
|
|
+ }
|
|
|
public void DoBrightnessContrastAdjust()
|
|
|
{
|
|
|
using (AutoResetSEMControl autoReset = new AutoResetSEMControl(this))
|
|
|
@@ -253,31 +257,35 @@ namespace OTSMeasureApp._1_OTSMeasure.Measure._3_MeasureFlow
|
|
|
var desirebright = m_BrightnessContrastRegulateParam.brightphaseGrayvalue;
|
|
|
|
|
|
SortedDictionary<double, SEMStateObject> BCstatedic =new SortedDictionary<double, SEMStateObject>();
|
|
|
-
|
|
|
- while (Math.Abs( dark-desiredark)>3 || Math.Abs(bright-desirebright)>3)
|
|
|
+ brightnessContrastAdjustRuning = true;
|
|
|
+ bool finishcondition = Math.Abs(dark - desiredark) < 1 && Math.Abs(bright - desirebright) < 1;
|
|
|
+ while (!finishcondition)
|
|
|
{
|
|
|
|
|
|
-
|
|
|
- double curbrightness = 0, curcontrast = 0;
|
|
|
-
|
|
|
-
|
|
|
+ //regulate
|
|
|
+ double curbrightness = 0, curcontrast = 0;
|
|
|
+ m_SemHardwareMgr.GetSemBrightness(ref curbrightness);
|
|
|
+ m_SemHardwareMgr.GetSemContrast(ref curcontrast);
|
|
|
+ RegulateBrightnessAndContrast(bright, desirebright, dark, desiredark,ref curbrightness,ref curcontrast);
|
|
|
+ Thread.Sleep(200);
|
|
|
+
|
|
|
+ //record the state
|
|
|
|
|
|
var error1 = desirebright - bright;
|
|
|
var error2 = desiredark - dark;
|
|
|
var varerror = Math.Pow(error1, 2) + Math.Pow(error2, 2);
|
|
|
SEMStateObject BcsemState = new SEMStateObject();
|
|
|
- m_SemHardwareMgr.GetSemBrightness(ref curbrightness);
|
|
|
- m_SemHardwareMgr.GetSemContrast(ref curcontrast);
|
|
|
+
|
|
|
BcsemState.brightness = curbrightness;
|
|
|
BcsemState.contrast = curcontrast;
|
|
|
if(!BCstatedic.ContainsKey(varerror))
|
|
|
{
|
|
|
BCstatedic.Add(varerror, BcsemState);
|
|
|
- }
|
|
|
- if((DateTime.Now-starttime).TotalSeconds>30)
|
|
|
+ }
|
|
|
+ //time out check
|
|
|
+ if ((DateTime.Now-starttime).TotalSeconds>100)
|
|
|
{
|
|
|
log.Warn("Auto BC time out, stop the auto BC!");
|
|
|
-
|
|
|
if (BCstatedic.Count > 0)
|
|
|
{
|
|
|
var minerror = BCstatedic.Keys.Min();
|
|
|
@@ -286,15 +294,21 @@ namespace OTSMeasureApp._1_OTSMeasure.Measure._3_MeasureFlow
|
|
|
m_SemHardwareMgr.SetSemContrast(minstate.contrast);
|
|
|
log.Warn("Auto BC set brightness and contrast to:" + minstate.brightness + " " + minstate.contrast);
|
|
|
}
|
|
|
- return;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ // external stop check
|
|
|
+ if (brightnessContrastAdjustRuning==false)
|
|
|
+ {
|
|
|
+ log.Warn("stop the auto BC!");
|
|
|
+
|
|
|
+ break;
|
|
|
}
|
|
|
- RegulateBrightnessAndContrast(bright, desirebright, dark, desiredark,curbrightness,curcontrast);
|
|
|
|
|
|
- log.Info("two gray:" + bright.ToString() +" "+ dark.ToString());
|
|
|
- Thread.Sleep(500);
|
|
|
|
|
|
- // take BSE image for the fields
|
|
|
- pBSEIamge = m_ScanHardwareMgr.AcquireBSEImage();
|
|
|
+
|
|
|
+
|
|
|
+ // check bse image
|
|
|
+ pBSEIamge = m_ScanHardwareMgr.AcquireBSEImage();
|
|
|
|
|
|
if (pBSEIamge == null)
|
|
|
{
|
|
|
@@ -302,8 +316,10 @@ namespace OTSMeasureApp._1_OTSMeasure.Measure._3_MeasureFlow
|
|
|
return;
|
|
|
}
|
|
|
ProcessBSEImageToGetTheTwoGrayValue(pBSEIamge, ref bright, ref dark);
|
|
|
-
|
|
|
- }
|
|
|
+ log.Info("two gray:" + bright.ToString() + " " + dark.ToString());
|
|
|
+ finishcondition = Math.Abs(dark - desiredark) < 1 && Math.Abs(bright - desirebright) < 1;
|
|
|
+ }
|
|
|
+
|
|
|
m_SemHardwareMgr.GetSemContrast(ref m_BrightnessContrastRegulateParam.initialContrast);
|
|
|
m_SemHardwareMgr.GetSemBrightness(ref m_BrightnessContrastRegulateParam.initialBrightness);
|
|
|
log.Warn("Auto BC done!");
|
|
|
@@ -337,23 +353,24 @@ namespace OTSMeasureApp._1_OTSMeasure.Measure._3_MeasureFlow
|
|
|
m_SemHardwareMgr.SetSemContrast(contrast);
|
|
|
m_SemHardwareMgr.SetSemBrightness(bright);
|
|
|
}
|
|
|
- void RegulateBrightnessAndContrast(double bri, double desirebri, double dark, double desiredark,double curbrightness,double curcontrast)
|
|
|
+ void RegulateBrightnessAndContrast(double bri, double desirebri, double dark, double desiredark,ref double curbrightness,ref double curcontrast)
|
|
|
{
|
|
|
|
|
|
|
|
|
- var adjustScope =6;//the scope that sem brightness and contrast can be adjusted
|
|
|
+ var adjustScope =3;//the scope that sem brightness and contrast can be adjusted
|
|
|
|
|
|
var error1 = desirebri - bri;
|
|
|
var error2 = desiredark - dark;
|
|
|
|
|
|
var error = error1 + error2;
|
|
|
double brightness = curbrightness + (error/255)* adjustScope;
|
|
|
+ double contrast=0;
|
|
|
if (bri - dark > 10)
|
|
|
{
|
|
|
double expectcontrast = (desirebri - desiredark) / desirebri;
|
|
|
double currentcontrast = (bri - dark) / bri;
|
|
|
double gain = (expectcontrast - currentcontrast) / expectcontrast * adjustScope;
|
|
|
- double contrast = curcontrast + gain;
|
|
|
+ contrast = curcontrast + gain;
|
|
|
m_SemHardwareMgr.SetSemContrast(contrast);
|
|
|
|
|
|
}
|
|
|
@@ -362,18 +379,20 @@ namespace OTSMeasureApp._1_OTSMeasure.Measure._3_MeasureFlow
|
|
|
var everagegray=(bri+dark) / 2;
|
|
|
if (everagegray >= 125)
|
|
|
{
|
|
|
- double contrast = curcontrast - 0.5;
|
|
|
+ contrast = curcontrast - 0.5;
|
|
|
m_SemHardwareMgr.SetSemContrast(contrast);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- double contrast = curcontrast + 0.5;
|
|
|
+ contrast = curcontrast + 0.5;
|
|
|
m_SemHardwareMgr.SetSemContrast(contrast);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
m_SemHardwareMgr.SetSemBrightness(brightness);
|
|
|
+ curcontrast = contrast;
|
|
|
+ curbrightness = brightness;
|
|
|
}
|
|
|
|
|
|
bool InitAcquireBSEParam()
|