public void syncReceiveData()
        {
            dataSet = system_main.ReceiveData(30000000);
            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);
                        getStamp.FrameIndex = stamp.FrameIndex;
                        getStamp.Timestamp  = stamp.Timestamp;
                        getStamp.Encoder    = stamp.Encoder;
                        get_stamp_FrameIndex.Add(stamp.FrameIndex);
                        get_stamp_TimeStamp.Add(stamp.Timestamp);
                        get_stamp_EncoderValue.Add(stamp.Encoder);
                    }
                    dataReceivedFlag.Stamp = 1;
                }
                break;

                case GoDataMessageType.Measurement:
                {
                    GoMeasurementMsg measurementMsg = (GoMeasurementMsg)dataObj;
                    for (UInt32 k = 0; k < measurementMsg.Count; k++)
                    {
                        GoMeasurementData measurementData = measurementMsg.Get(k);
                        getMeasurement.Id      = measurementMsg.Id;
                        getMeasurement.value   = measurementData.Value;
                        getMeasurement.decison = measurementData.Decision;
                        get_measurementMsg_Id.Add(measurementMsg.Id);
                        get_measurementMsg_Value.Add(measurementData.Value);
                        get_measurementMsg_Decison.Add(measurementData.Decision);
                    }
                    dataReceivedFlag.Measurement = 1;
                }
                break;

                case GoDataMessageType.Alignment:
                {
                    GoAlignMsg dataItem = (GoAlignMsg)dataSet.Get(i);
                    if (dataItem.Status == KStatus.Ok)
                    {
                        calibrationSuccessfulBl = true;
                    }
                    else
                    {
                        calibrationSuccessfulBl = false;
                    }
                }
                break;
                }
            }
        }
示例#2
0
        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);
        }
示例#3
0
        static int Main(string[] args)
        {
            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();
                system.EnableData(true);
                system.Start();
                // refer to SetupMeasurement.cs for setting up of the measurement tools
                dataSet = system.ReceiveData(30000000);
                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.Measurement:
                    {
                        GoMeasurementMsg measurementMsg = (GoMeasurementMsg)dataObj;
                        for (UInt32 k = 0; k < measurementMsg.Count; ++k)
                        {
                            GoMeasurementData measurementData = measurementMsg.Get(k);
                            Console.WriteLine("ID: {0}", measurementMsg.Id);
                            Console.WriteLine("Value: {0}", measurementData.Value);
                            Console.WriteLine("Decision: {0}", measurementData.Decision);
                        }
                    }
                    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);

            return(1);
        }
示例#4
0
        public List <List <PosXYZ> > GetResult()
        {
            if (FrameworkExtenion.IsSimulate)
            {
                return(new List <List <PosXYZ> >()
                {
                    new List <PosXYZ>()
                    {
                        new PosXYZ(1, 1, 1), new PosXYZ(1, 1, 1), new PosXYZ(1, 1, 1)
                    },
                    new List <PosXYZ>()
                    {
                        new PosXYZ(2, 2, 2), new PosXYZ(2, 2, 2), new PosXYZ(2, 2, 2)
                    }
                });
            }

            try
            {
                //goOutput = sensor.Output.GetEthernetAt(0);
                //goOutput.ClearAllSources();

                var dataSet = system.ReceiveData(3000000);

                system.Stop();
                system.EnableData(false);

                //parse dataSet
                for (int i = 0; i < dataSet.Count; i++)
                {
                    GoDataMsg dataObj = (GoDataMsg)dataSet.Get(i);

                    switch (dataObj.MessageType)
                    {
                    case GoDataMessageType.Measurement:
                    {
                        //GoMeasurementMsg measurementMsg = (GoMeasurementMsg)dataObj;
                        //if (measurementMsg != null)
                        //{
                        //    var output = new List<double[]>();
                        //    for (var k = 0; k < measurementMsg.Count; ++k)
                        //    {
                        //        GoMeasurementData measurementData = measurementMsg.Get(k);
                        //        var data = new double[3];
                        //        data[0] = measurementMsg.Id;
                        //        data[1] = measurementData.Value;
                        //        data[2] = measurementData.Decision;
                        //        output.Add(data);
                        //    }
                        //    return output;
                        //}
                    }
                    break;

                    case GoDataMessageType.Generic:
                    {
                        GoGenericMsg genericMsg = dataObj as GoGenericMsg;
                        if (genericMsg != null)
                        {
                            byte[] buffer = new byte[genericMsg.BufferSize];
                            Marshal.Copy(genericMsg.BufferData, buffer, 0, (int)genericMsg.BufferSize);

                            var gridRawData = FlatnessParser.Parse(buffer);

                            var output = FlatnessParser.GetGridOutput(gridRawData);

                            if (FlatnessParser.GridParseMethod == GridParseMethod.RigidAlignAndOrderByX)
                            {
                                if (DisplayResultEvent != null)
                                {
                                    var dataList = new List <PosXYZ>();
                                    foreach (var d in output)
                                    {
                                        dataList.AddRange(d);
                                    }
                                    DisplayResultEvent.Invoke(FlatnessParser.CreateDisplay(dataList));
                                }
                            }
                            else
                            {
                                if (DisplayResultEvent != null)
                                {
                                    DisplayResultEvent.Invoke(FlatnessParser.CreateDisplay(gridRawData));
                                }
                            }

                            return(output);
                        }
                    }
                    break;
                    }
                }
            }
            catch (Exception ex)
            {
                LastError = $"GetResultError: {ex.Message}";
            }

            return(null);
        }
