本项目使用winform和C#对ABB进行通讯,打开vs2022,使用windows 窗口应用。需要一定的winforms基础。
然后打开Form1.cs窗口,找到工具箱,工具箱里面就是控件。将控件托入主窗口。第一天先教大家如何连接ABB机器人。ABB机器人连接可以通过TCP或者PC SDK连接,TCP连接需要ABB下载一个系统。PC SDK 是ABB公司自己弄的连接包,通过C#进行解析。所以在连接时需要引用ABB机器人连接包。需要到官网下载这两个文件。
首先第一天教大叫如何连接ABB。你们可以下载下图两个软件,是ABB用来虚拟模拟机器人的
1、在主窗口放入listview、button、raidobtton、textbox,如下图摆放.
2、双击一下搜索键,跳转值Forms1.cs,进行对button1函数设计
//搜素可连接的机器人
private void button1_Click(object sender, EventArgs e)
{
if (scanner == null)
{
scanner = new NetworkScanner();
}
scanner.Scan();
ControllerInfoCollection controls = scanner.Controllers;
this.listView1.Items.Clear();
foreach (ControllerInfo info in controls)
{
ListViewItem item = new ListViewItem(info.SystemName);
item.SubItems.Add(info.IPAddress.ToString());//显示IP地址
item.SubItems.Add(info.Version.ToString());//显示robotware版本
item.SubItems.Add(info.IsVirtual.ToString());显示是否为虚拟控制
item.SubItems.Add(info.ControllerName.ToString());//显示控制器名称
item.Tag = info;
this.listView1.Items.Add(item);
}
}
然后对listView右键 -> 属性->事件 -> Doubleclick(设置事件函数名称)
//连接控制器
private void connectrobot(object sender, EventArgs e)
{
if (this.listView1.Items.Count > 0)
{
ListViewItem item = this.listView1.SelectedItems[0];
if (item != null)
{
ControllerInfo info = (ControllerInfo)item.Tag;
if (info.Availability == Availability.Available)
{
if (controller != null)
{
controller.Logoff();
controller.Dispose();
controller = null;
}
controller = ControllerFactory.CreateFrom(info);
controller.Logon(UserInfo.DefaultUser);
MessageBox.Show("已经登录控制器" + info.SystemName);
isConnect = true;
timer1.Enabled = true;
subscribe();
}
}
}
hScrollBar1.Value = controller.MotionSystem.SpeedRatio;//获取控制器的速度率
tasks = controller.Rapid.GetTasks();
radioButton1.Checked = true;
}
设置笛卡尔坐标和关节坐标,其中一个属性将Checked 设置为true 。并且在工具箱中找到Timer控件拖进主窗口。
双击timer进入函数编辑
private void timer1_Tick(object sender, EventArgs e)
{
textBox1.Text = controller.MotionSystem.SpeedRatio.ToString() + "%";//将ABB速度与滑动块实时连接并控制速度率。
//关节坐标
if (radioButton1.Checked)
{
JointTarget RJ = controller.MotionSystem.ActiveMechanicalUnit.GetPosition();
label2.Text = "J1:";
label3.Text = "J2:";
label4.Text = "J3:";
label5.Text = "J4:";
label6.Text = "J5:";
label7.Text = "J6:";
PX1.Text = RJ.RobAx.Rax_1.ToString(format: "0.00");
PY1.Text = RJ.RobAx.Rax_2.ToString(format: "0.00");
PZ1.Text = RJ.RobAx.Rax_3.ToString(format: "0.00");
RX1.Text = RJ.RobAx.Rax_4.ToString(format: "0.00");
RY1.Text = RJ.RobAx.Rax_5.ToString(format: "0.00");
RZ1.Text = RJ.RobAx.Rax_6.ToString(format: "0.00");
}
//基坐标
if (radioButton2.Checked)
{
double tx;
double ty;
double tz;
RobTarget robTarget =
controller.MotionSystem.ActiveMechanicalUnit.GetPosition(CoordinateSystemType.World);
label2.Text = "PX:";
label3.Text = "PY:";
label4.Text = "PZ:";
label5.Text = "RX:";
label6.Text = "RY:";
label7.Text = "RZ;";
PX1.Text = robTarget.Trans.X.ToString(format: "0.00");
PY1.Text = robTarget.Trans.Y.ToString(format: "0.00");
PZ1.Text = robTarget.Trans.Z.ToString(format: "0.00");
robTarget.Rot.ToEulerAngles(out tx, out ty, out tz);
RX1.Text = tx.ToString(format: "0.00");
RY1.Text = ty.ToString(format: "0.00");
RZ1.Text = tz.ToString(format: "0.00");
}
}
打开robotstudio和虚拟示教器。 运行软件连接ABB机器人。
过后在将一下查看变量。如有描述错误,希望一起谈论~