Beispiel #1
0
        private void TestSequence_Thread(SrbThread.dIsThreadStoping IsStoping)
        {
            int max_speed = (bgd.pid_clu.k0 * 1024 / (bgd.pid_clu.k1 + 1024)) - 10;
            int s0        = 0;
            int s1        = max_speed / 4;
            int s2        = max_speed * 3 / 4;

            int[] speed_table_1 = { s0, s1, s2, s1, s2, s1, s2, s0, -s1, -s2, -s1, -s2, -s1, -s2, s0 };

            Stopwatch sw         = new Stopwatch();
            string    output_csv = "time,target_s,sensor_s,odometer\n";
            double    time       = 0;

            while (true)
            {
                sw.Restart();
                int i = ((int)time) / 1000;
                if (i >= speed_table_1.Length)
                {
                    break;
                }
                bgd.target_speed = speed_table_1[((int)time) / 1000];
                bgd.addDataAccess(1, true);
                output_csv += string.Format("{0},{1},{2},{3}\n", time, bgd.target_speed, bgd.sensor_speed, bgd.odometer / 10.0);
                if (IsStoping())
                {
                    break;
                }
                while (getElapsedMs(sw) < period_in_ms)
                {
                    ;
                }
                time += period_in_ms;
            }
            string path = "./log/SpeedMotor-test-record/";

            path += System.DateTime.Now.ToString("yy-MM-dd");
            path += "/";
            System.IO.Directory.CreateDirectory(path);//如果文件夹不存在就创建它
            string time_str   = System.DateTime.Now.ToString("HHmmss");
            string Table_file = path + "speed_table_1" + time_str + ".csv";

            try
            {
                System.IO.File.WriteAllText(Table_file, output_csv, System.Text.Encoding.UTF8);
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString(), "不能写日志文件!");
            }
            try
            {
                System.Diagnostics.Process.Start(Application.StartupPath + "/" + Table_file);
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString(), "不能打开日志文件!");
            }
            return;
        }
Beispiel #2
0
        private void sync_test_Thread(SrbThread.dIsThreadStoping IsStoping)
        {
            Node[] sync_check_nodes = null;
            string sync_check_str   = null;

            while (true)
            {
                sync_bc.getSyncStatus(ref sync_check_str, ref sync_check_nodes);
                System.Threading.Thread.Sleep(500);
                if (IsStoping())
                {
                    string path = "./log/Sync-record/";
                    path += System.DateTime.Now.ToString("yy-MM-dd");
                    path += "/";
                    System.IO.Directory.CreateDirectory(path);//如果文件夹不存在就创建它
                    string time_str   = System.DateTime.Now.ToString("HHmmss");
                    string Table_file = path + "Sync" + time_str + ".csv";
                    string Png_file   = path + "Sync" + time_str + ".png";
                    string md_file    = path + "Sync" + time_str + ".md";
                    string R_Argument = path + "Sync" + time_str;
                    try
                    {
                        System.IO.File.WriteAllText(Table_file, sync_check_str, System.Text.Encoding.ASCII);
                    }
                    catch (Exception exp)
                    {
                        MessageBox.Show(exp.ToString(), "不能写日志文件!");
                    }

                    string cmdStr = string.Format(@"{2}/{0} {2}/{1}",
                                                  "R/SyncTest.r", R_Argument, Application.StartupPath);
                    SRB.Frame.LanguageR.run(cmdStr);
                    try
                    {
                        System.Diagnostics.Process.Start(Application.StartupPath + "/" + Png_file);
                    }
                    catch (Exception exp)
                    {
                        MessageBox.Show(exp.ToString(), "没有找到图像");
                    }
                    try
                    {
                        System.Diagnostics.Process.Start(Application.StartupPath + "/" + md_file);
                    }
                    catch (Exception exp)
                    {
                        MessageBox.Show(exp.ToString(), "没有找到文档");
                    }
                    return;
                }
            }
        }
