private void btnTestDrawing_Click(object sender, EventArgs e)
        {
            lblChooseDisplay.Visible = true;
            cbIsPosition.Visible     = true;
            cbIsTorque.Visible       = true;

            dp = new drawProcess(this.pictureBox1.Size.Width, this.pictureBox1.Size.Height, Color.DarkCyan);

            timer1.Interval = 100;
            timer1.Start();
        }
Ejemplo n.º 2
0
        private void btnTestDrawing_Click(object sender, EventArgs e)
        {
            lblChooseDisplay.Visible = true;
            cbIsPosition.Visible     = true;
            cbIsTorque.Visible       = true;

            dp = new drawProcess(this.pictureBox1.Size.Width, this.pictureBox1.Size.Height, Color.DarkCyan);
            this.timer1.Start();

            //this.pictureBox1.CreateGraphics().DrawImage(dp.drawTest(), 0, 0);
        }
        private void btnRecorectBias_Click(object sender, EventArgs e)
        {
            timer2.Stop();
            lblChooseDisplay.Visible = true;
            cbIsPosition.Visible     = true;
            cbIsTorque.Visible       = true;


            dp1 = new drawProcess(this.pictureBox1.Width, this.pictureBox1.Height, Color.DarkCyan);

            timer3.Interval = 50;
            timer3.Start();
        }
        private void btnTestDrawing_Click(object sender, EventArgs e)
        {
            lblChooseDisplay.Visible = true;
            cbIsPosition.Visible     = true;
            cbIsTorque.Visible       = true;

            dp = new drawProcess(this.pictureBox1.Size.Width, this.pictureBox1.Size.Height, Color.DarkCyan);
            this.timer1.Start();



            positionRawData = getRawData("dataPosition.txt");
            torqueRawData   = getRawData("dataTorque.txt");
            MessageBox.Show("finished");
        }