示例#5
0
        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);
        }
示例#6
0
        static int Main(string[] args)
        {
            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();
                system.EnableData(true);
                system.Start();
                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.UniformProfile:
                    {
                        GoResampledProfileMsg profileMsg = (GoResampledProfileMsg)dataObj;
                        Console.WriteLine("  Resampled Profile Message batch count: {0}", profileMsg.Count);
                        for (UInt32 k = 0; k < profileMsg.Count; ++k)
                        {
                            int validPointCount   = 0;
                            int profilePointCount = profileMsg.Width;
                            Console.WriteLine("    Item[{0}]: Profile data ({1} points)", k, profileMsg.Width);
                            context.xResolution = (double)profileMsg.XResolution / 1000000;
                            context.zResolution = (double)profileMsg.ZResolution / 1000000;
                            context.xOffset     = (double)profileMsg.XOffset / 1000;
                            context.zOffset     = (double)profileMsg.ZOffset / 1000;

                            short[]        points        = new short[profilePointCount];
                            ProfilePoint[] profileBuffer = new ProfilePoint[profilePointCount];
                            IntPtr         pointsPtr     = profileMsg.Data;
                            Marshal.Copy(pointsPtr, points, 0, points.Length);

                            for (UInt32 arrayIndex = 0; arrayIndex < profilePointCount; ++arrayIndex)
                            {
                                if (points[arrayIndex] != -32768)
                                {
                                    profileBuffer[arrayIndex].x = context.xOffset + context.xResolution * arrayIndex;
                                    profileBuffer[arrayIndex].z = context.zOffset + context.zResolution * points[arrayIndex];
                                    validPointCount++;
                                }
                                else
                                {
                                    profileBuffer[arrayIndex].x = context.xOffset + context.xResolution * arrayIndex;
                                    profileBuffer[arrayIndex].z = -32768;
                                }
                            }
                            Console.WriteLine("Received {0} Range Points", profilePointCount);
                            Console.WriteLine("Valid Points {0}", validPointCount);
                        }
                    }
                    break;

                    case GoDataMessageType.ProfilePointCloud:
                    {
                        GoProfileMsg profileMsg = (GoProfileMsg)dataObj;
                        Console.WriteLine("  Profile Message batch count: {0}", profileMsg.Count);
                        for (UInt32 k = 0; k < profileMsg.Count; ++k)
                        {
                            int  validPointCount   = 0;
                            long profilePointCount = profileMsg.Width;
                            Console.WriteLine("    Item[{0}]: Profile data ({1} points)", i, profileMsg.Width);
                            context.xResolution = profileMsg.XResolution / 1000000;
                            context.zResolution = profileMsg.ZResolution / 1000000;
                            context.xOffset     = profileMsg.XOffset / 1000;
                            context.zOffset     = profileMsg.ZOffset / 1000;
                            GoPoints[]     points        = new GoPoints[profilePointCount];
                            ProfilePoint[] profileBuffer = new ProfilePoint[profilePointCount];
                            int            structSize    = Marshal.SizeOf(typeof(GoPoints));
                            IntPtr         pointsPtr     = profileMsg.Data;
                            for (UInt32 array = 0; array < profilePointCount; ++array)
                            {
                                IntPtr incPtr = new IntPtr(pointsPtr.ToInt64() + array * structSize);
                                points[array] = (GoPoints)Marshal.PtrToStructure(incPtr, typeof(GoPoints));
                            }

                            for (UInt32 arrayIndex = 0; arrayIndex < profilePointCount; ++arrayIndex)
                            {
                                if (points[arrayIndex].x != -32768)
                                {
                                    profileBuffer[arrayIndex].x = context.xOffset + context.xResolution * points[arrayIndex].x;
                                    profileBuffer[arrayIndex].z = context.xOffset + context.xResolution * points[arrayIndex].y;
                                    validPointCount++;
                                }
                                else
                                {
                                    profileBuffer[arrayIndex].x = -32768;
                                    profileBuffer[arrayIndex].z = -32768;
                                }
                            }
                            Console.WriteLine("Received {0} Range Points", profilePointCount);
                            Console.WriteLine("Valid Points {0}", validPointCount);
                        }
                    }
                    break;

                    case GoDataMessageType.ProfileIntensity:
                    {
                        GoProfileIntensityMsg profileMsg = (GoProfileIntensityMsg)dataObj;
                        Console.WriteLine("  Profile Intensity Message batch count: {0}", profileMsg.Count);
                        for (UInt32 k = 0; k < profileMsg.Count; ++k)
                        {
                            byte[] intensity    = new byte[profileMsg.Width];
                            IntPtr intensityPtr = profileMsg.Data;
                            Marshal.Copy(intensityPtr, intensity, 0, intensity.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);

            return(1);
        }