private void timer1_Tick(object sender, EventArgs e)
        {
            float positionVoltageValue;
            float torqueVoltageValue;

            float position = float.Parse(pc.AnalogInput10(0, out positionVoltageValue));
            float troque   = float.Parse(pc.AnalogInput(1, out torqueVoltageValue));


            //if (true)
            //{
            //    position = 1744;
            //    troque = 2862;
            //}


            this.lblPositionValue.Text = positionRawData[ii].ToString();
            this.lblTorqueValue.Text   = torqueRawData[ii].ToString();


            if (ii < positionRawData.Count)
            {
                lpf1.Add(positionRawData[ii]);
                lpf2.Add(torqueRawData[ii]);
            }
            else
            {
                lpf1.Add(positionRawData[0]);
                lpf2.Add(torqueRawData[0]);
            }


            if (lpf1.Count == 900)
            {
                lpf1.Remove(lpf1[0]);
            }

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

            ii++;

            this.pictureBox1.CreateGraphics().DrawImage(dp.drawSignalCurve(lpf1, lpf2), 0, 0);
        }
        private void timer2_Tick(object sender, EventArgs e)
        {
            float positionVoltageValue;
            float torqueVoltageValue;


            float position = float.Parse(pc.AnalogInput10(0, out positionVoltageValue));
            float troque   = float.Parse(pc.AnalogInput10(1, out torqueVoltageValue));

            if (ifStartDebugMode)
            {
                position = 1982;
                troque   = 1111;
            }

            positionForEverySequence[sequenceIndexForExperiment].Add(position);
            torqueForEverySequence[sequenceIndexForExperiment].Add(troque);

            lblShowPosStep3.Text = position.ToString("00.00");
            lblShowTorStep3.Text = troque.ToString("00.00");
            if (trainOrTestUsed[sequenceIndexForExperiment])
            {
                if (rbUpT.Checked)
                {
                    if ((position > 1470 & position < 1982) || (position > 2494 || position < 976))
                    {
                        punishmentByHeat();
                        lblPunishmentStateValue.Text = "True";
                    }
                    else
                    {
                        unPunishmentByHeat();
                        lblPunishmentStateValue.Text = "False";
                    }
                }
                else
                {
                    if ((position > 1470 & position < 1982) || (position > 2494 || position < 976))
                    {
                        unPunishmentByHeat();
                        lblPunishmentStateValue.Text = "False";
                    }
                    else
                    {
                        punishmentByHeat();
                        lblPunishmentStateValue.Text = "True";
                    }
                }
            }
            else
            {
                unPunishmentByHeat();
                lblPunishmentStateValue.Text = "False";
            }

            timeIndex++;
            if (timeIndex == experimentTimeUsed[sequenceIndexForExperiment] * 10)
            {
                timeIndex = 0;
                sequenceIndexForExperiment++;
                dp2.clearCommunitivePosition();
                lpf3.Clear();
                lpf4.Clear();
                if (sequenceIndexForExperiment == experimentTimeUsed.Count)
                {
                    timer2.Stop();
                    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;
                }



                PICalc pic     = new PICalc(positionForEverySequence[sequenceIndexForExperiment - 1], torqueForEverySequence[sequenceIndexForExperiment - 1], rbUpT.Checked);
                float  piValue = pic.getSiglePIValue();


                Bitmap     imageHere = new Bitmap(imageNow);
                PictureBox pb        = new PictureBox();
                float      width     = this.flpBottomForImageList.Size.Width - 30;
                float      height    = (int)(((float)this.pictureBox3.Size.Height / (float)this.pictureBox3.Size.Width) * width);
                pb.Size = new Size((int)width, (int)height);
                Graphics g = Graphics.FromImage(imageHere);
                g.DrawString("PIValue: " + piValue.ToString(), new Font("Arial", 15), new SolidBrush(Color.LightGray), 130, 20);
                pb.Image    = imageHere;
                pb.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;

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



            ////debug mode
            //   position = 721;
            //   troque = 100;



            lpf3.Add(position);
            lpf4.Add(troque);
            if (lpf3.Count == 300)
            {
                lpf3.Remove(lpf3[0]);
            }

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



            this.pictureBox2.CreateGraphics().DrawImage(dp1.drawSignalCurve(lpf3, lpf4), 0, 0);
            imageNow = dp2.drawCommunitivePoint(position, ifStartDebugMode, sequenceIndexForExperiment);
            this.pictureBox3.CreateGraphics().DrawImage(imageNow, 0, 0);
            if (sequenceIndexForExperiment == 7 & ifBreakTime)
            {
                timer2.Stop();
                ifBreakTime        = false;
                btnReStart.Visible = true;
            }
        }
Пример #3
0
        private void timer2_Tick(object sender, EventArgs e)
        {
            float positionVoltageValue;
            float torqueVoltageValue;

            float position = float.Parse(pc.AnalogInput10(0, out positionVoltageValue));
            float troque   = float.Parse(pc.AnalogInput(1, out torqueVoltageValue));

            positionForEverySequence[sequenceIndexForExperiment].Add(position);
            torqueForEverySequence[sequenceIndexForExperiment].Add(troque);


            if (trainOrTestUsed[sequenceIndexForExperiment])
            {
                if (rbUpT.Checked)
                {
                    if ((position > 1488 & position < 2000) || (position > 2516 || position < 976))
                    {
                        punishmentByHeat();
                        lblPunishmentStateValue.Text = "True";
                    }
                    else
                    {
                        unPunishmentByHeat();
                        lblPunishmentStateValue.Text = "False";
                    }
                }
                else
                {
                    if ((position > 1488 & position < 2000) || (position > 2516 || position < 976))
                    {
                        unPunishmentByHeat();
                        lblPunishmentStateValue.Text = "False";
                    }
                    else
                    {
                        punishmentByHeat();
                        lblPunishmentStateValue.Text = "True";
                    }
                }
            }
            else
            {
                unPunishmentByHeat();
                lblPunishmentStateValue.Text = "False";
            }

            timeIndex++;
            if (timeIndex == experimentTimeUsed[sequenceIndexForExperiment] * 10)
            {
                timeIndex = 0;
                sequenceIndexForExperiment++;
                dp2.clearCommunitivePosition();
                lpf3.Clear();
                lpf4.Clear();
                if (sequenceIndexForExperiment == experimentTimeUsed.Count)
                {
                    timer2.Stop();
                    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;
                }



                Bitmap     imageHere = new Bitmap(imageNow);
                PictureBox pb        = new PictureBox();
                float      width     = this.flpBottomForImageList.Size.Width - 30;
                float      height    = (int)(((float)this.pictureBox3.Size.Height / (float)this.pictureBox3.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);
            }



            ////debug mode
            //   position = 721;
            //   troque = 100;



            lpf3.Add(position);
            lpf4.Add(troque);
            if (lpf3.Count == 150)
            {
                lpf3.Remove(lpf3[0]);
            }

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



            this.pictureBox2.CreateGraphics().DrawImage(dp1.drawSignalCurve(lpf3, lpf4), 0, 0);
            imageNow = dp2.drawCommunitivePoint(position, ifStartDebugMode, sequenceIndexForExperiment);
            this.pictureBox3.CreateGraphics().DrawImage(imageNow, 0, 0);
        }