Beispiel #3
0
                private void burnAllSTH(SrbThread.dIsThreadStoping IsStoping)
                {
                    System.Collections.Generic.Queue <Node> node_to_update = new System.Collections.Generic.Queue <Node>();
                    appendInfo(null);
                    foreach (Node n in bus)
                    {
                        if (n.Is_in_update == true)
                        {
                            node_to_update.Enqueue(n);
                        }
                    }
                    if (node_to_update.Count == 0)
                    {
                        appendInfo("No Node in update mode. " +
                                   "You may connect new nodes or set some nodes to update mode, than try burn all.\n");
                    }
                    else
                    {
                        appendInfo(string.Format(
                                       "{0} node(s) waiting to be burn.\n\n", node_to_update.Count));
                        int node_counter = 0;
                        foreach (Node n in node_to_update)
                        {
                            if (IsStoping())
                            {
                                appendInfo("Update all canceled.");
                                return;
                            }
                            node_counter++;
                            string hc = n.Updater.Hardware_code;
                            appendInfo(string.Format(
                                           "node {0}/{1} burning. hardware code is {2}\n",
                                           node_counter, node_to_update.Count, hc));

                            var sup_file = sup_loader.findByHardwareCode(hc);
                            if (sup_file != null)
                            {
                                n.Updater.loadFile(sup_file);
                                n.Updater.update();
                                n.gotoNormalMode();
                                appendInfo(string.Format(
                                               "\tburning done\n", hc));
                            }
                            else
                            {
                                appendInfo(string.Format(
                                               "\t.sup file not found for {0}, burning cancled", hc));
                            }
                        }
                    }
                }
Beispiel #4
0
        private void motor_test_Thread(SrbThread.dIsThreadStoping IsStoping)
        {
            Stopwatch sw = new Stopwatch();
            int       speed;
            string    output_csv = "时间,目标速度,传感速度,里程计\n";
            double    time       = 0;

            while (true)
            {
                sw.Restart();
                lock (speed_lock)
                {
                    speed = this.speed;
                }
                bgd.target_speed = speed;
                bgd.addDataAccess(1, true);
                output_csv += string.Format("{0},{1},{2},{3}\n", time, speed, bgd.sensor_speed, bgd.odometer / 10.0);
                if (IsStoping())
                {
                    string path = "./log/测速电机调试记录/";
                    path += System.DateTime.Now.ToString("yy-MM-dd");
                    path += "/";
                    System.IO.Directory.CreateDirectory(path);//如果文件夹不存在就创建它
                    string time_str   = System.DateTime.Now.ToString("HHmmss");
                    string Table_file = path + "电机数据" + time_str + ".csv";
                    try
                    {
                        System.IO.File.WriteAllText(Table_file, output_csv, System.Text.Encoding.UTF8);
                    }
                    catch (Exception exp)
                    {
                        MessageBox.Show(exp.ToString(), "不能写日志文件!");
                    }
                    try
                    {
                        System.Diagnostics.Process.Start(Application.StartupPath + "/" + Table_file);
                    }
                    catch (Exception exp)
                    {
                        MessageBox.Show(exp.ToString(), "不能打开日志文件!");
                    }
                    return;
                }
                while (getElapsedMs(sw) < period_in_ms)
                {
                    ;
                }
                time += period_in_ms;
            }
        }
Beispiel #5
0
 private void synchronizeThread(SrbThread.dIsThreadStoping IsStoping)
 {
     while (true)
     {
         syncAll();
         for (int i = 0; i < sync_timer_top; i++)
         {
             sync_timer_value = i;
             if (IsStoping())
             {
                 return;
             }
             Thread.Sleep(1000);
         }
     }
 }
Beispiel #6
0
                void gotoUpdateModeAllFromPowerOnSTH(SrbThread.dIsThreadStoping IsStoping)
                {
                    var stopwatch = new System.Diagnostics.Stopwatch();

                    stopwatch.Restart();
                    while (true)
                    {
                        bus.singleAccess(bus.accessRequest(null, null, AccessPort.Udp, UDT_CMD_HOLD));
                        if (stopwatch.ElapsedMilliseconds > 10000)
                        {
                            return;
                        }
                        if (IsStoping())
                        {
                            return;
                        }
                    }
                }
