实例介绍
【实例截图】
【文件目录】
│ MoveRobot.sln
│
└─MoveRobot
│ App.config
│ CoordinateTransformation.cs
│ Form1.cs
│ Form1.Designer.cs
│ Form1.resx
│ Form2.cs
│ Form2.Designer.cs
│ Form2.resx
│ MoveRobot.csproj
│ Program.cs
│ Public.cs
│
├─bin
│ └─Debug
│ ABB.Robotics.Controllers.PC.dll
│ ABB.Robotics.Controllers.PC.xml
│ MoveRobot.exe
│ MoveRobot.exe.config
│ MoveRobot.pdb
│ MoveRobot.vshost.exe
│ MoveRobot.vshost.exe.config
│ MoveRobot.vshost.exe.manifest
│ RobotStudio.Services.RobApi.Desktop.dll
│ RobotStudio.Services.RobApi.dll
│
├─Image
│ Industrial_robot_64px_532261_easyicon.net.ico
│ MainForm.ico
│ 机器人回原点.ico
│ 机器人运动.ico
│ 记录点的信息.ico
│
├─obj
│ └─Debug
│ │ DesignTimeResolveAssemblyReferences.cache
│ │ DesignTimeResolveAssemblyReferencesInput.cache
│ │ Interop.MSComctlLib.dll
│ │ MoveRobot.csproj.FileListAbsolute.txt
│ │ MoveRobot.csproj.GenerateResource.Cache
│ │ MoveRobot.csproj.ResolveComReference.cache
│ │ MoveRobot.csprojAssemblyReference.cache
│ │ MoveRobot.csprojResolveAssemblyReference.cache
│ │ MoveRobot.exe
│ │ MoveRobot.MianForm.resources
│ │ MoveRobot.pdb
│ │ MoveRobot.PointnameForm.resources
│ │ MoveRobot.Properties.Resources.resources
│ │ TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ │
│ └─TempPE
└─Properties
AssemblyInfo.cs
Resources.Designer.cs
Resources.resx
Settings.Designer.cs
Settings.settings
【核心代码】
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ABB.Robotics.Controllers; using ABB.Robotics.Controllers.Discovery; using ABB.Robotics.Controllers.MotionDomain; using ABB.Robotics.Controllers.RapidDomain; using System.Diagnostics; namespace MoveRobot { public partial class MianForm : Form { public MianForm() { InitializeComponent(); bool b = IsProcessStarted("RobotStudio"); if (b) { NetworkScanner ns = new NetworkScanner(); ns.Scan(); Public.ctr = new Controller(ns.Controllers[0]); Public.ctr.Logon(UserInfo.DefaultUser); } else { //弹出对话框选择工作站,当选择好工作站后打开所选工作站 if (openABBFile.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Process.Start(System.IO.Path.GetFullPath(openABBFile.FileName)); } System.Threading.Thread.Sleep(20000);//程序等待20s以便robotstudio打开 NetworkScanner ns = new NetworkScanner(); ns.Scan(); Public.ctr = new Controller(ns.Controllers[0]); Public.ctr.Logon(UserInfo.DefaultUser); } } /// <summary> /// 判断robotstudio软件是否打开 /// </summary> /// <param name="processName"></param> /// <returns></returns> private bool IsProcessStarted(string processName) { Process[] temp = Process.GetProcessesByName(processName); if (temp.Length > 0) return true; else return false; } #region 单个轴运动控制 /// <summary> /// 轴1移动 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAxis1_Click(object sender, EventArgs e) { MechanicalUnitCollection aMechCol = Public.ctr.MotionSystem.MechanicalUnits; JointTarget targetR = aMechCol[0].GetPosition(); JointTarget targetG = aMechCol[1].GetPosition(); targetR.ExtAx.Eax_a = targetG.ExtAx.Eax_a; targetR.RobAx.Rax_1 = float.Parse(txtAngle.Text); //判断轴度数是否超出范围 if (targetR.RobAx.Rax_1 < -180) { targetR.RobAx.Rax_1 = -180; } else if (targetR.RobAx.Rax_1 > 180) { targetR.RobAx.Rax_1 = 180; } targetR = MoveAxis(targetR); } /// <summary> /// 轴2移动 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAxis2_Click(object sender, EventArgs e) { MechanicalUnitCollection aMechCol = Public.ctr.MotionSystem.MechanicalUnits; JointTarget targetR = aMechCol[0].GetPosition(); JointTarget targetG = aMechCol[1].GetPosition(); targetR.RobAx.Rax_2 = float.Parse(txtAngle.Text); targetR.ExtAx.Eax_a = targetG.ExtAx.Eax_a; //判断轴度数是否超出范围 if (targetR.RobAx.Rax_2 < -90) { targetR.RobAx.Rax_2 = -90; } else if (targetR.RobAx.Rax_2 > 150) { targetR.RobAx.Rax_2 = 150; } targetR = MoveAxis(targetR); } /// <summary> /// 移动轴3 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAxis3_Click(object sender, EventArgs e) { MechanicalUnitCollection aMechCol = Public.ctr.MotionSystem.MechanicalUnits; JointTarget targetR = aMechCol[0].GetPosition(); JointTarget targetG = aMechCol[1].GetPosition(); targetR.RobAx.Rax_3 = float.Parse(txtAngle.Text); targetR.ExtAx.Eax_a = targetG.ExtAx.Eax_a; //判断轴度数是否超出范围 if (targetR.RobAx.Rax_3 < -180) { targetR.RobAx.Rax_3 = -180; } else if (targetR.RobAx.Rax_3 > 75) { targetR.RobAx.Rax_3 = 75; } targetR = MoveAxis(targetR); } /// <summary> /// 移动轴4 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAxis4_Click(object sender, EventArgs e) { MechanicalUnitCollection aMechCol = Public.ctr.MotionSystem.MechanicalUnits; JointTarget targetR = aMechCol[0].GetPosition(); JointTarget targetG = aMechCol[1].GetPosition(); targetR.RobAx.Rax_4 = float.Parse(txtAngle.Text); targetR.ExtAx.Eax_a = targetG.ExtAx.Eax_a; //判断轴度数是否超出范围 if (targetR.RobAx.Rax_4 < -400) { targetR.RobAx.Rax_4 = -400; } else if (targetR.RobAx.Rax_4 > 400) { targetR.RobAx.Rax_4 = 400; } targetR = MoveAxis(targetR); } /// <summary> ///移动轴5 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAxis5_Click(object sender, EventArgs e) { MechanicalUnitCollection aMechCol = Public.ctr.MotionSystem.MechanicalUnits; JointTarget targetR = aMechCol[0].GetPosition(); JointTarget targetG = aMechCol[1].GetPosition(); targetR.RobAx.Rax_5 = float.Parse(txtAngle.Text); targetR.ExtAx.Eax_a = targetG.ExtAx.Eax_a; if (targetR.RobAx.Rax_5 < -125) { targetR.RobAx.Rax_5 = -125; } else if (targetR.RobAx.Rax_5 > 120) { targetR.RobAx.Rax_5 = 120; } targetR = MoveAxis(targetR); } /// <summary> /// 移动轴6 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAxis6_Click(object sender, EventArgs e) { MechanicalUnitCollection aMechCol = Public.ctr.MotionSystem.MechanicalUnits; JointTarget targetR = aMechCol[0].GetPosition(); JointTarget targetG = aMechCol[1].GetPosition(); targetR.RobAx.Rax_6 = float.Parse(txtAngle.Text); targetR.ExtAx.Eax_a = targetG.ExtAx.Eax_a; if (targetR.RobAx.Rax_6 < -400) { targetR.RobAx.Rax_6 = -400; } else if (targetR.RobAx.Rax_6 > 400) { targetR.RobAx.Rax_6 = 400; } targetR = MoveAxis(targetR); } #endregion #region 直线运动控制 private void btnLineRunX_Click(object sender, EventArgs e) { MechanicalUnitCollection aMechCol = Public.ctr.MotionSystem.MechanicalUnits; RobTarget targetG = aMechCol[1].GetPosition(CoordinateSystemType.World); RobTarget targetR = aMechCol[0].GetPosition(CoordinateSystemType.World); targetR.Extax.Eax_a = targetG.Trans.X; targetR.Trans.X = Convert.ToSingle(nUDStep.Value); targetR = LineRun(targetR); } private void btnLineRunY_Click(object sender, EventArgs e) { MechanicalUnitCollection aMechCol = Public.ctr.MotionSystem.MechanicalUnits; RobTarget targetG = aMechCol[1].GetPosition(CoordinateSystemType.World); RobTarget targetR = aMechCol[0].GetPosition(CoordinateSystemType.World); targetR.Extax.Eax_a = targetG.Trans.X; targetR.Trans.Y = Convert.ToSingle(nUDStep.Value); targetR = LineRun(targetR); } private void btnLineRunZ_Click(object sender, EventArgs e) { MechanicalUnitCollection aMechCol = Public.ctr.MotionSystem.MechanicalUnits; RobTarget targetG = aMechCol[1].GetPosition(CoordinateSystemType.World); RobTarget targetR = aMechCol[0].GetPosition(CoordinateSystemType.World); targetR.Extax.Eax_a = targetG.Trans.X; targetR.Trans.Z = Convert.ToSingle(nUDStep.Value); targetR = LineRun(targetR); } #endregion #region 重定位运动控制 private void btnRotatoRunRX_Click(object sender, EventArgs e) { double[] rpy = new double[3];//用于存储欧拉角形式的位姿信息 double[] q = new double[4];//用于存储四元数形式的位姿信息 //读取机器人的位姿信息 MechanicalUnitCollection aMechCol = Public.ctr.MotionSystem.MechanicalUnits; RobTarget targetG = aMechCol[1].GetPosition(CoordinateSystemType.World); RobTarget targetR = aMechCol[0].GetPosition(CoordinateSystemType.World); targetR.Extax.Eax_a = targetG.Trans.X; //MessageBox.Show(aimtarget.Rot.Q1.ToString() "\t" aimtarget.Rot.Q2.ToString() "\t" aimtarget.Rot.Q3.ToString() "\t" aimtarget.Rot.Q4.ToString()); //MessageBox.Show("计算结果" (Math.Pow(aimtarget.Rot.Q1, 2) Math.Pow(aimtarget.Rot.Q2, 2) Math.Pow(aimtarget.Rot.Q3, 2) Math.Pow(aimtarget.Rot.Q4, 2))); rpy = CoordinateTransformation.QuaternionToEuler(targetR.Rot.Q1, targetR.Rot.Q2, targetR.Rot.Q3, targetR.Rot.Q4); rpy[0] = Convert.ToDouble(nUDStep.Value); //MessageBox.Show("Roll:" rpy[0] "Pitch:" rpy[1] "Yaw:" rpy[2]); q = CoordinateTransformation.EulerToQuaternion(rpy[0], rpy[1], rpy[2]); targetR.Rot.Q1 = q[0]; targetR.Rot.Q2 = q[1]; targetR.Rot.Q3 = q[2]; targetR.Rot.Q4 = q[3]; //MessageBox.Show("Q1:" q[0] "Q2:" q[1] "Q3:" q[2] "Q4" q[3]); //MessageBox.Show("计算结果\t" (Math.Pow(q[0], 2) Math.Pow(q[1], 2) Math.Pow(q[2], 2) Math.Pow(q[3], 2)).ToString()); if ((Math.Pow(q[0], 2) Math.Pow(q[1], 2) Math.Pow(q[2], 2) Math.Pow(q[3], 2)).ToString() == "1") { targetR = LineRun(targetR); } else { MessageBox.Show("计算出错"); } } private void btnRotatoRunRY_Click(object sender, EventArgs e) { double[] rpy = new double[3]; double[] q = new double[4]; MechanicalUnitCollection aMechCol = Public.ctr.MotionSystem.MechanicalUnits; RobTarget targetG = aMechCol[1].GetPosition(CoordinateSystemType.World); RobTarget targetR = aMechCol[0].GetPosition(CoordinateSystemType.World); targetR.Extax.Eax_a = targetG.Trans.X; rpy = CoordinateTransformation.QuaternionToEuler(targetR.Rot.Q1, targetR.Rot.Q2, targetR.Rot.Q3, targetR.Rot.Q4); rpy[1] = Convert.ToDouble(nUDStep.Value); q = CoordinateTransformation.EulerToQuaternion(rpy[0], rpy[1], rpy[2]); targetR.Rot.Q1 = q[0]; targetR.Rot.Q2 = q[1]; targetR.Rot.Q3 = q[2]; targetR.Rot.Q4 = q[3]; if ((Math.Pow(q[0], 2) Math.Pow(q[1], 2) Math.Pow(q[2], 2) Math.Pow(q[3], 2)).ToString() == "1") { targetR = LineRun(targetR); } else { MessageBox.Show("计算出错"); } } private void btnRotatoRunRZ_Click(object sender, EventArgs e) { double[] rpy = new double[3]; double[] q = new double[4]; MechanicalUnitCollection aMechCol = Public.ctr.MotionSystem.MechanicalUnits; RobTarget targetG = aMechCol[1].GetPosition(CoordinateSystemType.World); RobTarget targetR = aMechCol[0].GetPosition(CoordinateSystemType.World); targetR.Extax.Eax_a = targetG.Trans.X; rpy = CoordinateTransformation.QuaternionToEuler(targetR.Rot.Q1, targetR.Rot.Q2, targetR.Rot.Q3, targetR.Rot.Q4); rpy[2] = Convert.ToDouble(nUDStep.Value); q = CoordinateTransformation.EulerToQuaternion(rpy[0], rpy[1], rpy[2]); targetR.Rot.Q1 = q[0]; targetR.Rot.Q2 = q[1]; targetR.Rot.Q3 = q[2]; targetR.Rot.Q4 = q[3]; if ((Math.Pow(q[0], 2) Math.Pow(q[1], 2) Math.Pow(q[2], 2) Math.Pow(q[3], 2)).ToString() == "1") { targetR = LineRun(targetR); } else { MessageBox.Show("计算出错"); } } #endregion /// <summary> /// 一键机器人回到机械原点 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnHomePoint_Click(object sender, EventArgs e) { JointTarget target = Public.ctr.MotionSystem.ActiveMechanicalUnit.GetPosition(); target.RobAx.Rax_1 = 0; target.RobAx.Rax_2 = 0; target.RobAx.Rax_3 = 0; target.RobAx.Rax_4 = 0; target.RobAx.Rax_5 = 30; target.RobAx.Rax_6 = 0; target = MoveAxis(target); } #region 将点位姿信息增添到listview中 /// <summary> /// 记录点的信息,并将其添加到listview中 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnRecord_Click(object sender, EventArgs e) { MechanicalUnitCollection aMechCol = Public.ctr.MotionSystem.MechanicalUnits; RobTarget targetG = aMechCol[1].GetPosition(CoordinateSystemType.World); RobTarget targetR = aMechCol[0].GetPosition(CoordinateSystemType.World); targetR.Extax.Eax_a = targetG.Trans.X; //显示记录点名称对话框 PointnameForm fm = new PointnameForm(); fm.ShowDialog(); //将点的位姿信息添加到listview中 if (System.String.IsNullOrWhiteSpace(Public.pointName)) { } else { ListViewItem iItem = listView1.Items.Add((listView1.Items.Count 1).ToString()); iItem.SubItems.Add(Public.pointName); iItem.SubItems.Add(targetR.ToString()); iItem.EnsureVisible(); } } #endregion #region 编程运动 /// <summary> /// 点击按钮开始按照指定点和指定运动方式进行运动 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnRun_Click(object sender, EventArgs e) { try { RobTarget target = RobTarget.Parse(listView1.SelectedItems[0].SubItems[2].Text); switch (cboRunStyle.Text) { case "直线运动": target = LineRun(target); break; case "曲线运动": target = JointRun(target); break; case "圆弧运动": //执行MoveC时总是执行不了,robotstudio中给出的原因如下: //1 终点太靠近起点。2 圆点离起点过近。3 圆点离终点过近。4 不确定的重定向。5 圆过大 > 240 度。 //当定义的位姿点正确时,该指令可以进行,所以在前期选择位姿点时要有所选择 target = CircleRun(target, RobTarget.Parse(listView1.SelectedItems[1].SubItems[2].Text)); break; default: break; } } catch (Exception a) { MessageBox.Show(a.ToString()); } } #endregion #region 导轨运动操作 private void btnTrack_Click(object sender, EventArgs e) { MechanicalUnitCollection aMechCol = Public.ctr.MotionSystem.MechanicalUnits; RobTarget targetG = aMechCol[1].GetPosition(CoordinateSystemType.World); RobTarget targetR = aMechCol[0].GetPosition(CoordinateSystemType.World); targetR.Extax.Eax_a = targetG.Trans.X float.Parse(txtAngle.Text); targetR.Trans.X = float.Parse(txtAngle.Text); targetR = GuidRun(targetR); } #endregion #region 机器人运动的方法 /// <summary> /// 将变换后的轴度数和更改后的数据传递给控制器,并使得机器人按照绝对轴关节运动 /// </summary> /// <param name="target">加上转动角度后的轴度数</param> /// <returns>轴关节度数</returns> private JointTarget MoveAxis(JointTarget target) { RapidData r = Public.ctr.Rapid.GetRapidData("T_ROB1", "Module1", "t"); RapidData pc = Public.ctr.Rapid.GetRapidData("T_ROB1", "Module1", "pc"); RapidData time = Public.ctr.Rapid.GetRapidData("T_ROB1", "Module1", "time"); ABB.Robotics.Controllers.RapidDomain.Num timeN = new Num(float.Parse(txtTime.Text)); ABB.Robotics.Controllers.RapidDomain.Num n = new Num(1); using (Mastership m = Mastership.Request(Public.ctr.Rapid)) { r.Value = target; pc.Value = n; time.Value = timeN; } return target; } /// <summary> /// 将变换后机器人位姿信息传递给控制器,并使得机器人按照关节式移动方式运动 /// </summary> /// <param name="target">机器人位姿信息</param> /// <returns>变换后的位姿信息</returns> private RobTarget JointRun(RobTarget target) { RapidData r = Public.ctr.Rapid.GetRapidData("T_ROB1", "Module1", "aimtarget"); RapidData pc = Public.ctr.Rapid.GetRapidData("T_ROB1", "Module1", "pc"); RapidData time = Public.ctr.Rapid.GetRapidData("T_ROB1", "Module1", "time"); ABB.Robotics.Controllers.RapidDomain.Num n = new Num(3); ABB.Robotics.Controllers.RapidDomain.Num timeN = new Num(float.Parse(txtTime.Text)); using (Mastership m = Mastership.Request(Public.ctr.Rapid)) { r.Value = target; pc.Value = n; time.Value = timeN; } return target; } /// <summary> /// 机器人直线运动 /// </summary> /// <param name="aimtarget">机器人整体位姿信息</param> /// <returns>变化后的位姿信息</returns> private RobTarget LineRun(RobTarget aimtarget) { RapidData r = Public.ctr.Rapid.GetRapidData("T_ROB1", "Module1", "aimtarget"); RapidData pc = Public.ctr.Rapid.GetRapidData("T_ROB1", "Module1", "pc"); RapidData time = Public.ctr.Rapid.GetRapidData("T_ROB1", "Module1", "time"); ABB.Robotics.Controllers.RapidDomain.Num n = new Num(2); ABB.Robotics.Controllers.RapidDomain.Num timeN = new Num(float.Parse(txtTime.Text)); using (Mastership m = Mastership.Request(Public.ctr.Rapid)) { r.Value = aimtarget; pc.Value = n; time.Value = timeN; } return aimtarget; } /// <summary> /// 机器人按照圆弧类型运动 /// </summary> /// <param name="target1">中间点位姿信息</param> /// <param name="target2">目标点位姿信息</param> /// <returns>中间点位姿信息</returns> private RobTarget CircleRun(RobTarget target1, RobTarget target2) { RapidData r = Public.ctr.Rapid.GetRapidData("T_ROB1", "Module1", "aimtarget"); RapidData mid = Public.ctr.Rapid.GetRapidData("T_ROB1", "Module1", "midtarget"); RapidData pc = Public.ctr.Rapid.GetRapidData("T_ROB1", "Module1", "pc"); RapidData time = Public.ctr.Rapid.GetRapidData("T_ROB1", "Module1", "time"); ABB.Robotics.Controllers.RapidDomain.Num timeN = new Num(float.Parse(txtTime.Text)); ABB.Robotics.Controllers.RapidDomain.Num n = new Num(4); using (Mastership m = Mastership.Request(Public.ctr.Rapid)) { r.Value = target1; mid.Value = target2; pc.Value = n; time.Value = timeN; } return target1; } /// <summary> /// 使机器人沿导轨运动 /// </summary> /// <param name="aimtarget"></param> /// <returns></returns> private RobTarget GuidRun(RobTarget aimtarget) { RapidData r = Public.ctr.Rapid.GetRapidData("T_ROB1", "Module1", "aimtarget"); RapidData pc = Public.ctr.Rapid.GetRapidData("T_ROB1", "Module1", "pc"); RapidData time = Public.ctr.Rapid.GetRapidData("T_ROB1", "Module1", "time"); ABB.Robotics.Controllers.RapidDomain.Num n = new Num(5); ABB.Robotics.Controllers.RapidDomain.Num timeN = new Num(float.Parse(txtTime.Text)); using (Mastership m = Mastership.Request(Public.ctr.Rapid)) { r.Value = aimtarget; pc.Value = n; time.Value = timeN; } return aimtarget; } #endregion /// <summary> /// 将机器人当前各轴的度数显示在对应的label中 /// </summary> private void WriteAxisAngle() { try { JointTarget target = Public.ctr.MotionSystem.ActiveMechanicalUnit.GetPosition(); lblAxis1.Text = "Axis1:" Math.Round(target.RobAx.Rax_1, 2, MidpointRounding.AwayFromZero).ToString(); lblAxis2.Text = "Axis2:" Math.Round(target.RobAx.Rax_2, 2, MidpointRounding.AwayFromZero).ToString(); lblAxis3.Text = "Axis3:" Math.Round(target.RobAx.Rax_3, 2, MidpointRounding.AwayFromZero).ToString(); lblAxis4.Text = "Axis4:" Math.Round(target.RobAx.Rax_4, 2, MidpointRounding.AwayFromZero).ToString(); lblAxis5.Text = "Axis5:" Math.Round(target.RobAx.Rax_5, 2, MidpointRounding.AwayFromZero).ToString(); lblAxis6.Text = "Axis6:" Math.Round(target.RobAx.Rax_6, 2, MidpointRounding.AwayFromZero).ToString(); } catch (Exception) { } } private void MianForm_Load(object sender, EventArgs e) { lblSpeed.Text = trackBar1.Value.ToString(); toolStripStatusLabel1.Text = System.DateTime.Now.ToString();//加载窗体时将时间给状态栏 WriteAxisAngle(); } /// <summary> /// 时间事件,每隔0.1s触发一次,1、显示当前时间在状态栏中;2、将机器人当前位姿传递给label /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void timer1_Tick(object sender, EventArgs e) { toolStripStatusLabel1.Text = System.DateTime.Now.ToString(); WriteAxisAngle(); } #region listview中鼠标右键操作 /// <summary> /// 右击鼠标选择删除,则将选中行从listview中删除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void 删除ToolStripMenuItem_Click(object sender, EventArgs e) { //int currentIndex = 0; if (this.listView1.SelectedItems.Count > 0)//判断listview有被选中项 { for (int i = 0; i < this.listView1.SelectedItems.Count; i ) { listView1.Items[i].Remove(); } //currentIndex = this.listView1.SelectedItems[0].Index;//取当前选中项的index //listView1.Items[currentIndex].Remove(); } } /// <summary> /// 右击鼠标选择修改点名称,弹出输入点名称对话框,并将修改后的值传递给listview /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void 修改点名称ToolStripMenuItem_Click(object sender, EventArgs e) { if (this.listView1.SelectedItems.Count==1) { PointnameForm fm = new PointnameForm(); fm.ShowDialog(); //将点的位姿信息添加到listview中 if (System.String.IsNullOrWhiteSpace(Public.pointName)) { } else { int currentIndex = 0; if (this.listView1.SelectedItems.Count > 0)//判断listview有被选中项 { currentIndex = this.listView1.SelectedItems[0].Index;//取当前选中项的index listView1.Items[currentIndex].SubItems[1].Text = Public.pointName;//将更改后的名称传递给listview中 } } } else if (this.listView1.SelectedItems.Count < 1) { MessageBox.Show("请先选择位姿点"); } else if (this.listView1.SelectedItems.Count > 1) { MessageBox.Show("请只选择一个位姿点"); } } /// <summary> /// 右击鼠标选择添加到运动,将位姿信息传递给listbox /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void 添加到运动ToolStripMenuItem_Click(object sender, EventArgs e) { listBox1.Items.Add(this.listView1.SelectedItems[0].SubItems[2].Text); } #endregion #region 点击菜单栏中相应控件出发相应的事件 private void 退出ToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("是否退出MoveRobot", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Stop); if (dr == DialogResult.OK) { this.Close(); } } private void 帮助ToolStripMenuItem_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start("http://new.abb.com/");//打开指定网站 } private void 打开ToolStripMenuItem_Click(object sender, EventArgs e) { this.openFileDialog1.ShowDialog(); } private void 保存ToolStripMenuItem_Click(object sender, EventArgs e) { this.openFileDialog1.ShowDialog(); } private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e) { this.openFileDialog1.ShowDialog(); } private void 新建ToolStripMenuItem_Click(object sender, EventArgs e) { this.openFileDialog1.ShowDialog(); } private void robotStudioToolStripMenuItem_Click(object sender, EventArgs e) { process1.Start(); } #endregion /// <summary> /// 当滑动条的值变化时,将变化后的值传递给speed;同时将滑动条变化后的值给label /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void trackBar1_ValueChanged(object sender, EventArgs e) { Public.speed = trackBar1.Value; Public.ctr.MotionSystem.SpeedRatio = trackBar1.Value; lblSpeed.Text = trackBar1.Value.ToString(); } /// <summary> /// 单轴运动时输入角度的限制 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void txtAngle_KeyPress(object sender, KeyPressEventArgs e) { //当按下的值不是数字或者.时,弹出提示对话框并且不将按键值传入文本框 if ((e.KeyChar != 8 && !char.IsDigit(e.KeyChar)) && e.KeyChar != 13 && e.KeyChar != 46 && e.KeyChar != 45) { MessageBox.Show("旋转角度只能输入数字", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); e.Handled = true; } if (txtAngle.Text == "-") { } //当文本框内的值大于100或小于-100时,并且按键不是backpace和enter时弹出提示对话框,并不将按键值传入文本框 else if ((float.Parse(txtAngle.Text) > 100 || float.Parse(txtAngle.Text) < -100) && (e.KeyChar != 8 && e.KeyChar != 13)) { MessageBox.Show("旋转角度过大", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); e.Handled = true; } } } }
标签:
网友评论
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
支持(0) 盖楼(回复)
支持(0) 盖楼(回复)