示教机械臂

Dependencies:   MQTT SDFileSystem WIZnet_Library mbed

Fork of wmx_laser_copy by w mx

Revision:
11:568789ce1397
Parent:
10:acc53f50c9df
Child:
12:51be919e2c78
--- a/mainwmx.cpp	Tue Jul 31 12:51:28 2018 +0000
+++ b/mainwmx.cpp	Tue Jul 31 14:18:04 2018 +0000
@@ -69,6 +69,10 @@
 int dir_y = 1;///调试时调整
 int dir_z = 1;///调试时调整
 
+bool ready = 0;
+bool start = 0;
+bool done =0;
+
 char buf[256];
 int cur;
 bool received;
@@ -337,6 +341,34 @@
     }
 }
 
+void on_control_cmd(const char* actuator_name, const char* control_value)
+{
+
+    if (strcmp(actuator_name, "create") == 0) 
+    {
+        int the_command = atoi(control_value);
+        //
+        if(the_command==0)
+        {
+            ready=1;
+            pc.printf("get ready\r\n");
+        }
+        else if(the_command==1)
+        {
+            start=1;
+            pc.printf("get start\r\n");
+        }
+        else if(the_command==2)
+        {
+            done=1;
+            pc.printf("get done\r\n");
+        }
+        //
+        
+    }
+}
+
+
 int main()
 {
     init_zero();     //初始化
@@ -344,7 +376,44 @@
     pc.printf("beginning\r\n");
     beginning();
     pc.printf("finish\r\n");
-    while(1) {
+    
+    MQTTSocket sock;
+    MClient client(sock);
+    //声明所有的传感器,每行一个,每个由名字、单位两部分组成,最后一行必须为空指针作为结尾
+    const char* sensors[][2] = {
+        "report", "",
+        NULL, NULL //最后一行以空指针作为结束标记
+    };
+
+    //声明所有的执行器,每行一个,每个由名字、参数类型两部分组成,最后一行必须为空指针作为结尾
+    const char* actuators[][2] = {
+        "create", "",
+        NULL, NULL //最后一行以空指针作为结束标记
+    };
+    pc.printf("connecting...\r\n");
+
+    networking_init(sock, client, "192.168.1.100", sensors, actuators, on_control_cmd);
+
+    pc.printf("Initialization done.\r\n");
+    pc.printf("laser printer send ready.haha\r\n");
+    ready=0;
+    start=0;
+    done=0;
+
+    while(1) 
+    {   
+        if(!ready)
+        {
+            publish_value(client, "report", "ready.");
+            pc.printf("send ready.%d\r\n",flagw);
+            
+        }
+        if(!start&&ready)
+        {
+            pc.printf("send start.%d\r\n",flagw);
+            publish_value(client, "report", "wait to start.");
+            
+        }
 //        btInterrupt();
         //wait(0.1);
         //if (sw.read() == 0)
@@ -370,9 +439,9 @@
             moveto(now_x,now_y,Z);
             flagz = false;
         }
-        if(flagw)
+        if(flagw||start)
         {
-         
+            pc.printf("openning %d\r\n",flagw);
          
             FILE *fp = fopen("/sd/write.txt", "r"); //打开文件,路径以“/sd/”开头
         
@@ -400,6 +469,15 @@
             }
             flagw = false;
             pc.printf("%d\r\n",flagw);
+            if(!done)
+            {
+                publish_value(client, "report", "done.");
+                pc.printf("send done.%d\r\n",flagw);
+                
+            }
+            ready=0;
+            start=0;
+            done=0;
         }
         /*if (flagw)
         {
@@ -430,6 +508,6 @@
             pc.printf("write end");
             received = false;
         }
-    }
-
+        client.yield(1000);
+    } 
 }