Beispiel #7
0
        private void get_speed_table_Thread(SrbThread.dIsThreadStoping IsStoping)
        {
            Stopwatch sw         = new Stopwatch();
            string    output_csv = "pwm,speed\n";
            double    time       = 0;
            ushort    pwm        = 50;

            for (pwm = 0; pwm < 1000; pwm += 1)
            {
                for (int i = 0; i < 20; i++)
                {
                    sw.Restart();
                    bgd.test_pwm_clu.Direction = 0;
                    bgd.test_pwm_clu.Pwm       = pwm;
                    bgd.test_pwm_clu.write();
                    bgd.addDataAccess(1, true);

                    output_csv += string.Format("{0},{1}\n", pwm, bgd.sensor_speed);
                    if (IsStoping())
                    {
                        bgd.test_pwm_clu.Direction = 4;
                        bgd.test_pwm_clu.Pwm       = 0;
                        bgd.test_pwm_clu.write();
                        return;
                    }
                    while (getElapsedMs(sw) < period_in_ms)
                    {
                        ;
                    }
                }
            }


            bgd.test_pwm_clu.Direction = 4;
            bgd.test_pwm_clu.Pwm       = 0;
            bgd.test_pwm_clu.write();
            string path = "./log/SpeedMotor-test-record/";

            path += System.DateTime.Now.ToString("yy-MM-dd");
            path += "/";
            System.IO.Directory.CreateDirectory(path);//如果文件夹不存在就创建它
            string time_str   = System.DateTime.Now.ToString("HHmmss");
            string Table_file = path + "PWM-speed-test" + time_str + ".csv";
            string Png_file   = path + "PWM-speed-test" + time_str + ".png";

            try
            {
                System.IO.File.WriteAllText(Table_file, output_csv, System.Text.Encoding.ASCII);
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString(), "不能写日志文件!");
            }
            using (Process myPro = new Process())
            {
                string cmdStr = string.Format(@"{3}/{0} {3}/{1} {3}/{2}",
                                              "R/moto4.r", Table_file, Png_file, Application.StartupPath);

                string cmdExe = @"C:\Program Files\R\R-4.0.1\bin\rscript.exe";
                //指定启动进程是调用的应用程序和命令行参数
                ProcessStartInfo psi = new ProcessStartInfo(cmdExe, cmdStr);
                myPro.StartInfo = psi;
                myPro.Start();
                myPro.WaitForExit();
            }
            try
            {
                System.Diagnostics.Process.Start(Application.StartupPath + "/" + Png_file);
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString(), "没有找到图像");
            }

            return;
        }
Beispiel #8
0
        public void TestSequence_Thread(SrbThread.dIsThreadStoping IsStoping)
        {
            pd = new PerformanceDetector(10);
            bgd.setPd(pd);
            int lose_times = 0;

            if (pg_last != null)
            {
                chart.remove(pg_last.Plots[0]);
                chart.remove(pg_last.Plots[1]);
            }
            if (pg != null)
            {
                pg_last = pg;
                pg_last.Plots[0].Color = System.Drawing.Color.FromArgb(64, pg_last.Plots[0].Color);
                pg_last.Plots[1].Color = System.Drawing.Color.FromArgb(64, pg_last.Plots[1].Color);
            }
            pg = new PlotGroup(3);
            pg.Plots[0].Color   = System.Drawing.Color.ForestGreen;
            pg.Plots[1].Color   = System.Drawing.Color.Violet;
            chart.Forcu_on_plot = pg.Plots[0];
            chart.add(pg.Plots[0]);
            chart.add(pg.Plots[1]);


            if (target_speed_table == null)
            {
                target_speed_table = initSpeedArray();
            }
            Stopwatch sw = new Stopwatch();

            float time = 0f;

            sw.Restart();
            object motion = null;

            double[] temp = new double[3];
            while (time < target_speed_table.Max_time)
            {
                pd.beginCheck();

                bgd.target_speed = target_speed_table.speed(time, ref motion);

                pd.checkPoint(1);
                bgd.addDataAccess_pd(1, true);
                pd.checkPoint(5);
                temp[0] = bgd.target_speed;
                temp[1] = bgd.sensor_speed;
                temp[2] = bgd.odometer;
                pg.append(time, temp);
                pd.checkPoint(6);
                bool check(long[] ticks)
                {
                    return(((ticks[6] - ticks[0]).tickToMs()) > 2);
                }

                pd.endCheckPoint(check);

                if (IsStoping())
                {
                    break;
                }
                while (sw.getElapsedMs() - time < period_in_ms)
                {
                    ;
                }
                time = sw.getElapsedMs();
            }
            string lose_sync_report = "";

            pd.initPage();
            do
            {
                lose_sync_report += $"T={(pd[6] - pd[0]).tickToMs():f2}, Send = {pd[3] - pd[2]}, recv = {pd[4] - pd[3]},";
                lose_sync_report += $"a1={pd[2] - pd[1]}, a2 = {pd[5] - pd[4]} ";
                lose_sync_report += $"access-(send+recv)={pd[5] - pd[1]-(pd[4] - pd[2])}\n\n";
            }while (pd.nextPage());



            this.lose_sync_report = lose_sync_report;
            if (eGetMotorStatus != null)
            {
                eGetMotorStatus.Invoke(pg);
            }
        }