예제 #1
0
 private void trackK4_MouseUp(object sender, MouseEventArgs e)
 {
     if (K4 != trackK4.Value)
     {
         K4 = trackK4.Value;
         string str = K4.ToString();
         textK4.Text = str;
         koshiClient.uartWrite("#d" + str + "$");
     }
 }
예제 #2
0
파일: Form1.cs 프로젝트: lipoyang/Pendolino
 private void trackK4_MouseUp(object sender, MouseEventArgs e)
 {
     if (K4 != trackK4.Value)
     {
         K4 = trackK4.Value;
         string str = K4.ToString();
         textK4.Text = str;
         gpduinoClient.send("#d" + str + "$");
     }
 }
예제 #3
0
        private void SerialComGyro_callback(char[] rxBuff)
        {
            string data = new string(rxBuff);

            if (data.Length < 1)
            {
                return;
            }

            switch (data[0])
            {
            // ログデータ
            case 'd':
                try
                {
                    int   t, y;
                    float theta, omega, x, v;
                    float y1, y2, y3, y4;
                    t = Convert.ToInt32(data.Substring(1, 4), 16);

                    theta = (float)Convert.ToInt16(data.Substring(5, 4), 16) / 100.0F;
                    omega = (float)Convert.ToInt16(data.Substring(9, 4), 16) / 100.0F;
                    x     = (float)Convert.ToInt16(data.Substring(13, 4), 16) / 100.0F;
                    v     = (float)Convert.ToInt16(data.Substring(17, 4), 16) / 100.0F;
                    y     = Convert.ToInt16(data.Substring(21, 4), 16);

                    y1 = K1 * theta;
                    y2 = K2 * omega;
                    y3 = K3 * x / 100;
                    y4 = K4 * v / 100;

                    this.BeginInvoke((Action)(() => {
                        textTheta.Text = theta.ToString("F1");
                        textOmega.Text = omega.ToString("F1");
                        textX.Text = x.ToString("F1");
                        textV.Text = v.ToString("F1");

                        textK1Theta.Text = y1.ToString("F1");
                        textK2Omega.Text = y2.ToString("F1");
                        textK3X.Text = y3.ToString("F1");
                        textK4V.Text = y4.ToString("F1");

                        textY.Text = y.ToString();

                        if (t < time)
                        {
                            chart1.Series[0].Points.Clear();
                            chart1.Series[1].Points.Clear();
                            chart2.Series[0].Points.Clear();
                            chart2.Series[1].Points.Clear();
                            chart3.Series[0].Points.Clear();
                            chart3.Series[1].Points.Clear();
                            chart3.Series[2].Points.Clear();
                            chart3.Series[3].Points.Clear();
                            chart3.Series[4].Points.Clear();
                        }
                        time = t;

                        if (time < 30000)
                        {
                            chart1.ChartAreas[0].AxisX.Minimum = 0;
                            chart1.ChartAreas[0].AxisX.Maximum = 30000;
                            chart2.ChartAreas[0].AxisX.Minimum = 0;
                            chart2.ChartAreas[0].AxisX.Maximum = 30000;
                            chart3.ChartAreas[0].AxisX.Minimum = 0;
                            chart3.ChartAreas[0].AxisX.Maximum = 30000;
                        }
                        else
                        {
                            chart1.ChartAreas[0].AxisX.Minimum = time - 30000;
                            chart1.ChartAreas[0].AxisX.Maximum = time;
                            chart2.ChartAreas[0].AxisX.Minimum = time - 30000;
                            chart2.ChartAreas[0].AxisX.Maximum = time;
                            chart3.ChartAreas[0].AxisX.Minimum = time - 30000;
                            chart3.ChartAreas[0].AxisX.Maximum = time;
                        }

                        double max;
                        max = Math.Abs(theta);
                        if (max > MAX_THETA)
                        {
                            chart1.ChartAreas[0].AxisY.Maximum = MAX_THETA * 2;
                            chart1.ChartAreas[0].AxisY.Minimum = -MAX_THETA * 2;
                            chart1.ChartAreas[0].AxisY.Interval = MAX_THETA;
                            time1 = time;
                        }
                        if (time > time1 + 30000)
                        {
                            chart1.ChartAreas[0].AxisY.Maximum = MAX_THETA;
                            chart1.ChartAreas[0].AxisY.Minimum = -MAX_THETA;
                            chart1.ChartAreas[0].AxisY.Interval = MAX_THETA / 2;
                        }

                        max = Math.Abs(omega);
                        if (max > MAX_OMEGA)
                        {
                            chart1.ChartAreas[0].AxisY2.Maximum = MAX_OMEGA * 2;
                            chart1.ChartAreas[0].AxisY2.Minimum = -MAX_OMEGA * 2;
                            chart1.ChartAreas[0].AxisY2.Interval = MAX_OMEGA;
                            time2 = time;
                        }
                        if (time > time2 + 30000)
                        {
                            chart1.ChartAreas[0].AxisY2.Maximum = MAX_OMEGA;
                            chart1.ChartAreas[0].AxisY2.Minimum = -MAX_OMEGA;
                            chart1.ChartAreas[0].AxisY2.Interval = MAX_OMEGA / 2;
                        }

                        max = Math.Abs(x);
                        if (max > MAX_X)
                        {
                            chart2.ChartAreas[0].AxisY.Maximum = MAX_X * 2;
                            chart2.ChartAreas[0].AxisY.Minimum = -MAX_X * 2;
                            chart2.ChartAreas[0].AxisY.Interval = MAX_X;
                            time3 = time;
                        }
                        if (time > time3 + 30000)
                        {
                            chart2.ChartAreas[0].AxisY.Maximum = MAX_X;
                            chart2.ChartAreas[0].AxisY.Minimum = -MAX_X;
                            chart2.ChartAreas[0].AxisY.Interval = MAX_X / 2;
                        }

                        max = Math.Abs(v);
                        if (max > MAX_V)
                        {
                            chart2.ChartAreas[0].AxisY2.Maximum = MAX_V * 2;
                            chart2.ChartAreas[0].AxisY2.Minimum = -MAX_V * 2;
                            chart2.ChartAreas[0].AxisY2.Interval = MAX_V;
                            time4 = time;
                        }
                        if (time > time4 + 30000)
                        {
                            chart2.ChartAreas[0].AxisY2.Maximum = MAX_V;
                            chart2.ChartAreas[0].AxisY2.Minimum = -MAX_V;
                            chart2.ChartAreas[0].AxisY2.Interval = MAX_V / 2;
                        }

                        chart1.Series[0].Points.AddXY(t, theta);
                        chart1.Series[1].Points.AddXY(t, omega);
                        chart2.Series[0].Points.AddXY(t, x);
                        chart2.Series[1].Points.AddXY(t, v);
                        chart3.Series[0].Points.AddXY(t, y1);
                        chart3.Series[1].Points.AddXY(t, y2);
                        chart3.Series[2].Points.AddXY(t, y3);
                        chart3.Series[3].Points.AddXY(t, y4);
                        chart3.Series[4].Points.AddXY(t, y);
                    }));


                    logCsv.write(
                        t.ToString() + "," +
                        theta.ToString("F2") + "," +
                        omega.ToString("F2") + "," +
                        x.ToString("F2") + "," +
                        v.ToString("F2") + "," +
                        y.ToString()
                        );
                }
                catch
                {
                }

                break;

            // 設定値読み出し応答
            case 'l':
                try
                {
                    K1  = Convert.ToInt32(data.Substring(1, 4), 16);
                    K2  = Convert.ToInt32(data.Substring(5, 4), 16);
                    K3  = Convert.ToInt32(data.Substring(9, 4), 16);
                    K4  = Convert.ToInt32(data.Substring(13, 4), 16);
                    Th0 = Convert.ToInt32(data.Substring(17, 4), 16);
                    int on = Convert.ToInt32(data.Substring(21, 2), 16);

                    this.BeginInvoke((Action)(() => {
                        try
                        {
                            trackK1.Value = K1;
                            textK1.Text = K1.ToString();
                            trackK2.Value = K2;
                            textK2.Text = K2.ToString();
                            trackK3.Value = K3;
                            textK3.Text = K3.ToString();
                            trackK4.Value = K4;
                            textK4.Text = K4.ToString();
                            trackTheta0.Value = Th0;
                            textTheta0.Text = ((float)Th0 / 10.0).ToString("F1");
                            if (on == 0x00)
                            {
                                buttonCtrl.Text = "制御ON";
                            }
                            else
                            {
                                buttonCtrl.Text = "制御OFF";
                            }
                        }
                        catch
                        {
                            MessageBox.Show("異常なパラメータがありました");
                        }
                    }));
                }
                catch
                {
                    MessageBox.Show("設定値の読み出しに失敗しました");
                }
                break;
            }
        }