Ejemplo n.º 5
0
        private void btnStep3Start_Click(object sender, EventArgs e)
        {
            lblChooseDisplay.Visible = true;
            cbIsPosition.Visible     = true;
            cbIsTorque.Visible       = true;

            //vSti = new Stimulations(v.pictureBox1.Width, v.pictureBox1.Height, 1);

            timeBeginPeriod(1);
            uint start = timeGetTime();
            uint newStart;
            int  count = 0;
            int  i = 0, j = 0;

            ifStop = false;

            dp1 = new drawProcess(this.pbPosition.Width, this.pbPosition.Height, Color.DarkCyan);
            dp2 = new drawProcess(this.pbCommunitive.Width, this.pbCommunitive.Height, Color.DarkCyan);

            lpf3.Clear();
            lpf4.Clear();
            positionForEverySequence.Clear();
            torqueForEverySequence.Clear();
            RightOrLeftForEverySequence.Clear();

            sequenceIndexForExperiment = 0;
            this.flpTopForLabel.Controls.Clear();
            this.flpBottomForImageList.Controls.Clear();
            int controlsLength;

            if (cbSetSeqChoosed_1.Checked)
            {
                controlsLength     = trainOrTest_1.Count;
                trainOrTestUsed    = trainOrTest_1;
                experimentTimeUsed = experimentTime_1;
            }
            else if (cbSetSeqChoosed_2.Checked)
            {
                controlsLength     = trainOrTest_2.Count;
                trainOrTestUsed    = trainOrTest_2;
                experimentTimeUsed = experimentTime_2;
            }
            else
            {
                controlsLength     = trainOrTest_3.Count;
                trainOrTestUsed    = trainOrTest_3;
                experimentTimeUsed = experimentTime_3;
            }


            dp1.getTrainOrTestSequence(trainOrTestUsed);
            dp2.getTrainOrTestSequence(trainOrTestUsed);

            controls = new List <Control>();
            for (int ii = 0; ii < controlsLength; ii++)
            {
                Label l = new Label();
                l.Name        = "lblDForSequence" + i.ToString();
                l.AutoSize    = true;
                l.BorderStyle = BorderStyle.FixedSingle;
                l.Margin      = new System.Windows.Forms.Padding(3);
                l.Font        = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                if (trainOrTestUsed[i] == true)
                {
                    l.Text = "Tr: " + experimentTimeUsed[i].ToString();
                }
                else
                {
                    l.Text = "Te: " + experimentTimeUsed[i].ToString();
                }
                controls.Add(l);

                this.flpTopForLabel.Controls.Add(l);
            }
            controls[0].BackColor = Color.DarkCyan;

            positionForEverySequence.Add(new List <float>());
            torqueForEverySequence.Add(new List <float>());
            RightOrLeftForEverySequence.Add(new List <int>());

            this.btnStep3Start.Enabled = false;


            while (!ifStop)
            {
                Application.DoEvents();
                newStart = timeGetTime();

                if (newStart - start >= 100)
                {
                    float torqueVoltageValue;
                    float troque = float.Parse(pc.AnalogInput(1, out torqueVoltageValue));
                    //troque = troque / 100;
                    troque_trans = (troque - 2048) / 2048 * 80;


                    //debug mode
                    //troque_trans = 10;

                    count++;
                    start = newStart;

                    //Wert = p1_c1 * p1_c2 * trq + p1_c3 * p1_c4 * p1_bias_  'p1_c1=0/1 (open closed); p1_c2=+1/-1 (norm/inverted); p1_c3=0/1 (p1_bias on/off); p1_c4=+1/-1 (cw/ccw)
                    //dPsi1 = p1_k * Wert * dt_
                    //ArenaPos1 = ArenaPos1 + dPsi1


                    degree = v.getDegree();
                    this.lblEXPStateP.Text    = degree.ToString();
                    this.lblEXPStateTRaw.Text = troque.ToString();
                    this.lblEXPSTateT.Text    = troque_trans.ToString();


                    //debug mode
                    //degree += 1;

                    if (degree > 180)
                    {
                        degree = degree - 360;
                    }
                    if (degree < -180)
                    {
                        degree = degree + 360;
                    }


                    lpf3.Add(degree);
                    lpf4.Add(troque_trans);
                    //Console.WriteLine(degree);
                    positionForEverySequence[sequenceIndexForExperiment].Add(degree);
                    torqueForEverySequence[sequenceIndexForExperiment].Add(troque_trans);
                    if (v.getRightOrLeft())
                    {
                        RightOrLeftForEverySequence[sequenceIndexForExperiment].Add(1);
                    }
                    else
                    {
                        RightOrLeftForEverySequence[sequenceIndexForExperiment].Add(0);
                    }

                    if (trainOrTestUsed[sequenceIndexForExperiment])
                    {
                        if (rbUpT.Checked)
                        {
                            if ((degree > -45 & degree < 45) || (degree < -135 & degree > 135))
                            {
                                punishmentByHeat();
                                lblPunishmentStateValue.Text = "True";
                            }
                            else
                            {
                                unPunishmentByHeat();
                                lblPunishmentStateValue.Text = "False";
                            }
                        }
                        else
                        {
                            if ((degree <-45 & degree> -135) || (degree > 45 || degree < 135))
                            {
                                unPunishmentByHeat();
                                lblPunishmentStateValue.Text = "False";
                            }
                            else
                            {
                                punishmentByHeat();
                                lblPunishmentStateValue.Text = "True";
                            }
                        }
                    }



                    if (count == experimentTimeUsed[sequenceIndexForExperiment] * 10)
                    {
                        count = 0;
                        sequenceIndexForExperiment++;
                        dp2.clearCommunitivePosition();
                        lpf3.Clear();
                        lpf4.Clear();
                        if (sequenceIndexForExperiment == experimentTimeUsed.Count)
                        {
                            ifStop = true;
                            this.btnStep3Start.Enabled = true;
                            pc.ClearALLDigitalPort();
                            //OpenLoop();
                            cbOpenOrClosed.Checked = false;
                            cbOpenOrClosed.Text    = "Open";
                            DataSave();
                        }
                        else
                        {
                            positionForEverySequence.Add(new List <float>());
                            torqueForEverySequence.Add(new List <float>());
                            RightOrLeftForEverySequence.Add(new List <int>());
                            controls[sequenceIndexForExperiment].BackColor = Color.DarkCyan;
                        }



                        Bitmap   imageHere = new Bitmap(imageNow);
                        Graphics g1        = Graphics.FromImage(imageHere);

                        PICalc piC        = new PICalc(positionForEverySequence[sequenceIndexForExperiment - 1], torqueForEverySequence[sequenceIndexForExperiment - 1], rbUpT.Checked ? true : false);
                        float  PIValueNow = piC.getSinglePIValue();
                        g1.DrawString("PI: " + (PIValueNow).ToString("0.00"), new Font("Arial", 15), new SolidBrush(Color.LightGray), 30, 50);
                        PictureBox pb     = new PictureBox();
                        float      width  = this.flpBottomForImageList.Size.Width - 30;
                        float      height = (int)(((float)this.pbCommunitive.Size.Height / (float)this.pbCommunitive.Size.Width) * width);
                        pb.Size = new Size((int)width, (int)height);

                        pb.Image    = imageHere;
                        pb.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;

                        this.flpBottomForImageList.Controls.Add(pb);
                    }


                    //this.pictureBox2.CreateGraphics().DrawImage(dp1.drawSignalCurve(lpf3, lpf4), 0, 0);

                    if (lpf3.Count == 400)
                    {
                        lpf3.Remove(lpf3[0]);
                    }

                    if (lpf4.Count == 400)
                    {
                        lpf4.Remove(lpf4[0]);
                    }

                    this.pbPosition.CreateGraphics().DrawImage(dp1.drawSignalCurve(lpf3, lpf4), 0, 0);
                    imageNow = dp2.drawCommunitivePoint(degree, false, sequenceIndexForExperiment);
                    this.pbCommunitive.CreateGraphics().DrawImage(imageNow, 0, 0);
                }
            }
        }
