V1

Dependencies:   BufferedSerial sn7544

Fork of GPG_motor by Kang mingyo

Files at this revision

API Documentation at this revision

Comitter:
kangmingyo
Date:
Thu May 23 23:04:30 2019 +0000
Parent:
1:1d18a2e8ce45
Child:
3:0c6258635590
Commit message:
2018/05/23;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
motor.lib Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu May 23 08:53:48 2019 +0000
+++ b/main.cpp	Thu May 23 23:04:30 2019 +0000
@@ -5,23 +5,56 @@
 InterruptIn tachoINT1(D4);
 InterruptIn tachoINT2(D5);
 Serial pc(USBTX,USBRX,115200);
-
-void update_current(void){
+char rx_buffer[10];
+int index=0;
+volatile int flag;
+void update_current(void)
+{
     motor1.UpdateCurrentPosition();
-  //  pc.printf("Update Position\r\n");
+    //  pc.printf("Update Position\r\n");
+}
+void rx_cb(void){
+    char ch;
+    ch = pc.getc();
+    pc.putc(ch);
+    rx_buffer[index++]=ch;
+    if(ch==0x0D){
+        pc.putc(0x0A);
+        rx_buffer[--index]='\0';
+        index=0;
+        flag=1;
+    }
 }
 
+int set_speed(void)
+{
+    int speed;
+    speed = atoi((const char*)rx_buffer);
+    if(speed>78){speed=78;}
+    if(speed<-78){speed=-78;}
+    motor1.setTarget(speed);
+    pc.printf(" Set speed = %d\r\n", speed);
+    return speed;
+}
 
-int main(){
+int main()
+{
     tachoINT1.fall(&update_current);
     tachoINT1.rise(&update_current);
     tachoINT2.fall(&update_current);
     tachoINT2.rise(&update_current);
-    
-    while(1){
+    pc.attach(callback(rx_cb));
+    int rpm;
+
+    while(1) {
+        flag=0;
+        pc.printf("Enter the value for speed [-78,78]\r\n");
+        while(flag!=1) {
+            rpm=motor1.getRPM();
+            pc.printf("rpm = %d\r\n",rpm);
+            wait(1);
         }
-    
-}
+        set_speed();
+    }
 
-
-
+}
--- a/motor.lib	Thu May 23 08:53:48 2019 +0000
+++ b/motor.lib	Thu May 23 23:04:30 2019 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/teams/Pipe-Inpection-Robot/code/motor/#df8469e71728
+https://os.mbed.com/teams/Pipe-Inpection-Robot/code/motor/#a629f46d6594