Yosuke Kirihata / Mbed 2 deprecated Nucleo_CaitSith_Firmware_added_delayServo

Dependencies:   mbed

Fork of Nucleo_CaitSith_Firmware by Yosuke Kirihata

Files at this revision

API Documentation at this revision

Comitter:
YosukeK
Date:
Sat Mar 07 17:46:56 2015 +0000
Parent:
7:3fcb0d1c41aa
Commit message:
???????????????????????????????????????????????

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Mar 07 15:49:55 2015 +0000
+++ b/main.cpp	Sat Mar 07 17:46:56 2015 +0000
@@ -100,29 +100,62 @@
                 //ルンバ移動指示
                 case 'M'://CTM+500-500
                     ret = true;
+                    
+                    int left = 0;
+                    int right = 0;
+                    
+                    int length = strlen(buffer);
+                    pc.printf("length:%d\n", length);
+                    if(buffer[3] == 'L') {
+                        left = atoi(buffer + 4);
+                        pc.printf("left:%d\n", left);
 
-                    char buff[4+1];
-                    int  temp;
-                    int  leftWheelVelocity, rightWheelVelocity;
-  
-                    //pc.printf("Param:%s\n", before);
-                    strncpy(buff, buffer + 4, 4);
-                    buff[4] = '\0';
-                    pc.printf("%s\n", buff);
-                    leftWheelVelocity = atoi(buff);
-                    pc. printf("%d\n", leftWheelVelocity);                
-                
-                    //printf("Param:%s\n", before);
-                    strncpy(buff, buffer + 9, 4);//(char*)buffer[3+4]
-                    buff[4] = '\0';
-                    pc. printf("%s\n", buff);
-                    rightWheelVelocity = atoi(buff);
-                    pc. printf("%d\n", rightWheelVelocity);
+                        int i = 4;
+                        while (i < length) {
+                            i++;
+                            if (buffer[i] == 'R') {
+                                pc.printf("find R index:%d\n", i);
+                                break;
+                            }
+                        }
+                        int right = atoi(buffer + i+1);
+                        pc.printf("right:%d\n", right);
+
+                    } else {
+                        ret = false;
+                        break;
+                    }
+                    
+//
+//                    char buff[4+1];
+//                    int  temp;
+//                    int  leftWheelVelocity, rightWheelVelocity;
+//  
+//                    while (buffer + i == 'R') {
+//                        i++;
+//                    }
+//  
+//                    //pc.printf("Param:%s\n", before);
+//                    strncpy(buff, buffer + 4, 4);
+//                    buff[4] = '\0';
+//                    pc.printf("%s\n", buff);
+//                    leftWheelVelocity = atoi(buff);
+//                    pc. printf("%d\n", leftWheelVelocity);                
+//                
+//                    //printf("Param:%s\n", before);
+//                    strncpy(buff, buffer + 9, 4);//(char*)buffer[3+4]
+//                    buff[4] = '\0';
+//                    pc. printf("%s\n", buff);
+//                    rightWheelVelocity = atoi(buff);
+//                    pc. printf("%d\n", rightWheelVelocity);
             
                     //SendData::SendData *data = new SendData(leftWheelVelocity, rightWheelVelocity);
                     
-                    data.wheelVelocity[0] = leftWheelVelocity;
-                    data.wheelVelocity[1] = rightWheelVelocity;
+                    data.wheelVelocity[0] = left;//leftWheelVelocity;
+                    data.wheelVelocity[1] = right;//rightWheelVelocity;
+
+                    pc. printf("%d, %d\n", data.wheelVelocity[0], data.wheelVelocity[1]);
+
                     
                     base.set(&data);