예제 #4
0
        public Form1()
        {
            InitializeComponent();

            rxState = STATE_READY;
            rxPtr   = 0;
            rxBuff  = new char[5000];

            koshiClient = new KoshiClient();
            koshiClientUI.setKoshiClient(koshiClient);
            koshiClient.onConnect      += onConnect;
            koshiClient.onDisconnect   += onDisconnect;
            koshiClient.onUpdateUartRx += onUpdateUartRx;

            K1              = trackK1.Value;
            textK1.Text     = K1.ToString();
            K2              = trackK2.Value;
            textK2.Text     = K2.ToString();
            K3              = trackK3.Value;
            textK3.Text     = K3.ToString();
            K4              = trackK4.Value;
            textK4.Text     = K4.ToString();
            Th0             = trackTheta0.Value;
            textTheta0.Text = ((float)Th0 / 10.0).ToString("F1");

            chart1.ChartAreas[0].Position.X               = 0;
            chart1.ChartAreas[0].Position.Y               = 0;
            chart1.ChartAreas[0].Position.Width           = 85;
            chart1.ChartAreas[0].Position.Height          = 100;
            chart1.ChartAreas[0].InnerPlotPosition.X      = 10;
            chart1.ChartAreas[0].InnerPlotPosition.Y      = 5;
            chart1.ChartAreas[0].InnerPlotPosition.Width  = 80;
            chart1.ChartAreas[0].InnerPlotPosition.Height = 80;
            chart1.Legends[0].Position.X      = 85;
            chart1.Legends[0].Position.Y      = 3;
            chart1.Legends[0].Position.Width  = 15;
            chart1.Legends[0].Position.Height = 50;

            chart2.ChartAreas[0].Position.X               = 0;
            chart2.ChartAreas[0].Position.Y               = 0;
            chart2.ChartAreas[0].Position.Width           = 85;
            chart2.ChartAreas[0].Position.Height          = 100;
            chart2.ChartAreas[0].InnerPlotPosition.X      = 10;
            chart2.ChartAreas[0].InnerPlotPosition.Y      = 5;
            chart2.ChartAreas[0].InnerPlotPosition.Width  = 80;
            chart2.ChartAreas[0].InnerPlotPosition.Height = 80;
            chart2.Legends[0].Position.X      = 85;
            chart2.Legends[0].Position.Y      = 3;
            chart2.Legends[0].Position.Width  = 15;
            chart2.Legends[0].Position.Height = 50;

            chart3.ChartAreas[0].Position.X               = 0;
            chart3.ChartAreas[0].Position.Y               = 0;
            chart3.ChartAreas[0].Position.Width           = 85;
            chart3.ChartAreas[0].Position.Height          = 100;
            chart3.ChartAreas[0].InnerPlotPosition.X      = 10;
            chart3.ChartAreas[0].InnerPlotPosition.Y      = 5;
            chart3.ChartAreas[0].InnerPlotPosition.Width  = 80;
            chart3.ChartAreas[0].InnerPlotPosition.Height = 80;
            chart3.Legends[0].Position.X      = 80;
            chart3.Legends[0].Position.Y      = 3;
            chart3.Legends[0].Position.Width  = 20;
            chart3.Legends[0].Position.Height = 50;

            chart1.Series.Clear();
            chart1.Series.Add("θ");
            chart1.Series.Add("ω");
            chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            chart1.Series[1].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            chart1.Series[0].YAxisType = AxisType.Primary;
            chart1.Series[1].YAxisType = AxisType.Secondary;

            chart2.Series.Clear();
            chart2.Series.Add("x");
            chart2.Series.Add("v");
            chart2.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            chart2.Series[1].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            chart2.Series[0].YAxisType = AxisType.Primary;
            chart2.Series[1].YAxisType = AxisType.Secondary;

            chart3.Series.Clear();
            chart3.Series.Add("K1・θ");
            chart3.Series.Add("K2・ω");
            chart3.Series.Add("K3・x");
            chart3.Series.Add("K4・v");
            chart3.Series.Add("y");
            chart3.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            chart3.Series[1].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            chart3.Series[2].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            chart3.Series[3].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            chart3.Series[4].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;

            chart1.ChartAreas[0].AxisY.Maximum            = MAX_THETA;
            chart1.ChartAreas[0].AxisY.Minimum            = -MAX_THETA;
            chart1.ChartAreas[0].AxisY.Interval           = MAX_THETA / 2;
            chart1.ChartAreas[0].AxisY.LabelStyle.Format  = "F2";
            chart1.ChartAreas[0].AxisY2.Maximum           = MAX_OMEGA;
            chart1.ChartAreas[0].AxisY2.Minimum           = -MAX_OMEGA;
            chart1.ChartAreas[0].AxisY2.Interval          = MAX_OMEGA / 2;
            chart1.ChartAreas[0].AxisY2.LabelStyle.Format = "F1";
            chart2.ChartAreas[0].AxisY.Maximum            = MAX_X;
            chart2.ChartAreas[0].AxisY.Minimum            = -MAX_X;
            chart2.ChartAreas[0].AxisY.Interval           = MAX_X / 2;
            chart2.ChartAreas[0].AxisY.LabelStyle.Format  = "F1";
            chart2.ChartAreas[0].AxisY2.Maximum           = MAX_V;
            chart2.ChartAreas[0].AxisY2.Minimum           = -MAX_V;
            chart2.ChartAreas[0].AxisY2.Interval          = MAX_V / 2;
            chart2.ChartAreas[0].AxisY2.LabelStyle.Format = "F1";
            chart3.ChartAreas[0].AxisY.Maximum            = 128;
            chart3.ChartAreas[0].AxisY.Minimum            = -128;
            chart3.ChartAreas[0].AxisY.Interval           = 32;

            logCsv = new LogCsv();
            logCsv.setHeader("t,theta,omega,x,v,y1,y2,y3,y4,y");

            sw    = System.Diagnostics.Stopwatch.StartNew();
            time  = 0;
            time1 = time2 = time3 = time4 = 0;
        }
