Exemplo n.º 1
0
        public void saveToCsv(MotorStatus[] motor_status_array)
        {
            string file = FileRecordMaker.getStringFile("SpeedMotorF", "test-sequence", "csv");

            string output_csv = "time,target_s,sensor_s,odometer\n";

            foreach (MotorStatus sta in motor_status_array)
            {
                output_csv += string.Format("{0},{1},{2},{3}\n", sta.time, sta.target_speed, sta.sensor_speed, sta.odometer / 10.0);
            }


            try
            {
                System.IO.File.WriteAllText(file, output_csv, System.Text.Encoding.UTF8);
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString(), "不能写日志文件!");
            }
            if (is_open_csv)
            {
                try
                {
                    System.Diagnostics.Process.Start(Application.StartupPath + "/" + file);
                }
                catch (Exception exp)
                {
                    MessageBox.Show(exp.ToString(), "不能打开日志文件!");
                }
            }
            return;
        }
Exemplo n.º 2
0
        private void saveBTN_Click(object sender, EventArgs e)
        {
            string file = FileRecordMaker.getStringFile("SpeedMotorF", "test-sequence", "svg");

            chart1.paintSVG(file);
            try
            {
                System.Diagnostics.Process.Start(Application.StartupPath + "/" + file);
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString(), "不能打开日志文件!");
            }
        }
Exemplo n.º 3
0
        public void saveToSvg(MotorStatus[] motor_status_array)
        {
            string file    = FileRecordMaker.getStringFile("SpeedMotorF", "test-sequence", "svg");
            var    setting = new XmlWriterSettings();

            setting.Indent = true;

            XmlWriter writer = XmlWriter.Create(file, setting);
            double    Y_zoom = 0.1;
            double    X_zoom = 1;
            double    w      = motor_status_array.Length * period_in_ms * X_zoom + 100;
            double    h      = 15000 * 2 * Y_zoom + 100;


            writer.WriteStartDocument();
            writer.WriteStartElement("svg", "http://www.w3.org/2000/svg");
            writer.WriteAttributeString("version", "1.1");
            writer.WriteAttributeString("id", "svg_head");
            writer.WriteAttributeString("width", $"{w}");
            writer.WriteAttributeString("height", $"{h}");

            writer.WriteStartElement("g");
            writer.WriteAttributeString("id", "grid");
            writer.WriteAttributeString("transform", $"translate(50, {h/2})");



            string d_st         = "";
            double x_grid_space = 1000 * X_zoom * 0.1;
            double y_grid_space = 1000 * X_zoom * 0.2;

            void buildGrid(string width)
            {
                for (double x = x_grid_space; x < w; x += x_grid_space)
                {
                    d_st += $"M {x} {-h / 2} L {x} {h / 2}";
                }
                for (double y = y_grid_space; y < h / 2; y += y_grid_space)
                {
                    d_st += $"M 0 {y} L {w} {y}";
                    d_st += $"M 0 {-y} L {w} {-y}";
                }
                writer.WriteStartElement("path");
                writer.WriteAttributeString("id", "grid");
                writer.WriteAttributeString("d", d_st);
                writer.WriteAttributeString("stroke", "black");
                writer.WriteAttributeString("stroke-width", width);
                writer.WriteAttributeString("fill", "none");
                writer.WriteEndElement();
            }

            d_st         = "";
            x_grid_space = 1000 * X_zoom * 0.1;
            y_grid_space = 1000 * X_zoom * 0.2;
            buildGrid("0.2");
            d_st         = "";
            x_grid_space = 1000 * X_zoom;
            y_grid_space = 1000 * X_zoom;
            buildGrid("0.4");

            for (double x = x_grid_space; x < w; x += x_grid_space)
            {
                writer.WriteStartElement("text");
                writer.WriteAttributeString("x", $"{x}");
                writer.WriteAttributeString("y", "0");
                writer.WriteAttributeString("fill", "black");
                writer.WriteAttributeString("font-family", "微软雅黑");
                writer.WriteAttributeString("font-size", "32px");
                writer.WriteString($"{x /1000/ X_zoom}s");
                writer.WriteEndElement();
            }


            writer.WriteStartElement("path");
            writer.WriteAttributeString("id", "Coordinate");
            writer.WriteAttributeString("d", $"M 0 0 L {w - 50} 0  M 0 {-h / 2} L  0 {h / 2}");
            writer.WriteAttributeString("stroke", "black");
            writer.WriteAttributeString("stroke-width", "2");
            writer.WriteAttributeString("fill", "none");
            writer.WriteEndElement();



            string target_st  = "M 0 0 ";
            string senseor_st = "M 0 0 ";

            foreach (var sta in motor_status_array)
            {
                string x = $"{X_zoom * sta.time}";
                target_st  += $"L {x} {-sta.target_speed* Y_zoom}";
                senseor_st += $"L {x} {-sta.sensor_speed * Y_zoom}";
            }
            writer.WriteStartElement("path");
            writer.WriteAttributeString("id", "target_speed");
            writer.WriteAttributeString("d", target_st);
            writer.WriteAttributeString("stroke", "DarkViolet");
            writer.WriteAttributeString("stroke-width", "1");
            writer.WriteAttributeString("fill", "none");
            writer.WriteEndElement();

            writer.WriteStartElement("path");
            writer.WriteAttributeString("id", "senseor_speed");
            writer.WriteAttributeString("d", senseor_st);
            writer.WriteAttributeString("stroke", "Green");
            writer.WriteAttributeString("stroke-width", "1");
            writer.WriteAttributeString("fill", "none");
            writer.WriteEndElement();


            writer.WriteEndElement();
            writer.WriteEndElement();

            writer.Flush();
            writer.Close();
            writer.Dispose();

            try
            {
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString(), "不能写入文件!");
            }
            if (is_open_svg)
            {
                try
                {
                    System.Diagnostics.Process.Start(Application.StartupPath + "/" + file);
                }
                catch (Exception exp)
                {
                    MessageBox.Show(exp.ToString(), "不能打开文件!");
                }
            }
            return;
        }