Ejemplo n.º 6
0
        private void btnTestDrawing_Click(object sender, EventArgs e)
        {
            lblChooseDisplay.Visible = true;
            cbIsPosition.Visible     = true;
            cbIsTorque.Visible       = true;

            vSti = new Stimulations(v.pictureBox1.Width, v.pictureBox1.Height, 1);



            dp1 = new drawProcess(this.pictureBox1.Width, this.pictureBox1.Height, Color.DarkCyan);

            timer2.Start();
            //while (!ifStop)
            //{
            //    Application.DoEvents();
            //    newStart = timeGetTime();

            //    if (newStart - start >= 100)
            //    {


            //        if (isOpenCircle)
            //        {
            //            degree += degree;
            //        }
            //        float torqueVoltageValue;
            //        float troque = float.Parse(pc.AnalogInput(1, out torqueVoltageValue));
            //        troque = troque / 100;
            //        troque_trans = (troque - 2048) / 2048 * 80;


            //        debug mode
            //        troque_trans = 10;

            //        count++;
            //        start = newStart;

            //        Wert = p1_c1 * p1_c2 * trq + p1_c3 * p1_c4 * p1_bias_  'p1_c1=0/1 (open closed); p1_c2=+1/-1 (norm/inverted); p1_c3=0/1 (p1_bias on/off); p1_c4=+1/-1 (cw/ccw)
            //        dPsi1 = p1_k * Wert * dt_
            //        ArenaPos1 = ArenaPos1 + dPsi1


            //        float k = float.Parse(tbKValue.Text);
            //        degree += troque_trans * k * 0.01f;
            //        this.lblPositionValue.Text = degree.ToString();
            //        this.lblTorqueValue.Text = troque.ToString();
            //        this.lblTroqueTransValue.Text = troque_trans.ToString();

            //        if (degree > 180)
            //        {
            //            degree = degree - 360;
            //        }
            //        if (degree < -180)
            //        {
            //            degree = degree + 360;
            //        }
            //        v.pictureBox1.CreateGraphics().DrawImage(vSti.DrawV_Test(degree), 0, 0);

            //        lpf1.Add(degree);
            //        lpf2.Add(troque_trans);

            //        lpf1.Add(180);
            //        lpf2.Add(10);
            //        if (lpf1.Count == 400)
            //        {
            //            lpf1.Remove(lpf1[0]);
            //        }

            //        if (lpf2.Count == 400)
            //        {
            //            lpf2.Remove(lpf2[0]);
            //        }

            //        this.pictureBox1.CreateGraphics().DrawImage(dp1.drawSignalCurve(lpf1, lpf2), 0, 0);


            //    }

            //    if (count == 20000)
            //    {
            //        ifStop = true;
            //        break;
            //    }



            //}

            //this.pictureBox1.CreateGraphics().DrawImage(dp.drawTest(), 0, 0);
        }
        private void btnStep3Start_Click(object sender, EventArgs e)
        {
            dp1 = new drawProcess(this.pictureBox2.Width, this.pictureBox2.Height, Color.DarkCyan);
            dp2 = new drawProcess(this.pictureBox3.Width, this.pictureBox3.Height, Color.DarkCyan);
            //for (int i = 0; i < 6; i++)
            //{
            //    if (i % 2 == 0)
            //    {
            //        trainOrTestForTest.Add(true);
            //    }
            //    else
            //    {
            //        trainOrTestForTest.Add(false);
            //    }

            //    experimentTimeForTest.Add(300);


            //}

            if (tbExperimentName.Text == "")
            {
                MessageBox.Show("ExpName is NULL");
            }
            else
            {
                lpf3.Clear();
                lpf4.Clear();
                positionForEverySequence.Clear();
                torqueForEverySequence.Clear();
                sequenceIndexForExperiment = 0;
                this.flpTopForLabel.Controls.Clear();
                this.flpBottomForImageList.Controls.Clear();
                int controlsLength;
                if (cbSetSeqChoosed_1.Checked)
                {
                    controlsLength     = trainOrTest_1.Count;
                    trainOrTestUsed    = trainOrTest_1;
                    experimentTimeUsed = experimentTime_1;
                }
                else if (cbSetSeqChoosed_2.Checked)
                {
                    controlsLength     = trainOrTest_2.Count;
                    trainOrTestUsed    = trainOrTest_2;
                    experimentTimeUsed = experimentTime_2;
                }
                else
                {
                    controlsLength     = trainOrTest_3.Count;
                    trainOrTestUsed    = trainOrTest_3;
                    experimentTimeUsed = experimentTime_3;
                }


                dp1.getTrainOrTestSequence(trainOrTestUsed);
                dp2.getTrainOrTestSequence(trainOrTestUsed);

                controls = new List <Control>();
                for (int i = 0; i < controlsLength; i++)
                {
                    Label l = new Label();
                    l.Name        = "lblDForSequence" + i.ToString();
                    l.AutoSize    = true;
                    l.BorderStyle = BorderStyle.FixedSingle;
                    l.Margin      = new System.Windows.Forms.Padding(3);
                    l.Font        = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                    if (trainOrTestUsed[i] == true)
                    {
                        l.Text = "Tr: " + experimentTimeUsed[i].ToString();
                    }
                    else
                    {
                        l.Text = "Te: " + experimentTimeUsed[i].ToString();
                    }
                    controls.Add(l);

                    this.flpTopForLabel.Controls.Add(l);
                }
                controls[0].BackColor = Color.DarkCyan;

                positionForEverySequence.Add(new List <float>());
                torqueForEverySequence.Add(new List <float>());
                ifBreakTime = true;
                timer2.Start();
                timer1.Stop();
                this.btnStep3Start.Enabled = false;
            }
        }
        private void btnStep3Start_Click(object sender, EventArgs e)
        {
            lblChooseDisplay.Visible = true;
            cbIsPosition.Visible     = true;
            cbIsTorque.Visible       = true;

            //vSti = new Stimulations(v.pictureBox1.Width, v.pictureBox1.Height, 1);

            timeBeginPeriod(1);
            uint start = timeGetTime();
            uint newStart;
            int  count = 0;
            int  i = 0, j = 0;

            ifStop = false;

            dp1 = new drawProcess(this.pbPosition.Width, this.pbPosition.Height, Color.DarkCyan);
            //dp2 = new drawProcess(this.pbCommunitive.Width, this.pbCommunitive.Height, Color.DarkCyan);

            lpf3.Clear();
            lpf4.Clear();
            positionForEverySequence.Clear();
            torqueForEverySequence.Clear();
            sequenceIndexForExperiment = 0;
            //this.flpTopForLabel.Controls.Clear();
            //this.flpBottomForImageList.Controls.Clear();
            int controlsLength;

            if (cbSetSeqChoosed_1.Checked)
            {
                controlsLength     = trainOrTest_1.Count;
                trainOrTestUsed    = trainOrTest_1;
                experimentTimeUsed = experimentTime_1;
            }
            else if (cbSetSeqChoosed_2.Checked)
            {
                controlsLength     = trainOrTest_2.Count;
                trainOrTestUsed    = trainOrTest_2;
                experimentTimeUsed = experimentTime_2;
            }
            else
            {
                controlsLength     = trainOrTest_3.Count;
                trainOrTestUsed    = trainOrTest_3;
                experimentTimeUsed = experimentTime_3;
            }


            dp1.getTrainOrTestSequence(trainOrTestUsed);
            //dp2.getTrainOrTestSequence(trainOrTestUsed);

            //controls = new List<Control>();
            //for (int ii = 0; ii < controlsLength; ii++)
            //{
            //    Label l = new Label();
            //    l.Name = "lblDForSequence" + i.ToString();
            //    l.AutoSize = true;
            //    l.BorderStyle = BorderStyle.FixedSingle;
            //    l.Margin = new System.Windows.Forms.Padding(3);
            //    l.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            //    if (trainOrTestUsed[i] == true)
            //    {
            //        l.Text = "Tr: " + experimentTimeUsed[i].ToString();
            //    }
            //    else
            //    {
            //        l.Text = "Te: " + experimentTimeUsed[i].ToString();
            //    }
            //    controls.Add(l);

            //    this.flpTopForLabel.Controls.Add(l);
            //}
            //controls[0].BackColor = Color.DarkCyan;

            positionForEverySequence.Add(new List <float>());
            torqueForEverySequence.Add(new List <float>());


            this.btnStep3Start.Enabled = false;

            float settingDegree = -135;

            oritation = 1;
            vf.SetRandomPoint();



            while (!ifStop)
            {
                Application.DoEvents();
                newStart = timeGetTime();

                if (newStart - start >= 50)
                {
                    sw = new System.Diagnostics.Stopwatch();
                    sw.Start();
                    float torqueVoltageValue;
                    float troque = float.Parse(pc.AnalogInput(1, out torqueVoltageValue));
                    //troque = troque / 100;
                    troque_trans = (troque - 2048) / 2048 * 80;


                    //debug mode
                    //troque_trans = 10;

                    count++;
                    start = newStart;

                    //Wert = p1_c1 * p1_c2 * trq + p1_c3 * p1_c4 * p1_bias_  'p1_c1=0/1 (open closed); p1_c2=+1/-1 (norm/inverted); p1_c3=0/1 (p1_bias on/off); p1_c4=+1/-1 (cw/ccw)
                    //dPsi1 = p1_k * Wert * dt_
                    //ArenaPos1 = ArenaPos1 + dPsi1



                    settingDegree += 1.8f * oritation;
                    if (settingDegree >= 135)
                    {
                        oritation = -1;
                    }
                    if (settingDegree <= -135)
                    {
                        oritation = 1;
                    }


                    this.lblEXPStateP.Text    = settingDegree.ToString();
                    this.lblEXPStateTRaw.Text = troque.ToString();
                    this.lblEXPSTateT.Text    = troque_trans.ToString();


                    //debug mode
                    //degree += 1;


                    //v.pictureBox1.CreateGraphics().DrawImage(vSti.DrawV_Test(degree), 0, 0);

                    lpf3.Add(settingDegree);
                    lpf4.Add(troque_trans);
                    //Console.WriteLine(degree);
                    positionForEverySequence[sequenceIndexForExperiment].Add(settingDegree);
                    torqueForEverySequence[sequenceIndexForExperiment].Add(troque_trans);



                    if (count == experimentTimeUsed[sequenceIndexForExperiment] * 20)
                    {
                        count = 0;
                        sequenceIndexForExperiment++;
                        //dp2.clearCommunitivePosition();
                        lpf3.Clear();
                        lpf4.Clear();
                        settingDegree = -135;
                        oritation     = 1;
                        if (sequenceIndexForExperiment == experimentTimeUsed.Count)
                        {
                            ifStop = true;
                            this.btnStep3Start.Enabled = true;
                            pc.ClearALLDigitalPort();
                            //OpenLoop();
                            cbOpenOrClosed.Checked = false;
                            cbOpenOrClosed.Text    = "Open";
                            DataSave();
                        }
                        else
                        {
                            positionForEverySequence.Add(new List <float>());
                            torqueForEverySequence.Add(new List <float>());
                            //controls[sequenceIndexForExperiment].BackColor = Color.DarkCyan;
                        }
                    }


                    //this.pictureBox2.CreateGraphics().DrawImage(dp1.drawSignalCurve(lpf3, lpf4), 0, 0);

                    if (lpf3.Count == 400)
                    {
                        lpf3.Remove(lpf3[0]);
                    }

                    if (lpf4.Count == 400)
                    {
                        lpf4.Remove(lpf4[0]);
                    }

                    this.pbPosition.CreateGraphics().DrawImage(dp1.drawSignalCurve(lpf3, lpf4), 0, 0);
                    //imageNow = dp2.drawCommunitivePoint(degree, false,sequenceIndexForExperiment);
                    //this.pbCommunitive.CreateGraphics().DrawImage(imageNow, 0, 0);
                    this.vf.pbCanvas.CreateGraphics().DrawImage(vf.getImage(settingDegree), 0, 0);
                    this.vf.simpleOpenGlControl1.Refresh();

                    sw.Stop();
                    TimeSpan ts = sw.Elapsed;
                    this.lblShowFrameTime.Text = ts.Milliseconds.ToString();
                }
            }
        }