示教机械臂
Dependencies: MQTT SDFileSystem WIZnet_Library mbed
Fork of wmx_laser_copy by
Diff: mainwmx.cpp
- Revision:
- 9:a3f9faa9ca1f
- Parent:
- 8:e76bebe9c45f
- Child:
- 10:acc53f50c9df
--- a/mainwmx.cpp Fri Jul 27 10:19:40 2018 +0000 +++ b/mainwmx.cpp Tue Jul 31 03:56:05 2018 +0000 @@ -13,14 +13,16 @@ #include <stdlib.h> #include "SDFileSystem.h" #include "networking.h" +//#include <string> + -#define edgex1 30 // 上x(正朝向开关)下y(负朝向开关) -#define edgex2 125 // __ -#define edgey1 90 // || -#define edgey2 150 // 115mm y2 -#define widthx 95 // x2 || x1 -#define widthy 60 // //=====190mm====//30mm/|开关 +#define edgex1 125 // 上x(正朝向开关)下y(负朝向开关) +#define edgex2 155 // __ +#define edgey1 70 // || +#define edgey2 100 // 125mm y2 +#define widthx 30 // x2 || x1 +#define widthy 30 // //=====210mm====//35mm/|开关 #define mm 100//100步1mm // || // || // || @@ -62,7 +64,7 @@ //与实际有关参数 float Lenoflattice = 1 ;//mm 取1mm为xy单元 unit_xy/Lenoflattice=100 -int unit_xy = 200; //单位长度(xy移动一格)对应unit_xy转 大约10cm/3圈/9600step 约96mm/9600step=0.1mm/10step +int unit_xy = 100; //单位长度(xy移动一格)对应unit_xy转 大约10cm/3圈/9600step 约96mm/9600step=0.1mm/10step int unit_x = 103; //单位长度(xy移动一格)对应unit_x转 大约10cm/3圈/9600step 约96mm/9600step=0.1mm/10step int unit_y = 103; //单位长度(xy移动一格)对应unit_y转 大约10cm/3圈/9600step 约96mm/9600step=0.1mm/10step ///Ticker ticker_step; @@ -77,12 +79,14 @@ double y=0;//图片y边长 double x=0;//图片x边长 int key=0;//判断变量 +int dot=0;//点计数 +int flag=0; +//char w[4294967295]; void rotate(int id ,int pix); - void biginning() { pc.printf("x\n"); // 上x(正朝向开关)下y(负朝向开关) @@ -97,7 +101,14 @@ rotate(1,-5); // __ y1 } // rotate(1,mm*edgey1); // __ 开关 15mm - + //定位 + for (int i = 0; i < 500; i++) + { + switch_GS = 1; + wait(0.005); + switch_GS = 0; + wait(0.005); + } //走轮廓 rotate(0,mm*widthx); rotate(1,mm*widthy); @@ -197,7 +208,7 @@ pc.printf("reading\r\n"); for (int i = 0; fscanf(fp_drawing, "(%f,%f,%f)", &x, &y, &v) == 3; i++) { - pc.printf("(%f,%f,%f)\r\n", x, y, v); + pc.printf("(%f,%f,%f)|%d|%d\r\n", x, y, v,i,dot); moveto(x, y); markdot(v); // moveto(thedata[i][0],thedata[i][1]); @@ -209,10 +220,16 @@ void on_control_cmd(const char* actuator_name, const char* control_value) { //pc.printf("Received [%s] [%s]\r\n", actuator_name, control_value); - if (strcmp(actuator_name, "dat") == 0&&status==3) { + if (strcmp(actuator_name, "dat") == 0) { //接受到的坐标数据写入存储卡 - //pc.printf("Received yes\n"); + //fprintf(fp_drawing, "%s", control_value); fprintf(fp_drawing, "%s", control_value); + dot++; + if(strcmp(control_value, "(0,0,1)") == 0) + { + flag=1; + pc.printf("received (0,0,1) %d|%d\r\n",status,dot); + } } else if (strcmp(actuator_name, "cmd") == 0) { int the_command = atoi(control_value); @@ -226,7 +243,7 @@ } if (key==2) { x=the_command; - pc.printf("Received x %f\n",y); + pc.printf("Received x %f\n",x); } if (key==3) { @@ -245,9 +262,9 @@ Getdata = 1; pc.printf("Received Getdata %d\n",Getdata); } - else if (the_command == 3&&status==2&&key==0) {//传k + /*else if (the_command == 3&&status==2&&key==0) {//传k key=1; - } + }*/ else if (the_command == 4&&status==2&&key==0) {//传x key=2; } @@ -298,33 +315,43 @@ Getawork = 0; Getdata = 0; - publish_value(client, "report", "input x:"); - client.yield(5000); - publish_value(client, "report", "input y:"); - client.yield(5000); - - pc.printf("input k:\r\n"); - publish_value(client, "report", "input k:"); - wait(1); - int i=10; - while(y*k>widthy||i>0) - { - pc.printf("no%f|%f|%f|%d\r\n",y,k,y*k,i); - client.yield(1000); - i--; - } - pc.printf("yes%f|%f|%f\r\n",y,k,y*k); - pc.printf("ready.\r\n"); + //pc.printf("yes%f|%f|%f\r\n",y,k,y*k); + //pc.printf("ready.\r\n"); pc.printf("biginning\r\n"); biginning(); pc.printf("finish\r\n"); + //draw(); + while (true) { + if(x==0||y==0&&status==2) + { + while(x==0&&status==2) + { + pc.printf("waiting x\r\n"); + publish_value(client, "report", "input x:"); + client.yield(5000); + } + while(y==0&&status==2) + { + pc.printf("waiting y\r\n"); + publish_value(client, "report", "input y:"); + client.yield(5000); + } + publish_value(client, "report", "ready."); + } + while(y*k>widthy&&status==2) + { + k-=0.01; + pc.printf("no%f|%f|%f\r\n",y,k,y*k); + wait(0.001); + } if (status == 2) { + if (Getawork) { //收到新任务 Getawork = 0; @@ -336,18 +363,22 @@ pc.printf("File opened\r\n"); status = 3; publish_value(client, "report", "wait data."); + pc.printf("wait data.%d\r\n",status); } } - else - { - wait(0.1); - publish_value(client, "report", "ready."); - } + } - else if (status == 3) + if (status == 3) { + if(flag==1) + { + //wait(15); + + publish_value(client, "report", "all wrote."); + pc.printf("wrote finish %d\r\n",status); + } if (Getdata) { //数据接收完 Getdata = 0; @@ -357,17 +388,27 @@ status = 4; } } - else if (status == 4) + if (status == 4) { // pc.printf("debug4 \r\n"); // dealdata(); - pc.printf("Drawing.. %d \r\n",status); + pc.printf("Drawing.. %d |%d\r\n",status,dot); // usbprintdata(); draw(); publish_value(client, "report", "done."); + pc.printf("done. %d \r\n",status); status = 2; + x=0; + y=0; + Getawork = 0; + Getdata = 0; + unit_xy=200; + k=1.0; + flag=0; + dot=0; + //strcpy(w,""); } client.yield(1000); } - + }