private void timer2_Tick(object sender, EventArgs e) { 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; settingDegree += 1.8f * oritation; if (settingDegree >= 135) { oritation = -1; } if (settingDegree <= -135) { oritation = 1; } this.lblPositionValue.Text = settingDegree.ToString(); this.lblTorqueValue.Text = troque.ToString(); this.lblTroqueTransValue.Text = troque_trans.ToString(); lpf1.Add(settingDegree); 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); this.vf.pbCanvas.CreateGraphics().DrawImage(vf.getImage(settingDegree), 0, 0); this.vf.simpleOpenGlControl1.Refresh(); sw.Stop(); TimeSpan ts = sw.Elapsed; this.lblDebugTime.Text = ts.Milliseconds.ToString(); }
private void timer2_Tick(object sender, EventArgs e) { float torqueVoltageValue; float troque = float.Parse(pc.AnalogInput(1, out torqueVoltageValue)); //troque = troque / 100; troque_trans = (troque - 2048) / 2048 * 80; this.lblPositionValue.Text = degree.ToString(); this.lblTorqueValue.Text = troque.ToString(); this.lblTroqueTransValue.Text = troque_trans.ToString(); 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); }
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)); //this.label1.Text = torqueVoltageValue.ToString("00.00"); float position = cc.getPositionSignal(); float troque = cc.getTorqueSignal(); if (ifStartDebugMode) { position = 1744; troque = 2862; } this.lblPositionValue.Text = position.ToString(); this.lblTorqueValue.Text = troque.ToString(); this.pictureBox1.CreateGraphics().DrawImage(dp.drawSignalCurve(lpf1, lpf2), 0, 0); }
private void timer1_Tick(object sender, EventArgs e) { float position = cc.getPositionSignal(); float troque = cc.getTorqueSignal(); if (ifStartDebugMode) { position = 1982; troque = 0; } this.lblPositionValue.Text = position.ToString(); this.lblTorqueValue.Text = troque.ToString(); lpf1.Add(position); lpf2.Add(troque); if (lpf1.Count == 300) { lpf1.Remove(lpf1[0]); } if (lpf2.Count == 300) { lpf2.Remove(lpf2[0]); } this.pictureBox1.CreateGraphics().DrawImage(dp.drawSignalCurve(lpf1, lpf2), 0, 0); }
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 timer1_Tick(object sender, EventArgs e) { position = float.Parse(pc.AnalogInput(0, out positionVoltageValue)); troque = float.Parse(pc.AnalogInput(1, out torqueVoltageValue)); tacho = float.Parse(pc.AnalogInput(2, out tachoVoltageValue)); if (ifStartDebugMode) { position = position / 100; troque = troque / 100; } this.lblPosition.Text = position.ToString(); this.lblTorque.Text = troque.ToString(); this.lblTacho.Text = tacho.ToString(); this.lblPositionVoltageValue.Text = positionVoltageValue.ToString("0.000"); this.lblTorqueVoltageValue.Text = torqueVoltageValue.ToString("0.000"); this.lblTachoVoltageValue.Text = tachoVoltageValue.ToString("0.000"); lpf1.Add(position); lpf2.Add(troque); if (lpf1.Count == 300) { lpf1.Remove(lpf1[0]); } if (lpf2.Count == 300) { lpf2.Remove(lpf2[0]); } this.CreateGraphics().DrawImage(dpl.drawSignalCurve(lpf1, lpf2), 540, 60); this.CreateGraphics().DrawImage(dpl.drawPosition(troque), 540, 420); }
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); } } }
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; } }
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(); } } }
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); }