>更多内容请点击上方 ABB机器人实战技巧 关注 也可点击公众号下方 往期经典 浏览更多内容 转载请先后台留言,大家一起支持原创,推动机器人使用和发展 本公众号对各类ABB机器人应用,仿真,毕业设计提供技术支持,详细后台留言 本公众号诚挚希望与各机器人培训机构,机器人使用单元合作,提供技术支持,详细后台留言 点击文末的阅读原文,获取完整上位机和机器人源代码
1. 上位机控制ABB机器人,可以通过PCSDK修改机器人RAPID代码中的VAR和PERS数据的当前值。对于CONST类型的robtarget,无法修改,即无法直接实现示教器上的“修改位置”功能。2. PCSDK只提供了对于对于VAR和PERS的当前值的修改函数,但在WebService中可以修改数据的当前值(Currentvalue)和初值(Init Value)。对于常量,只有初值(InitValue)。此WebService功能适用rw6和rw7。(rw7为webservice2.0,url略有不同)3. 可以借助postman进行测试。例如对m300模块下的p2000点位(const存储类型)修改值,可以采用如下url,数据key为value,值为一个标准robtarget类型的数据格式4. 可以在postman中使用如下url获取当前机器人的robtarget(基于当前的tool和wobj),注:返回的外轴数据格式如下,若要直接写入机器人的robtarget,需要改写为9E95. 可以在C#中按照下图创建若干button和textbox,具体代码如下:注:为方便处理返回的Json格式及使用WebSocket,可以在Nuget中安装如下内容PM> Install-Package Microsoft.AspNet.WebApi.Client -Version 5.1.2 PM> Install-Package System.Json -Version 4.0.20126.16343
private void button1_Click(object sender, EventArgs e) { try { string url = textBox3.Text.Trim() + "?json=1"; string username = "Default User"; string password = "robotics";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; request.Credentials = new NetworkCredential(username, password); request.CookieContainer = _cookies; WebResponse response = request.GetResponse(); if (response != null) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { string result = reader.ReadToEnd(); dynamic obj = Newtonsoft.Json.JsonConvert.DeserializeObject(result); var service = obj._embedded._state[0]; string s1 = Convert.ToString(service.value); s1 = s1.Replace("+", ""); textBox1.Text = s1 + "\r\n"; } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void button2_Click(object sender, EventArgs e) { if (MessageBox.Show("是否继续", "修改位置不可撤销", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK) { try { string url = textBox3.Text.Trim() + "?action=setInitValue"; string body = "value=" + textBox2.Text.Trim(); HttpWebRequest request; request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.Credentials = new NetworkCredential("Default User", "robotics"); request.CookieContainer = _cookies; request.ContentType = "application/x-www-form-urlencoded"; Stream s = request.GetRequestStream(); s.Write(Encoding.ASCII.GetBytes(body), 0, body.Length); s.Close(); using (var httpResponse = (HttpWebResponse)request.GetResponse()) { if ((int)httpResponse.StatusCode == 204) { MessageBox.Show("示教成功"); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
private void button3_Click(object sender, EventArgs e) { string url = "http://localhost/rw/motionsystem/mechunits/ROB_1/robtarget?json=1"; string username = "Default User"; string password = "robotics";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; request.Credentials = new NetworkCredential(username, password); request.CookieContainer = _cookies; WebResponse response = request.GetResponse(); if (response != null) { using (StreamReader reader = new StreamReader(response.GetResponseStream())) { string result = reader.ReadToEnd(); dynamic obj = Newtonsoft.Json.JsonConvert.DeserializeObject(result); var service = obj._embedded._state[0]; textBox2.Text = "[[" + service.x + "," + service.y + "," + service.z + "],[" + service.q1 + "," + service.q2 + "," + service.q3 + "," + service.q4 + "],[" + service.cf1 + "," + service.cf4 + "," + service.cf6 + "," + service.cfx + "],[" +service.eaxa + "," + service.eaxb + "," + service.eaxc + "," + service.eaxd + "," + service.eaxe + "," + service.eaxf + "]]"; }
} }
点击文末的阅读原文,获取完整上位机和机器人源代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |