/// <summary>
        /// Вывод файла координат
        /// </summary>
        /// <param name="points">Лист контуров с соответствующим цетром масс для контура</param>
        public static void PointToFile(IList <CentroMass.ContourWithMass> points, int timeend)
        {
            //****Создание экземпляра файла Excel****
            // Создаём экземпляр приложения
            Excel.Application excelApp = new Excel.Application();
            // Создаём экземпляр рабочий книги Excel
            Excel.Workbook workBook;
            // Создаём экземпляр листа Excel
            Excel.Worksheet workSheet;
            workBook  = excelApp.Workbooks.Add();
            workSheet = (Excel.Worksheet)workBook.Worksheets.get_Item(1);

            //Внесение в книгу первых строк констант
            workSheet.Name = "data1";
            workSheet.Range["A2:D10000"].NumberFormat = "0.00E+00"; // установка формата ячеек
            workSheet.Cells[1, 1] = "t";
            workSheet.Cells[1, 2] = "x";
            workSheet.Cells[1, 3] = "y";
            workSheet.Cells[1, 4] = "z";
            workSheet.Cells[2, 1] = 0 * 1e-3;
            workSheet.Cells[2, 4] = 0;
            workSheet.Cells[2, 2] = 390;
            workSheet.Cells[2, 3] = 686.6;
            double TIME  = 1 * 1e-3;
            int    COUNT = 3;

            //Интерпритация команды опускания пера манипулятора
            var STRUCT = RobotCommand.Start(ref TIME, 687);

            for (int i = 0; i < STRUCT.Count; i++)
            {
                workSheet.Cells[COUNT, 1] = STRUCT[i].time;
                workSheet.Cells[COUNT, 4] = STRUCT[i].z;
                workSheet.Cells[COUNT, 2] = STRUCT[i].x;
                workSheet.Cells[COUNT, 3] = STRUCT[i].y;
                COUNT++;
            }
            STRUCT = null;

            STRUCT = RobotCommand.ToTheContourPoint(ref TIME, 202, -52, 500.000025, points[0].Contr[0].X - 100, points[0].Contr[0].Y + 500);
            for (int i = 0; i < STRUCT.Count; i++)
            {
                workSheet.Cells[COUNT, 1] = STRUCT[i].time;
                workSheet.Cells[COUNT, 4] = STRUCT[i].z;
                workSheet.Cells[COUNT, 2] = STRUCT[i].x;
                workSheet.Cells[COUNT, 3] = STRUCT[i].y;
                COUNT++;
            }
            STRUCT = null;


            bool flagContourType;                               // флаг для поднятия

            for (int i = 0; i < points.Count; i++)              // Коллекция I - ых контуров ( количество найденых 0..n)
            {
                for (int m = 0; m < points[i].Contr.Count; m++) // Обращение к элементам коллекции points[i].Contr
                {
                    workSheet.Cells[COUNT, 1] = TIME;
                    workSheet.Cells[COUNT, 4] = points[i].Contr[m].X - 100;
                    workSheet.Cells[COUNT, 2] = points[i].Contr[m].Y + 500.000025;
                    workSheet.Cells[COUNT, 3] = 200;
                    COUNT++;
                    TIME            = 0.001 + TIME;
                    flagContourType = true; // идем по контуру
                }

                if (i == points.Count - 1)
                {
                    break;
                }
                flagContourType = false; // переход

                if (flagContourType == false)
                {
                    STRUCT = RobotCommand.PenUp(ref TIME, 200, points[i].Contr[points[i].Contr.Count - 1].X - 100, points[i].Contr[points[i].Contr.Count - 1].Y + 500.000025, 1 * 1e-3);
                    for (int j = 0; j < STRUCT.Count; j++)
                    {
                        workSheet.Cells[COUNT, 1] = STRUCT[j].time;
                        workSheet.Cells[COUNT, 4] = STRUCT[j].z;
                        workSheet.Cells[COUNT, 2] = STRUCT[j].x;
                        workSheet.Cells[COUNT, 3] = STRUCT[j].y;
                        COUNT++;
                    }
                    STRUCT = null;

                    STRUCT = RobotCommand.PenPause(ref TIME, 215, points[i].Contr[points[i].Contr.Count - 1].X - 100, points[i].Contr[points[i].Contr.Count - 1].Y + 500.000025, points[i + 1].Contr[points[i + 1].Contr.Count - 1].X - 100, points[i + 1].Contr[points[i + 1].Contr.Count - 1].Y + 500.000025);

                    for (int j = 0; j < STRUCT.Count; j++)
                    {
                        workSheet.Cells[COUNT, 1] = STRUCT[j].time;
                        workSheet.Cells[COUNT, 4] = STRUCT[j].z;
                        workSheet.Cells[COUNT, 2] = STRUCT[j].x;
                        workSheet.Cells[COUNT, 3] = STRUCT[j].y;
                        COUNT++;
                    }
                    STRUCT = null;

                    STRUCT = RobotCommand.PenDown(ref TIME, 215, points[i + 1].Contr[points[i + 1].Contr.Count - 1].X - 100, points[i + 1].Contr[points[i + 1].Contr.Count - 1].Y + 500.000025, 1 * 1e-3);
                    for (int j = 0; j < STRUCT.Count; j++)
                    {
                        workSheet.Cells[COUNT, 1] = STRUCT[j].time;
                        workSheet.Cells[COUNT, 4] = STRUCT[j].z;
                        workSheet.Cells[COUNT, 2] = STRUCT[j].x;
                        workSheet.Cells[COUNT, 3] = STRUCT[j].y;
                        COUNT++;
                    }
                    STRUCT = null;
                }
            }

            STRUCT = RobotCommand.Stop(ref TIME, timeend, points[points.Count - 1].Contr[points[points.Count - 1].Contr.Count - 1].X - 100, points[points.Count - 1].Contr[points[points.Count - 1].Contr.Count - 1].Y + 500.000025, 200);
            for (int j = 0; j < STRUCT.Count; j++)
            {
                workSheet.Cells[COUNT, 1] = STRUCT[j].time;
                workSheet.Cells[COUNT, 4] = STRUCT[j].z;
                workSheet.Cells[COUNT, 2] = STRUCT[j].x;
                workSheet.Cells[COUNT, 3] = STRUCT[j].y;
                COUNT++;
            }

            //Обработка ошибки сохранения
            try
            {
                string outpath = Environment.CurrentDirectory + "/";
                workBook.SaveAs(@outpath + "end_position1.xlsx");
                workBook.Close();
                excelApp.Quit();
            }
            catch (Exception ex)
            {
                workBook.Close();
                excelApp.Quit();
                System.Windows.Forms.MessageBox.Show(ex.Message + "Ошибка сохранения. Файл остался в прежнем состоянии. Ресурсы освобождены.");
            }
        }
