|
- 初始化程序
- 初始化函数如下:
- /*定义串口全局变量*/
- var serial;
- /*打开与运动控制器连接的串口*/
- function motor_open()
- {
- serail = _serial.open({speed:115200,prity:0,data_bit:8,stop_bit:0});
- return serail;
- }
- /*串口参数检查*/
- function motor_check()
- {
- serail.check({speed:115200,prity:0,data_bit:8,stop_bit:0});
- }
- /*运动机构执行程序*/
- function motor_go(opt)
- {
- serail.write('G01 X'+opt.x+' Y'+opt.y+' F200\n');
- }
- /*打开运动控制器*/
- motor_open();
- 接口程序
- /*运动控制接口*/
- _http.post('/usr/motor',function(opt){
- print('G01 X'+opt.x+' Y'+opt.y+' F200\n');
- _http.response('ok');
- motor_check();
- motor_go(opt);
- math_variables_1.variables.robot_loc_y = opt.y;
- math_variables_1.variables.robot_loc_x = opt.x;
- _applet.sync('math_variables_1');
- });
- /*GCode测试接口*/
- _http.get('/usr/gcode',function(opt){
- print('G01 X'+opt.x+' Y'+opt.y+' F200\n');
- _http.response('ok');
- motor_check();
- motor_go(opt);
- });
- /*获取运动机构位置接口*/
- _http.get('/usr/reqloc',function(opt){
- _http.response(JSON.stringify(math_variables_2.variables));
- });
- /*增加螺丝孔位置接口*/
- _http.get('/usr/addloc',function(opt){
- _http.response('ok');
- var i = parseInt(math_variables_2.total/3);
- print('total count:'+i);
- var n = i;
- var xdiff = math_variables_1.variables.cam_org_x - math_variables_1.variables.robot_org_x;
- var ydiff = math_variables_1.variables.cam_org_y - math_variables_1.variables.robot_org_y;
- math_variables_2.variables['loc_'+n+'_x'] = opt.x - xdiff;
- math_variables_2.variables['loc_'+n+'_y'] = opt.y - ydiff;
- math_variables_2.variables['loc_'+n+'_z'] = opt.z;
- _applet.sync('math_variables_2');
- print('X:'+screw_loc[i].x+' Y:'+screw_loc[i].y+' Z:'+screw_loc[i].z);
- });
- /*更新螺丝孔位置接口*/
- _http.get('/usr/updateloc',function(opt){
- _http.response('ok');
- var i = opt.idx;
- print('total count:'+i);
- var cnt = parseInt(math_variables_2.total/3);
- var xdiff = math_variables_1.variables.cam_org_x - math_variables_1.variables.robot_org_x;
- var ydiff = math_variables_1.variables.cam_org_y - math_variables_1.variables.robot_org_y;
- if(i < cnt){
- math_variables_2.variables['loc_'+i+'_x'] = opt.x - xdiff;
- math_variables_2.variables['loc_'+i+'_y'] = opt.y - ydiff;
- math_variables_2.variables['loc_'+i+'_z'] = opt.z;
- }
- _applet.sync('math_variables_2');
- _applet.restore('math_variables_2');
- print('X:'+screw_loc[i].x+' Y:'+screw_loc[i].y+' Z:'+screw_loc[i].z);
- });
- /*删除螺丝孔位置接口*/
- _http.get('/usr/delloc',function(opt){
- _http.response('ok');
- var idx = opt.idx;
- var cnt = parseInt(math_variables_2.total/3);
- var j;
- print('total count:'+cnt);
- for (var i = idx; i < cnt-1; i++) {
- j = i+1;
- math_variables_2.variables['loc_'+i+'_x'] = math_variables_2.variables['loc_'+j+'_x'];
- math_variables_2.variables['loc_'+i+'_y'] = math_variables_2.variables['loc_'+j+'_y'];
- math_variables_2.variables['loc_'+i+'_z'] = math_variables_2.variables['loc_'+j+'_z'];
- }
- i = cnt-1;
- delete math_variables_2.variables['loc_'+i+'_x'];
- delete math_variables_2.variables['loc_'+i+'_y'];
- delete math_variables_2.variables['loc_'+i+'_z'];
- _applet.sync('math_variables_2');
- _applet.restore('math_variables_2');
- print('X:'+screw_loc[i].x+' Y:'+screw_loc[i].y+' Z:'+screw_loc[i].z);
- });
- /*修改相机坐标接口*/
- _http.get('/usr/camloc',function(opt,http){
- _http.response('ok');
- print('set camera location');
- //print(JSON.stringify(math_variables_1.variables));
- math_variables_1.variables.cam_org_y = opt.y;
- math_variables_1.variables.cam_org_x = opt.x;
- print('setloc ssss'+math_variables_1.variables.cam_org_y);
- _applet.sync('math_variables_1');
- });
- /*修改机械手坐标接口*/
- _http.get('/usr/robotloc',function(opt,http){
- _http.response('ok');
- print('set robot loccation');
- //print(JSON.stringify(math_variables_1.variables));
- math_variables_1.variables.robot_org_y = opt.y;
- math_variables_1.variables.robot_org_x = opt.x;
- print('setloc ssss'+math_variables_1.variables.cam_org_y);
- _applet.sync('math_variables_1');
- _applet.restore('math_variables_1');
- });
- /*光源控制接口*/
- _http.get('/usr/light',function(opt,http){
- _http.response(JSON.stringify(opt));
- if(opt && opt.bright !== undefined){
- print(opt.bright);
- _light.bright(parseInt(opt.bright));
- }
- if(opt && opt.on !== undefined){
- _light.on(parseInt(opt.on));
- }
- if(opt && opt.mode !== undefined){
- _light.mode(parseInt(opt.mode));
- }
- });
- /*标定接口*/
- _http.get('usr/calibrate',function(){
- /*使用系统的once程序调用一次标定函数*/
- _applet.once(calibrate);
- });
复制代码
|
|