static int Main(string[] args) { try { KApiLib.Construct(); GoSdkLib.Construct(); GoSystem system = new GoSystem(); GoSensor sensor; GoDataSet dataSet = new GoDataSet(); KIpAddress ipAddress = KIpAddress.Parse(Constants.SENSOR_IP); sensor = system.FindSensorByIpAddress(ipAddress); sensor.Connect(); system.EnableData(true); GoSetup setup = sensor.Setup; setup.AlignmentType = GoAlignmentType.Stationary; setup.AlignmentStationaryTarget = GoAlignmentTarget.None; sensor.Align(); Console.WriteLine("Waiting for alignment calibration data to be collected..."); dataSet = system.ReceiveData(30000000); for (UInt32 i = 0; i < dataSet.Count; i++) { GoAlignMsg dataItem = (GoAlignMsg)dataSet.Get(i); if (dataItem.MessageType == GoDataMessageType.Alignment) { if (dataItem.Status == KStatus.Ok) { Console.WriteLine("Alignment calibration successful!"); } else { Console.WriteLine("Alignment calibration failed."); } } } system.Stop(); } catch (KException ex) { if (ex.Status == KStatus.ErrorTimeout) { Console.WriteLine("Failed to collect data for calibration within timeout limit..."); } else if (ex.Status != KStatus.Ok) { Console.WriteLine("Error:{0}", ex.Status); } } // wait for Enter key Console.WriteLine("\nPress ENTER to continue"); do { System.Threading.Thread.Sleep(100); } while (Console.Read() != (int)ConsoleKey.Enter); return(1); }
static int Main(string[] args) { try { KApiLib.Construct(); GoSdkLib.Construct(); GoSystem system = new GoSystem(); GoSensor sensor; KIpAddress ipAddress = KIpAddress.Parse(Constants.SENSOR_IP); sensor = system.FindSensorByIpAddress(ipAddress); sensor.Connect(); system.EnableData(true); //retrieve setup handle GoSetup setup = sensor.Setup; //retrieve tools handle GoTools tools = sensor.Tools; // add ProfilePosition tool, retreive tool handle GoProfilePosition profilePositionTool = (GoProfilePosition)tools.AddTool(GoToolType.ProfilePosition); // set name for tool profilePositionTool.Name = "Profile position Test"; // add Z measurement for ProfilePosition tool GoProfilePositionZ zProfileMeasurementTop = profilePositionTool.ZMeasurement; zProfileMeasurementTop.Enabled = true; zProfileMeasurementTop.Id = 0; //set ProfilePosition feature to top GoProfileFeature profileFeature = profilePositionTool.Feature; profileFeature.FeatureType = GoProfileFeatureType.MaxZ; // set the ROI to fill the entire active area GoProfileRegion regionTop = profileFeature.Region; regionTop.X = setup.GetTransformedDataRegionX(GoRole.Main); regionTop.Z = setup.GetTransformedDataRegionZ(GoRole.Main); regionTop.Height = setup.GetTransformedDataRegionHeight(GoRole.Main); regionTop.Width = setup.GetTransformedDataRegionWidth(GoRole.Main); // enable Ethernet output for measurement tool GoOutput output = sensor.Output; GoEthernet ethernetOutput = output.GetEthernet(); ethernetOutput.ClearAllSources(); ethernetOutput.AddSource(GoOutputSource.Measurement, 0); } catch (KException ex) { Console.WriteLine("Error: {0}", ex.Status); } // wait for ESC key Console.WriteLine("\nPress ENTER to continue"); do { System.Threading.Thread.Sleep(100); } while (Console.Read() != (int)ConsoleKey.Enter); return(1); }
Rect GetXZROI() { GoSetup _setup = _sensor.Setup; GoRole role = _sensor.Role; string jobName = _sensor.DefaultJob; _syncContext.Post(delegate { jobFile.Content = jobName; }, null); System.Windows.Point topLeft = new System.Windows.Point(_setup.GetActiveAreaXLimitMin(role), _setup.GetActiveAreaZLimitMax(role)); System.Windows.Point bottomRight = new System.Windows.Point(_setup.GetActiveAreaXLimitMax(role), _setup.GetActiveAreaZLimitMin(role)); Rect rect = new Rect(topLeft, bottomRight); return(rect); }
public int GetExposure(ref double exposureValue) { int rtn = 9; try { system_main_setup = sensor_main.Setup; exposureValue = system_main_setup.GetExposure(GoRole.Main); //get exposure/获取曝光 rtn = 0; } catch (KException ex) { rtn = (int)ex.Status; } return(rtn); }
int CalibrationSensor(int goalignmentType, int alignmentmovingTarget, double diskDiameter, double diskHeight) { try { GoSetup setup = sensor_main.Setup; setup.AlignmentType = GoAlignmentType.Moving; setup.AlignmentMovingTarget = GoAlignmentTarget.Disk; setup.DiskDiameter = diskDiameter; setup.DiskHeight = diskHeight; setup.AlignmentEncoderCalibrateEnabled = true; sensor_main.Align(); //wait for calibration disk to be scanned dataSet = system_main.ReceiveData(300000000); for (UInt32 i = 0; i < dataSet.Count; i++) { GoAlignMsg dataItem = (GoAlignMsg)dataSet.Get(i); if (dataItem.MessageType == GoDataMessageType.Alignment) { if (dataItem.Status == KStatus.Ok) { calibrationSuccessfulBl = true; } else { calibrationSuccessfulBl = false; } } } } catch (KException ex) { if (ex.Status == KStatus.ErrorTimeout) { errorInformation.Add(DateTime.Now.ToString("yyyy:MM:dd HHmmss") + "calibration disk time out"); } else if (ex.Status != KStatus.Ok) { errorInformation.Add(DateTime.Now.ToString("yyyy:MM:dd HHmmss") + "calibration error code" + ex.Status); } } return(0); }
public int SetExposure(double currentExposureAdd) { int rtn = 9; try { system_main_setup = sensor_main.Setup; currentExposre = system_main_setup.GetExposure(GoRole.Main); //set exposure/获取曝光 system_main_setup.SetExposure(GoRole.Main, currentExposre + currentExposureAdd); sensor_main.Flush(); rtn = 0; } catch (KException ex) { rtn = (int)ex.Status; } return(rtn); }
static int Main(string[] args) { try { KApiLib.Construct(); GoSdkLib.Construct(); GoSystem system = new GoSystem(); GoSensor sensor; double currentExposure, newExposure; KIpAddress ipAddress = KIpAddress.Parse(Constants.SENSOR_IP); sensor = system.FindSensorByIpAddress(ipAddress); sensor.Connect(); GoSetup setup = sensor.Setup; currentExposure = setup.GetExposure(GoRole.Main); Console.WriteLine("Current Parameters:"); Console.WriteLine("-------------------"); Console.WriteLine("Exposure: {0}", currentExposure); setup.SetExposure(GoRole.Main, currentExposure + 200); sensor.Flush(); newExposure = setup.GetExposure(GoRole.Main); Console.WriteLine("New Parameters:"); Console.WriteLine("-------------------"); Console.WriteLine("Exposure: {0}", newExposure); sensor.CopyFile("_live.job", "newExposure.job"); sensor.DefaultJob = "newExposure.job"; setup.SetExposure(GoRole.Main, currentExposure); } catch (KException ex) { Console.WriteLine("Error: {0}", ex.Status); } // wait for Enter key Console.WriteLine("\nPress ENTER to continue"); do { System.Threading.Thread.Sleep(100); } while (Console.Read() != (int)ConsoleKey.Enter); return(1); }
void goRun() { try { KApiLib.Construct(); GoSdkLib.Construct(); system = new GoSystem(); GoSensor sensor; KIpAddress ipAddress = KIpAddress.Parse(IPAddress); GoDataSet dataSet = new GoDataSet(); sensor = system.FindSensorByIpAddress(ipAddress); sensor.Connect(); infoTxt.Text = "Conn" + Environment.NewLine; GoSetup setup = sensor.Setup; setup.ScanMode = GoMode.Surface; system.EnableData(true); system.SetDataHandler(OnDataReceived); infoTxt.Text += "Binding data handler" + Environment.NewLine; system.Start(); infoTxt.Text += "System Started" + Environment.NewLine; infoTxt.Text += "Waiting Data" + Environment.NewLine; GoActiveAreaConfig goActiveAreaConfig = new GoActiveAreaConfig(); sensor.Setup.GetActiveAreaLength(GoRole.Main); GoSetup set = sensor.Setup; setup. // wait for Enter key } catch (KException ex) { } }
public void SetupMeasurement() //Connect to Gocator system.setup measurement data under profile mode { system_main_setup = sensor_main.Setup; //retrieve setup handle }
public static void takephoto(string name2) { try { KApiLib.Construct(); GoSdkLib.Construct(); GoSystem system = new GoSystem(); GoSensor sensor; KIpAddress ipAddress = KIpAddress.Parse(Constants.SENSOR_IP); GoDataSet dataSet = new GoDataSet(); sensor = system.FindSensorByIpAddress(ipAddress); sensor.Connect(); GoSetup setup = sensor.Setup; setup.ScanMode = GoMode.Surface; system.EnableData(true); system.Start(); Console.WriteLine("Waiting for Whole Part Data..."); dataSet = system.ReceiveData(30000000); //DataContext context = new DataContext(); for (UInt32 i = 0; i < dataSet.Count; i++) { GoDataMsg dataObj = (GoDataMsg)dataSet.Get(i); switch (dataObj.MessageType) { case GoDataMessageType.Stamp: { GoStampMsg stampMsg = (GoStampMsg)dataObj; for (UInt32 j = 0; j < stampMsg.Count; j++) { GoStamp stamp = stampMsg.Get(j); Console.WriteLine("Frame Index = {0}", stamp.FrameIndex); Console.WriteLine("Time Stamp = {0}", stamp.Timestamp); Console.WriteLine("Encoder Value = {0}", stamp.Encoder); } } break; case GoDataMessageType.UniformSurface: { GoUniformSurfaceMsg goSurfaceMsg = (GoUniformSurfaceMsg)dataObj; // 定义变量gosurfacemsg,类型gosurfacemsg long length = goSurfaceMsg.Length; //surface长度 long width = goSurfaceMsg.Width; //surface宽度 long bufferSize = width * length; double XResolution = goSurfaceMsg.XResolution / 1000000.0; //surface 数据X方向分辨率为nm,转为mm double YResolution = goSurfaceMsg.YResolution / 1000000.0; //surface 数据Y方向分辨率为nm,转为mm double ZResolution = goSurfaceMsg.ZResolution / 1000000.0; //surface 数据Z方向分辨率为nm,转为mm double XOffset = goSurfaceMsg.XOffset / 1000.0; //接收到surface数据X方向补偿单位um,转mm double YOffset = goSurfaceMsg.YOffset / 1000.0; //接收到surface数据Y方向补偿单位um,转mm double ZOffset = goSurfaceMsg.ZOffset / 1000.0; //接收到surface数据Z方向补偿单位um,转mm IntPtr bufferPointer = goSurfaceMsg.Data; int rowIdx, colIdx; SurfacePoints[] surfacePointCloud = new SurfacePoints[bufferSize]; short[] ranges = new short[bufferSize]; Marshal.Copy(bufferPointer, ranges, 0, ranges.Length); FileStream fs; string path = string.Format("D:\\Grasp\\Grasp\\EyeToHandData\\{0}.txt", name2); //if (!File.Exists(path)) //{ fs = new FileStream(path, FileMode.Create, FileAccess.Write); //else //{ // fs = new FileStream(path, FileMode.Append, FileAccess.Write); //} StreamWriter sr = new StreamWriter(fs); for (rowIdx = 0; rowIdx < length; rowIdx++) //row is in Y direction { for (colIdx = 0; colIdx < width; colIdx++) //col is in X direction { surfacePointCloud[rowIdx * width + colIdx].x = colIdx * XResolution + XOffset; //客户需要的点云数据X值 surfacePointCloud[rowIdx * width + colIdx].y = rowIdx * YResolution + YOffset; //客户需要的点云数据Y值 surfacePointCloud[rowIdx * width + colIdx].z = ranges[rowIdx * width + colIdx] * ZResolution + ZOffset; //客户需要的点云数据Z值 sr.WriteLine(surfacePointCloud[rowIdx * width + colIdx].x + "," + surfacePointCloud[rowIdx * width + colIdx].y + "," + surfacePointCloud[rowIdx * width + colIdx].z); //开始写入值 } } sr.Write("end"); //ushort[] ZValues = new ushort[ranges.Length]; //for (int k = 0; k < ranges.Length; k++) //{ // ZValues[k] = (ushort)(ranges[k] - short.MinValue); //} //for (UInt32 k = 0; k < bufferSize; k++) //{ // sr.WriteLine(surfacePointCloud[k].x.ToString() + "," + surfacePointCloud[k].y.ToString() + "," + surfacePointCloud[k].z.ToString());//开始写入值 //} sr.Close(); fs.Close(); } break; case GoDataMessageType.SurfaceIntensity: { GoSurfaceIntensityMsg surfaceMsg = (GoSurfaceIntensityMsg)dataObj; long width = surfaceMsg.Width; long height = surfaceMsg.Length; long bufferSize = width * height; IntPtr bufferPointeri = surfaceMsg.Data; Console.WriteLine("Whole Part Intensity Image received:"); Console.WriteLine(" Buffer width: {0}", width); Console.WriteLine(" Buffer height: {0}", height); byte[] ranges = new byte[bufferSize]; Marshal.Copy(bufferPointeri, ranges, 0, ranges.Length); } break; } } system.Stop(); } catch (KException ex) { Console.WriteLine("Error: {0}", ex.Status); } // wait for ESC key //Console.WriteLine("\nPress ENTER to continue"); //do //{ // System.Threading.Thread.Sleep(100); //} while (Console.Read() != (int)ConsoleKey.Enter); }
private void Form1_Load(object sender, EventArgs e) { // 主窗口大小、位置 int Desk_width = Screen.PrimaryScreen.WorkingArea.Width; int Desk_height = Screen.PrimaryScreen.WorkingArea.Height; Width = Desk_width; Height = Desk_height; Location = new Point(0, 0); // 尝试连接ABB NetworkScanner networkScanner = new NetworkScanner(); networkScanner.Scan(); controllers = networkScanner.Controllers; foreach (ControllerInfo info in controllers) { ListViewItem item = new ListViewItem("PC"); item.SubItems.Add("ABB"); item.SubItems.Add("Detected"); item.Tag = info; listView_Log.Items.Add(item); ABB_Connect_OK = true; if_ABB_init = true; } // 初始化内存映射 if (If_Init_mmf == false) { try { mmf = MemoryMappedFile.CreateNew(memo_file_name, memo_capacity); } catch (Exception Memo_e) { Console.WriteLine("Memo File: {0} Exception caught.", Memo_e); return; } try { accessor = mmf.CreateViewAccessor(); } catch (Exception Memo_e) { Console.WriteLine("Memo File: {0} Exception caught.", Memo_e); return; } If_Init_mmf = true; } // Endof-初始化内存映射 // Gocator启动 // 进行Gocator初始化的相关工作 KApiLib.Construct(); GoSdkLib.Construct(); GC_system = new GoSystem(); KIpAddress ipAddress = KIpAddress.Parse(SENSOR_IP); try { sensor = GC_system.FindSensorByIpAddress(ipAddress); } catch (Exception GC_e) { Console.WriteLine("XX Gocator Error XX : {0} Exception caught.", GC_e); return; } sensor.Connect(); sensor_setup = sensor.Setup; GC_system.EnableData(true); GC_system.SetDataHandler(onData); if_Gocator_init = true; // Endof-Gocator启动 }// - Endof - Form1Load
/// <summary> /// Get Point Cloud from Gocator /// </summary> /// <returns></returns> private void Point3DGenerator(KObject data) { GoDataSet goDataSource = (GoDataSet)data; PointCloud pc = new PointCloud(); long count = goDataSource.Count; for (int i = 0; i < count; i++) { GoDataMsg dataMsg = (GoDataMsg)goDataSource.Get(i); switch (dataMsg.MessageType) { case GoDataMessageType.Surface: GoSurfaceMsg goSurfaceMsg = (GoSurfaceMsg)(dataMsg); pc.Width = (int)goSurfaceMsg.Width; pc.Height = (int)goSurfaceMsg.Length; pc.XResolution = (float)goSurfaceMsg.XResolution / 1000000; pc.YResolution = (float)goSurfaceMsg.YResolution / 1000000; pc.ZResolution = (float)goSurfaceMsg.ZResolution / 1000000; pc.XOffset = (float)goSurfaceMsg.XOffset / 1000; pc.ZOffset = (float)goSurfaceMsg.ZOffset / 1000; pc.YOffset = (float)goSurfaceMsg.YOffset / 1000; GoSetup goSetup = _sensor.Setup; GoRole goRole = new GoRole(); pc.ZStart = (float)goSetup.GetActiveAreaZ(goRole); pc.XStart = (float)goSetup.GetActiveAreaX(goRole); pc.ZRange = (float)goSetup.GetActiveAreaHeight(goRole); /// //generate csv file for point data save /// pc.ProfileList = new List <List <Point3D> >(); //int pointsCount = 0; pc.Point3DArray = new Point3D[pc.Width * pc.Height]; int pointsCount = 0; for (int j = 0; j < pc.Height; j++) { List <Point3D> profileList = new List <Point3D>(); for (int k = 0; k < pc.Width; k++) { Point3D tempPoint = new Point3D(); tempPoint.X = pc.XOffset + k * pc.XResolution; tempPoint.Y = pc.YOffset + j * pc.YResolution; //tempPoint.Z = (goSurfaceMsg.Get(j, k) == -32768) ? 0 : (pc.ZOffset + goSurfaceMsg.Get(j, k) * pc.ZResolution); //No Z Start //tempPoint.X = k * pc.XResolution; //tempPoint.Y = j * pc.YResolution; tempPoint.Z = (goSurfaceMsg.Get(j, k) == -32768) ? 0 : (pc.ZOffset + goSurfaceMsg.Get(j, k) * pc.ZResolution - pc.ZStart); profileList.Add(tempPoint); pc.Point3DArray[pointsCount] = tempPoint; pointsCount++; } pc.ProfileList.Add(profileList); } //data.Destroy(); dataMsg.Destroy(); goSurfaceMsg.Destroy(); SerializePointCloud(pc); break; default: break; } } }