优微视开发者社区

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 19645|回复: 4

自动锁螺丝机造作指南(六) 接口编程

[复制链接]

26

主题

26

帖子

109

积分

版主

Rank: 7Rank: 7Rank: 7

积分
109
发表于 2019-4-27 16:38:57 | 显示全部楼层 |阅读模式
  1. 初始化程序
  2. 初始化函数如下:

  3. /*定义串口全局变量*/
  4. var serial;

  5. /*打开与运动控制器连接的串口*/
  6. function motor_open()
  7. {
  8.     serail = _serial.open({speed:115200,prity:0,data_bit:8,stop_bit:0});
  9.     return serail;
  10. }

  11. /*串口参数检查*/
  12. function motor_check()
  13. {
  14.     serail.check({speed:115200,prity:0,data_bit:8,stop_bit:0});
  15. }

  16. /*运动机构执行程序*/
  17. function motor_go(opt)
  18. {
  19.     serail.write('G01 X'+opt.x+' Y'+opt.y+' F200\n');
  20. }

  21. /*打开运动控制器*/
  22. motor_open();
  23. 接口程序
  24. /*运动控制接口*/
  25. _http.post('/usr/motor',function(opt){
  26.     print('G01 X'+opt.x+' Y'+opt.y+' F200\n');
  27.     _http.response('ok');
  28.     motor_check();
  29.     motor_go(opt);

  30.     math_variables_1.variables.robot_loc_y = opt.y;
  31.     math_variables_1.variables.robot_loc_x = opt.x;
  32.     _applet.sync('math_variables_1');
  33. });

  34. /*GCode测试接口*/
  35. _http.get('/usr/gcode',function(opt){
  36.     print('G01 X'+opt.x+' Y'+opt.y+' F200\n');
  37.     _http.response('ok');
  38.     motor_check();
  39.     motor_go(opt);
  40. });

  41. /*获取运动机构位置接口*/
  42. _http.get('/usr/reqloc',function(opt){
  43.     _http.response(JSON.stringify(math_variables_2.variables));
  44. });

  45. /*增加螺丝孔位置接口*/
  46. _http.get('/usr/addloc',function(opt){
  47.     _http.response('ok');
  48.     var i = parseInt(math_variables_2.total/3);
  49.     print('total count:'+i);
  50.     var n = i;
  51.     var xdiff = math_variables_1.variables.cam_org_x - math_variables_1.variables.robot_org_x;
  52.     var ydiff = math_variables_1.variables.cam_org_y - math_variables_1.variables.robot_org_y;
  53.     math_variables_2.variables['loc_'+n+'_x'] = opt.x - xdiff;
  54.     math_variables_2.variables['loc_'+n+'_y'] = opt.y - ydiff;
  55.     math_variables_2.variables['loc_'+n+'_z'] = opt.z;
  56.     _applet.sync('math_variables_2');
  57.     print('X:'+screw_loc[i].x+' Y:'+screw_loc[i].y+' Z:'+screw_loc[i].z);
  58. });

  59. /*更新螺丝孔位置接口*/
  60. _http.get('/usr/updateloc',function(opt){
  61.     _http.response('ok');
  62.     var i = opt.idx;
  63.     print('total count:'+i);
  64.     var cnt = parseInt(math_variables_2.total/3);

  65.     var xdiff = math_variables_1.variables.cam_org_x - math_variables_1.variables.robot_org_x;
  66.     var ydiff = math_variables_1.variables.cam_org_y - math_variables_1.variables.robot_org_y;

  67.     if(i < cnt){
  68.         math_variables_2.variables['loc_'+i+'_x'] = opt.x - xdiff;
  69.         math_variables_2.variables['loc_'+i+'_y'] = opt.y - ydiff;
  70.         math_variables_2.variables['loc_'+i+'_z'] = opt.z;
  71.     }
  72.     _applet.sync('math_variables_2');
  73.     _applet.restore('math_variables_2');
  74.     print('X:'+screw_loc[i].x+' Y:'+screw_loc[i].y+' Z:'+screw_loc[i].z);
  75. });

  76. /*删除螺丝孔位置接口*/
  77. _http.get('/usr/delloc',function(opt){
  78.     _http.response('ok');
  79.     var idx = opt.idx;
  80.     var cnt = parseInt(math_variables_2.total/3);
  81.     var j;
  82.     print('total count:'+cnt);
  83.     for (var i = idx; i < cnt-1; i++) {
  84.         j = i+1;
  85.         math_variables_2.variables['loc_'+i+'_x'] = math_variables_2.variables['loc_'+j+'_x'];
  86.         math_variables_2.variables['loc_'+i+'_y'] = math_variables_2.variables['loc_'+j+'_y'];
  87.         math_variables_2.variables['loc_'+i+'_z'] = math_variables_2.variables['loc_'+j+'_z'];
  88.     }
  89.     i = cnt-1;
  90.     delete math_variables_2.variables['loc_'+i+'_x'];
  91.     delete math_variables_2.variables['loc_'+i+'_y'];
  92.     delete math_variables_2.variables['loc_'+i+'_z'];
  93.     _applet.sync('math_variables_2');
  94.     _applet.restore('math_variables_2');
  95.     print('X:'+screw_loc[i].x+' Y:'+screw_loc[i].y+' Z:'+screw_loc[i].z);
  96. });

  97. /*修改相机坐标接口*/
  98. _http.get('/usr/camloc',function(opt,http){
  99.     _http.response('ok');
  100.     print('set camera location');
  101.     //print(JSON.stringify(math_variables_1.variables));
  102.     math_variables_1.variables.cam_org_y = opt.y;
  103.     math_variables_1.variables.cam_org_x = opt.x;
  104.     print('setloc  ssss'+math_variables_1.variables.cam_org_y);
  105.     _applet.sync('math_variables_1');
  106. });

  107. /*修改机械手坐标接口*/
  108. _http.get('/usr/robotloc',function(opt,http){
  109.     _http.response('ok');
  110.     print('set robot loccation');
  111.     //print(JSON.stringify(math_variables_1.variables));
  112.     math_variables_1.variables.robot_org_y = opt.y;
  113.     math_variables_1.variables.robot_org_x = opt.x;
  114.     print('setloc  ssss'+math_variables_1.variables.cam_org_y);
  115.     _applet.sync('math_variables_1');
  116.     _applet.restore('math_variables_1');
  117. });

  118. /*光源控制接口*/
  119. _http.get('/usr/light',function(opt,http){
  120.     _http.response(JSON.stringify(opt));
  121.     if(opt && opt.bright !== undefined){
  122.         print(opt.bright);
  123.         _light.bright(parseInt(opt.bright));
  124.     }
  125.     if(opt && opt.on !== undefined){
  126.         _light.on(parseInt(opt.on));
  127.     }
  128.     if(opt && opt.mode !== undefined){
  129.         _light.mode(parseInt(opt.mode));
  130.     }
  131. });

  132. /*标定接口*/
  133. _http.get('usr/calibrate',function(){
  134.     /*使用系统的once程序调用一次标定函数*/
  135.     _applet.once(calibrate);
  136. });
复制代码

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Youvtec Inc. ( 粤ICP备15097825号-1 )

GMT+8, 2025-5-1 04:46 , Processed in 0.095798 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表