287 lines
9.7 KiB
C#
287 lines
9.7 KiB
C#
using AuroraDeviceCommon.Utils;
|
|
using PropertyTools.DataAnnotations;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AuroraLaser
|
|
{
|
|
public class LaserPowerCalibrationParam
|
|
{
|
|
|
|
DataTable m_centerCalibrationTable;
|
|
DataTable m_ringCalibrationTable;
|
|
string m_centerBeamPath, m_ringBeamPath;
|
|
|
|
public enum beamMode { Center = 1, Ring = 2, Error = 3 }
|
|
|
|
public DataTable CenterCalibrationTable {
|
|
get { return m_centerCalibrationTable; }
|
|
set { m_centerCalibrationTable = value; }
|
|
}
|
|
|
|
public DataTable RingCalibrationTable {
|
|
get { return m_ringCalibrationTable; }
|
|
set { m_ringCalibrationTable = value; }
|
|
}
|
|
|
|
public string CenterBeamPath {
|
|
get { return m_centerBeamPath; }
|
|
set { m_centerBeamPath = value; }
|
|
}
|
|
|
|
public string RingBeamPath {
|
|
get { return m_ringBeamPath; }
|
|
set { m_ringBeamPath = value; }
|
|
}
|
|
|
|
public LaserPowerCalibrationParam()
|
|
{
|
|
// 초기 설정할 때, CSV 파일을 토대로 Center, Ring Beam을
|
|
// 확인하는 부분이 필수적인 듯.
|
|
}
|
|
|
|
|
|
public void Initialize(string centerBeamPath, string ringBeamPath)
|
|
{
|
|
LoadTable(centerBeamPath, ringBeamPath);
|
|
}
|
|
|
|
public void InitializeTable(double maxPower, double interval, out DataTable dataTable, uint beam = 0)
|
|
{
|
|
DataTable m_calibrationTable = new DataTable();
|
|
|
|
if (beam == (int)beamMode.Error) {
|
|
dataTable = m_calibrationTable;
|
|
// MessageBox
|
|
return;
|
|
}
|
|
|
|
m_calibrationTable.Columns.Add(new DataColumn("Index", typeof(double)));
|
|
//m_calibrationTable.Columns.Add(new DataColumn("Voltage", typeof(double)));
|
|
m_calibrationTable.Columns.Add(new DataColumn("DesiredPower", typeof(double)));
|
|
m_calibrationTable.Columns.Add(new DataColumn("CalibratedPower", typeof(double)));
|
|
|
|
double index = 0;
|
|
DataRow row;
|
|
int iRowCount;
|
|
object[] rowArray;
|
|
|
|
while (index < 100) {
|
|
row = m_calibrationTable.NewRow();
|
|
iRowCount = m_calibrationTable.Rows.Count;
|
|
rowArray = new object[3];
|
|
|
|
//Index Percentage(0 ~ 100 %)
|
|
rowArray[0] = index;
|
|
//Voltage(0 ~ 10 V)
|
|
//rowArray[1] = index / 10;
|
|
//Desired Power(0 ~ Max Watt)
|
|
rowArray[1] = maxPower * index / 100;
|
|
//초기에는 Calibrated Power = Desired Power
|
|
rowArray[2] = rowArray[1];
|
|
|
|
row.ItemArray = rowArray;
|
|
m_calibrationTable.Rows.Add(row);
|
|
|
|
index = index + interval;
|
|
}
|
|
|
|
//마지막 100% 인 경우를 추가
|
|
row = m_calibrationTable.NewRow();
|
|
iRowCount = m_calibrationTable.Rows.Count;
|
|
rowArray = new object[3];
|
|
//Index Percentage(0 ~ 100 %)
|
|
rowArray[0] = 100;
|
|
//Voltage(0 ~ 10 V)
|
|
//rowArray[1] = 10;
|
|
//Desired Power(0 ~ Max Watt)
|
|
rowArray[1] = maxPower;
|
|
//Calibrated Power(0 ~ Max Watt)
|
|
rowArray[2] = maxPower;
|
|
|
|
row.ItemArray = rowArray;
|
|
m_calibrationTable.Rows.Add(row);
|
|
index = index + interval;
|
|
|
|
dataTable = m_calibrationTable;
|
|
}
|
|
|
|
public void LoadTable(string centerBeamPath, string ringBeamPath)
|
|
{
|
|
if (true == System.IO.Path.GetExtension(centerBeamPath).ToUpper().Contains("CSV")
|
|
&& true == System.IO.Path.GetExtension(ringBeamPath).ToUpper().Contains("CSV")) {
|
|
CenterCalibrationTable = ExcelManagementUnit.ImportDataFromCsv(centerBeamPath);
|
|
RingCalibrationTable = ExcelManagementUnit.ImportDataFromCsv(ringBeamPath);
|
|
m_centerBeamPath = centerBeamPath;
|
|
m_ringBeamPath = ringBeamPath;
|
|
} else {
|
|
// Message 박스 열기.
|
|
}
|
|
}
|
|
|
|
public void SaveTable(DataTable dataTable, uint beam = (uint)beamMode.Center)
|
|
{
|
|
string fileName;
|
|
if (beam == (int)beamMode.Center) {
|
|
fileName = CenterBeamPath;
|
|
CenterCalibrationTable = dataTable;
|
|
ExcelManagementUnit.ExportToCSV(fileName, CenterCalibrationTable);
|
|
}
|
|
if (beam == (int)beamMode.Ring) {
|
|
fileName = RingBeamPath;
|
|
RingCalibrationTable = dataTable;
|
|
ExcelManagementUnit.ExportToCSV(fileName, RingCalibrationTable);
|
|
}
|
|
// if (beam == (int)beamMode.Error) MessageBox
|
|
}
|
|
|
|
public double LinearInterpolation(double a, double b, double fa, double fb, double fc)
|
|
{
|
|
// x : a < c < b, y: f(a) < f(c) < f(b)
|
|
double incline = (fb - fa) / (b - a);
|
|
|
|
double sol = (fc - fa + incline * a) / incline;
|
|
|
|
return sol;
|
|
}
|
|
|
|
public double CalibrateWattToVolt(double power, uint beam = (uint)beamMode.Center)
|
|
{
|
|
//DataTable m_dataTable;
|
|
|
|
double wattToPercent = CalibrateWattToPercent(power, beam);
|
|
|
|
if (0 <= wattToPercent && wattToPercent <= 100) return wattToPercent / 10;
|
|
|
|
return 0;
|
|
}
|
|
|
|
public double CalibrateWattToPercent(double power, uint beam = (uint)beamMode.Center)
|
|
{
|
|
DataTable m_dataTable;
|
|
|
|
if (beam == (int)beamMode.Center) m_dataTable = CenterCalibrationTable;
|
|
else if (beam == (int)beamMode.Ring) m_dataTable = RingCalibrationTable;
|
|
else return 0;
|
|
|
|
int percentIndex = 0, calibratedIndex = 2;
|
|
|
|
double x1 = 0, x2 = 0, y1 = 0, y2 = 0;
|
|
for (int i = 1; i < m_dataTable.Rows.Count; i++) {
|
|
double.TryParse(Convert.ToString(m_dataTable.Rows[i][calibratedIndex]), out y2);
|
|
|
|
if (y1 < power && power <= y2) {
|
|
double.TryParse(Convert.ToString(m_dataTable.Rows[i - 1][percentIndex]), out x1);
|
|
double.TryParse(Convert.ToString(m_dataTable.Rows[i][percentIndex]), out x2);
|
|
|
|
return LinearInterpolation(x1, x2, y1, y2, power);
|
|
} else y1 = y2;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
public double CalibratePercentToWatt(double power, uint beam = (uint)beamMode.Center)
|
|
{
|
|
DataTable m_dataTable;
|
|
|
|
if (beam == (int)beamMode.Center) m_dataTable = CenterCalibrationTable;
|
|
else if (beam == (int)beamMode.Ring) m_dataTable = RingCalibrationTable;
|
|
else return 0;
|
|
|
|
int percentIndex = 0, calibratedIndex = 2;
|
|
|
|
double x1 = 0, x2 = 0, y1 = 0, y2 = 0;
|
|
for (int i = 1; i < m_dataTable.Rows.Count; i++) {
|
|
double.TryParse(Convert.ToString(m_dataTable.Rows[i][percentIndex]), out y2);
|
|
|
|
if (y1 < power && power <= y2) {
|
|
double.TryParse(Convert.ToString(m_dataTable.Rows[i - 1][calibratedIndex]), out x1);
|
|
double.TryParse(Convert.ToString(m_dataTable.Rows[i][calibratedIndex]), out x2);
|
|
|
|
return LinearInterpolation(x1, x2, y1, y2, power);
|
|
} else y1 = y2;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public class PowerProfileParam
|
|
{
|
|
double m_startPowerPercent = 100;
|
|
[Browsable(true)]
|
|
[ReadOnly(false)]
|
|
[DisplayName("1. Start Power(%)")]
|
|
[Description("Start Power(%)")]
|
|
|
|
public double StartPowerPercent {
|
|
get { lock (this) { return m_startPowerPercent; } }
|
|
set { lock (this) { m_startPowerPercent = value; } }
|
|
}
|
|
double m_endPowerPercent = 100;
|
|
[Browsable(true)]
|
|
[ReadOnly(false)]
|
|
[DisplayName("2. End Power(%)")]
|
|
[Description("End Power(%)")]
|
|
|
|
public double EndPowerPercent {
|
|
get { lock (this) { return m_endPowerPercent; } }
|
|
set { lock (this) { m_endPowerPercent = value; } }
|
|
}
|
|
|
|
double m_time = 1;
|
|
[Browsable(true)]
|
|
[ReadOnly(false)]
|
|
[DisplayName("3. Time(msec)")]
|
|
[Description("Time(msec)")]
|
|
public double Time {
|
|
get { lock (this) { return m_time; } }
|
|
set { lock (this) { m_time = value; } }
|
|
}
|
|
|
|
public void Copy(PowerProfileParam acopy)
|
|
{
|
|
m_startPowerPercent = acopy.m_startPowerPercent;
|
|
m_endPowerPercent = acopy.m_endPowerPercent;
|
|
m_time = acopy.m_time;
|
|
}
|
|
|
|
}
|
|
|
|
public class TopRootObject
|
|
{
|
|
public List<PowerProfilesList> PowerProfilesLists { get; set; }
|
|
}
|
|
|
|
public class PowerProfilesList
|
|
{
|
|
List<PowerProfile> m_powerProfiles = new List<PowerProfile>();
|
|
public List<PowerProfile> PowerProfiles {
|
|
get { lock (this) { return m_powerProfiles; } }
|
|
set { lock (this) { m_powerProfiles = value; } }
|
|
}
|
|
}
|
|
|
|
public class PowerProfile
|
|
{
|
|
List<PowerProfileParam> m_powerProfileParams = new List<PowerProfileParam>();
|
|
public List<PowerProfileParam> PowerProfileParams {
|
|
get { lock (this) { return m_powerProfileParams; } }
|
|
set { lock (this) { m_powerProfileParams = value; } }
|
|
}
|
|
|
|
|
|
public void Copy(PowerProfile acopy)
|
|
{
|
|
for (int i = 0; i < acopy.m_powerProfileParams.Count; i++) {
|
|
m_powerProfileParams.Add(new PowerProfileParam());
|
|
m_powerProfileParams[i].Copy(acopy.m_powerProfileParams[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|