예제 #5
0
        private void CheckHealthB_Click(object sender, EventArgs e) // определения состояния здоровья
        {
            vozrast_temp     = Convert.ToInt32(textBox1.Text);      // переменная возраста
            heartbeat_temp   = Convert.ToDouble(textBox3.Text);     // переменная биения сердца в нормальном режиме
            heartbeat_f_temp = Convert.ToDouble(textBox4.Text);


            //подключение к бд
            ConnectionString = @"Data Source = C:\Users\HomePC\Documents\Visual Studio 2015\Projects\DilplomChildDB\DilplomChildDB\bin\Debug\child_db.db; Version = 3 ";
            using (SQLiteConnection con = new SQLiteConnection(ConnectionString))
            {
                SQLiteCommand command = new SQLiteCommand("SELECT Id, Vozrast, Nagruzka FROM Age where [Vozrast] = " + vozrast_temp, con);
                con.Open();

                //поиск возраста
                SQLiteDataReader reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        label16.Text = reader["Nagruzka"].ToString();
                        age_temp     = Convert.ToInt32(reader["Vozrast"]);
                    }
                }
                else
                {
                    label16.Text = "No rows found.";
                }


                ////////////// поиск переменной К1. Поиск идёт через сравнение возрастапеременной возраста
                if (age_temp >= 3 && age_temp <= 5)
                {
                    SQLiteCommand command_02 = new SQLiteCommand("SELECT Id, start, end, K_n_3_5 FROM Age_n_3_5 where (start <= @heartbeat) and (end >= @heartbeat)", con);
                    command_02.Parameters.AddWithValue("@heartbeat", heartbeat_temp);

                    SQLiteDataReader reader_02 = command_02.ExecuteReader();
                    if (reader_02.HasRows)
                    {
                        while (reader_02.Read())
                        {
                            label17.Text = reader_02["K_n_3_5"].ToString();
                            K1           = Convert.ToDouble(label17.Text);
                        }
                    }
                    else
                    {
                        label17.Text = "No rows found.";
                    }
                }
                else
                {
                    if (age_temp >= 6 && age_temp <= 8)
                    {
                        SQLiteCommand command_03 = new SQLiteCommand("SELECT Id, start, end, K_n_6_8 FROM Age_n_6_8 where (start <= @heartbeat) and (end >= @heartbeat)", con);
                        command_03.Parameters.AddWithValue("@heartbeat", heartbeat_temp);

                        SQLiteDataReader reader_03 = command_03.ExecuteReader();
                        if (reader_03.HasRows)
                        {
                            while (reader_03.Read())
                            {
                                label18.Text = reader_03["K_n_6_8"].ToString();
                                K1           = Convert.ToDouble(label18.Text);
                            }
                        }
                        else
                        {
                            label18.Text = "No rows found.";
                        }
                    }
                    else
                    {
                        if (age_temp >= 9 && age_temp <= 11)
                        {
                            SQLiteCommand command_04 = new SQLiteCommand("SELECT Id, start, end, K_n_9_11 FROM Age_n_9_11 where (start <= @heartbeat) and (end >= @heartbeat)", con);
                            command_04.Parameters.AddWithValue("@heartbeat", heartbeat_temp);

                            SQLiteDataReader reader_04 = command_04.ExecuteReader();
                            if (reader_04.HasRows)
                            {
                                while (reader_04.Read())
                                {
                                    label19.Text = reader_04["K_n_9_11"].ToString();
                                    K1           = Convert.ToDouble(label19.Text);
                                }
                            }
                            else
                            {
                                label19.Text = "No rows found.";
                            }
                        }
                        else
                        {
                            if (age_temp >= 12)
                            {
                                SQLiteCommand command_05 = new SQLiteCommand("SELECT Id, start, end, K_n_12_18 FROM Age_n_12_18 where (start <= @heartbeat) and (end >= @heartbeat)", con);
                                command_05.Parameters.AddWithValue("@heartbeat", heartbeat_temp);

                                SQLiteDataReader reader_05 = command_05.ExecuteReader();
                                if (reader_05.HasRows)
                                {
                                    while (reader_05.Read())
                                    {
                                        label20.Text = reader_05["K_n_12_18"].ToString();
                                        K1           = Convert.ToDouble(label20.Text);
                                    }
                                }
                                else
                                {
                                    label20.Text = "No rows found.";
                                }
                            }
                            else
                            {
                                if (age_temp < 3)
                                {
                                    MessageBox.Show("Возраст не должен быть меньше 3 лет!");
                                }
                                else
                                {
                                    return;
                                }
                            }
                        }
                    }
                }
                ///////////////////////////////////поиск переменной К2


                if (age_temp >= 3 && age_temp <= 5)
                {
                    SQLiteCommand command_06 = new SQLiteCommand("SELECT Id, start, end, K_t_3_5 FROM Age_t_3_5 where (start <= @heartbeat) and (end >= @heartbeat)", con);
                    command_06.Parameters.AddWithValue("@heartbeat", heartbeat_f_temp);

                    SQLiteDataReader reader_06 = command_06.ExecuteReader();
                    if (reader_06.HasRows)
                    {
                        while (reader_06.Read())
                        {
                            label21.Text = reader_06["K_t_3_5"].ToString();
                            K2           = Convert.ToDouble(label21.Text);
                        }
                    }
                    else
                    {
                        label21.Text = "No rows found.";
                    }
                }
                else
                {
                    if (age_temp >= 6 && age_temp <= 8)
                    {
                        SQLiteCommand command_07 = new SQLiteCommand("SELECT Id, start, end, K_t_6_8 FROM Age_t_6_8 where (start <= @heartbeat) and (end >= @heartbeat)", con);
                        command_07.Parameters.AddWithValue("@heartbeat", heartbeat_f_temp);

                        SQLiteDataReader reader_07 = command_07.ExecuteReader();
                        if (reader_07.HasRows)
                        {
                            while (reader_07.Read())
                            {
                                label22.Text = reader_07["K_t_6_8"].ToString();
                                K2           = Convert.ToDouble(label22.Text);
                            }
                        }
                        else
                        {
                            label22.Text = "No rows found.";
                        }
                    }
                    else
                    {
                        if (age_temp >= 9 && age_temp <= 11)
                        {
                            SQLiteCommand command_08 = new SQLiteCommand("SELECT Id, start, end, K_t_9_11 FROM Age_t_9_11 where (start <= @heartbeat) and (end >= @heartbeat)", con);
                            command_08.Parameters.AddWithValue("@heartbeat", heartbeat_f_temp);

                            SQLiteDataReader reader_08 = command_08.ExecuteReader();
                            if (reader_08.HasRows)
                            {
                                while (reader_08.Read())
                                {
                                    label23.Text = reader_08["K_t_9_11"].ToString();
                                    K2           = Convert.ToDouble(label23.Text);
                                }
                            }
                            else
                            {
                                label23.Text = "No rows found.";
                            }
                        }
                        else
                        {
                            if (age_temp >= 12)
                            {
                                SQLiteCommand command_09 = new SQLiteCommand("SELECT Id, start, end, K_t_12_18 FROM Age_t_12_18 where (start <= @heartbeat) and (end >= @heartbeat)", con);
                                command_09.Parameters.AddWithValue("@heartbeat", heartbeat_f_temp);

                                SQLiteDataReader reader_09 = command_09.ExecuteReader();
                                if (reader_09.HasRows)
                                {
                                    while (reader_09.Read())
                                    {
                                        label24.Text = reader_09["K_t_12_18"].ToString();
                                        K2           = Convert.ToDouble(label24.Text);
                                    }
                                }
                                else
                                {
                                    label24.Text = "No rows found.";
                                }
                            }
                            else
                            {
                                if (age_temp < 3)
                                {
                                    MessageBox.Show("Возраст не должен быть меньше 3 лет!");
                                }
                                else
                                {
                                    return;
                                }
                            }
                        }
                    }
                }
                ///////////////////////////////////////////////////////


                ///////////////// выбор травмы
                k_travma_s = listBox1.SelectedItem.ToString();

                SQLiteCommand command_10 = new SQLiteCommand("SELECT Id, Travma, K_travma FROM Injury where Travma = @k_travma_s", con);
                command_10.Parameters.AddWithValue("@k_travma_s", k_travma_s);

                SQLiteDataReader reader_10 = command_10.ExecuteReader();
                if (reader_10.HasRows)
                {
                    while (reader_10.Read())
                    {
                        label25.Text = reader_10["K_travma"].ToString();
                        K3           = Convert.ToDouble(label25.Text);
                    }
                }
                else
                {
                    label25.Text = "No rows found.";
                }
                ///////////////////////

                K4           = ((K1 + K2 + K3) / 3); // переменная K4
                K4           = Math.Round(K4, 1);    // округление до одной переменной после запятой
                label26.Text = K4.ToString();
                ///////////////////////////


                SQLiteCommand command_11 = new SQLiteCommand("SELECT Id, K4_start, K4_end, UserText FROM Health where (K4_start <= @k4) and (K4_end >= @k4)", con);
                command_11.Parameters.AddWithValue("@k4", K4);

                SQLiteDataReader reader_11 = command_11.ExecuteReader();
                if (reader_11.HasRows)
                {
                    while (reader_11.Read())
                    {
                        label8.Text = reader_11["UserText"].ToString();
                    }
                }
                else
                {
                    label8.Text = "bug.";
                }
            }
        }