当前位置:
技能培训 >
ABB工业机器人-上位机示教const类型点位
ABB工业机器人-上位机示教const类型点位
文章出处:gkb01 阅读量:16715 发表时间:2022-08-13 09:16
上位机在机器人自动模式示教修改const常量点位
1. 上位机控制ABB机器人,可以通过PCSDK修改机器人RAPID代码中的VAR和PERS数据的当前值。对于CONST类型的robtarget,无法修改,即无法直接实现示教器上的“修改位置”功能。
2. PCSDK只提供了对于对于VAR和PERS的当前值的修改函数,但在WebService中可以修改数据的当前值(Current value)和初值(Init Value)。对于常量,只有初值(Init Value)
3. 可以借助postman进行测试。例如对m300模块下的p2000点位(const存储类型)修改值,可以采用如下url,数据key为value,值为一个标准robtarget类型的数据格式
注:测试时,机器人需要处于自动模式
修改成功,系统返回状态204
4. 可以在postman中使用如下url获取当前机器人的robtarget(基于当前的tool和wobj),注:返回的外轴数据格式如下,若要直接写入机器人的robtarget,需要改写为9E9
5. 可以在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)
{
//获取点位位置button
try
{
string url = textBox3.Text.Trim() + "?json=1";
//返回json格式数据,默认返回xml格式数据
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("+", "");
//返回外轴数据为9E+9,去除+号
textBox1.Text = s1 + "rn";
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void button2_Click(object sender, EventArgs e)
{
//示教 button
if (MessageBox.Show("是否继续", "修改位置不可撤销", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
{
try
{
string url = textBox3.Text.Trim() + "?action=setInitValue";
//string url = "http://127.0.0.1/rw/rapid/symbol/data/RAPID/T_ROB1/user/reg2?action=set";
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)
{
//显示当前位置button
string url = "http://localhost/rw/motionsystem/mechunits/ROB_1/robtarget?json=1";
//提交的地址,此处为本机虚拟IP
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];
double x = Convert.ToDouble(Convert.ToString(service.x));
double y = Convert.ToDouble(Convert.ToString(service.y));
double z = Convert.ToDouble(Convert.ToString(service.z));
double q1 = Convert.ToDouble(Convert.ToString(service.q1));
double q2 = Convert.ToDouble(Convert.ToString(service.q2));
double q3 = Convert.ToDouble(Convert.ToString(service.q3));
double q4 = Convert.ToDouble(Convert.ToString(service.q4));
double cf1 = Convert.ToDouble(Convert.ToString(service.cf1));
double cf4 = Convert.ToDouble(Convert.ToString(service.cf4));
double cf6 = Convert.ToDouble(Convert.ToString(service.cf6));
double cfx = Convert.ToDouble(Convert.ToString(service.cfx));
double eaxa = Convert.ToDouble(Convert.ToString(service.eaxa));
double eaxb = Convert.ToDouble(Convert.ToString(service.eaxb));
double eaxc = Convert.ToDouble(Convert.ToString(service.eaxc));
double eaxd = Convert.ToDouble(Convert.ToString(service.eaxd));
double eaxe = Convert.ToDouble(Convert.ToString(service.eaxe));
double eaxf = Convert.ToDouble(Convert.ToString(service.eaxf));
string s_eaxa;
string s_eaxb;
string s_eaxc;
string s_eaxd;
string s_eaxe;
string s_eaxf;
if (eaxa > 9E8)
{
s_eaxa = "9E9";
}
else
{
s_eaxa = service.eaxa;
}
if (eaxb > 9E8)
{
s_eaxb = "9E9";
}
else
{
s_eaxb = service.eaxb;
}
if (eaxc > 9E8)
{
s_eaxc = "9E9";
}
else
{
s_eaxc = service.eaxc;
}
if (eaxd > 9E8)
{
s_eaxd = "9E9";
}
else
{
s_eaxd = service.eaxd;
}
if (eaxe > 9E8)
{
s_eaxe = "9E9";
}
else
{
s_eaxe = service.eaxe;
}
if (eaxf > 9E8)
{
s_eaxf = "9E9";
}
else
{
s_eaxf = service.eaxf;
}
textBox2.Text = "[[" + x + "," + y + "," + z + "],["
+ q1 + "," + q2 + "," + q3 + "," + q4 + "],["
+ cf1 + "," + cf4 + "," + cf6 + "," + cfx + "],["
+ s_eaxa + "," + s_eaxb + "," + s_eaxc + "," + s_eaxd + "," + s_eaxe + "," + s_eaxf + "]]";
//textBox2.Text = "[[" + service.x + "," + service.y + "," + service.z + "],["
// + service.q1 + "," + service.q2 + "," + service.q3 + "," + service.q4 + "],["
// + service.cf1 + "," + service.cf4 + "," + service.cf6 + "," + service.cfx + "],["
}