Exemple #2
0
        /// <summary>
        /// Интерпритация команд для робота (вычисление траекторий)
        /// </summary>
        /// <param name="points">Входной лист точек всего контура</param>
        /// <param name="Zplot">Высота на которой находится раб.обл</param>
        /// <param name="ZplotPause">Высота на которой будет происходить перемещение с контура на контур</param>
        /// <returns></returns>
        public static IEnumerable <RobotCommand.RobotPosition> InterpretationOfCommands(IList <CentroMass.ContourWithMass> points, double Zplot, double ZplotPause)
        {
            TimeAll Times = new TimeAll();

            Times.Time = 1 * 1e-3;

            ///Манипулятор из точки (0,390,687) будет медленно опускаться в первую точку контура (x1,y1,z0)
            var STRUCT = RobotCommand.Start(Times.Time, Constants.StartZ, Constants.StartY, points[0].Contr[0].X - 100, points[0].Contr[0].Y + Constants.StartYPlot, Zplot);

            foreach (var position in STRUCT)
            {
                RobotCommand.RobotPosition result = new RobotCommand.RobotPosition();
                result.x    = position.x;
                result.y    = position.y;
                result.z    = position.z;
                result.time = position.time;
                Times.Time  = 0.001 + Times.Time;
                yield return(result);
            }


            for (int i = 0; i < points.Count; i++)              // Коллекция I - ых контуров ( количество найденых 0..n)
            {
                for (int m = 0; m < points[i].Contr.Count; m++) // Обращение к элементам коллекции points[i].Contr
                {
                    ///рисуем контур на плоскости
                    RobotCommand.RobotPosition result = new RobotCommand.RobotPosition();
                    result.time = Times.Time;
                    result.z    = points[i].Contr[m].X - 100;
                    result.x    = points[i].Contr[m].Y + Constants.StartYPlot;
                    result.y    = Zplot;
                    Times.Time  = 0.001 + Times.Time;
                    yield return(result);
                }

                ///если контур последний , выход из цикла рисования
                if (i == points.Count - 1)
                {
                    break;
                }
                else
                {
                    ///поднятие рабочего органа манипулятора в точке
                    STRUCT = RobotCommand.PenUp(Times.Time, Zplot, points[i].Contr[points[i].Contr.Count - 1].X - 100, points[i].Contr[points[i].Contr.Count - 1].Y + Constants.StartYPlot, Constants.timeUp, Zplot, ZplotPause);
                    foreach (var position in STRUCT)
                    {
                        RobotCommand.RobotPosition result = new RobotCommand.RobotPosition();
                        result.x    = position.x;
                        result.y    = position.y;
                        result.z    = position.z;
                        result.time = position.time;
                        Times.Time  = 0.001 + Times.Time;
                        yield return(result);
                    }

                    ///вычисление тракетории перемещения из (x1,y1,z0) в (x2,y2,z0)
                    STRUCT = RobotCommand.PenPause(Times.Time, ZplotPause, points[i].Contr[points[i].Contr.Count - 1].X - 100, points[i].Contr[points[i].Contr.Count - 1].Y + Constants.StartYPlot, points[i + 1].Contr[points[i + 1].Contr.Count - 1].X - 100, points[i + 1].Contr[points[i + 1].Contr.Count - 1].Y + Constants.StartYPlot);

                    foreach (var position in STRUCT)
                    {
                        RobotCommand.RobotPosition result = new RobotCommand.RobotPosition();
                        result.x    = position.x;
                        result.y    = position.y;
                        result.z    = position.z;
                        result.time = position.time;
                        Times.Time  = 0.001 + Times.Time;
                        yield return(result);
                    }

                    ///опускание рабочего органа манипулятора в точке
                    STRUCT = RobotCommand.PenDown(Times.Time, ZplotPause, points[i + 1].Contr[points[i + 1].Contr.Count - 1].X - 100, points[i + 1].Contr[points[i + 1].Contr.Count - 1].Y + Constants.StartYPlot, Constants.timeUp, Zplot);
                    foreach (var position in STRUCT)
                    {
                        RobotCommand.RobotPosition result = new RobotCommand.RobotPosition();
                        result.x    = position.x;
                        result.y    = position.y;
                        result.z    = position.z;
                        result.time = position.time;
                        Times.Time  = 0.001 + Times.Time;
                        yield return(result);
                    }
                }
            }
            ///поднятие рабочего органа манипулятора
            STRUCT = RobotCommand.Stop(Times.Time, Constants.StartZ, Constants.StartY, points[points.Count - 1].Contr[points[points.Count - 1].Contr.Count - 1].X - 100, points[points.Count - 1].Contr[points[points.Count - 1].Contr.Count - 1].Y + Constants.StartYPlot, Zplot, Constants.timeUp);
            foreach (var position in STRUCT)
            {
                RobotCommand.RobotPosition result = new RobotCommand.RobotPosition();
                result.x    = position.x;
                result.y    = position.y;
                result.z    = position.z;
                result.time = position.time;
                Times.Time  = 0.001 + Times.Time;
                yield return(result);
            }
            AllTime      = Times;
            AllTime.Time = Times.Time;
        }