モータ同定用プログラム

Dependencies:   mbed QEI motordriver SDFileSystem Encoder

Files at this revision

API Documentation at this revision

Comitter:
porizou3
Date:
Mon Mar 18 04:48:40 2019 +0000
Commit message:
firstcommit;

Changed in this revision

Encoder.lib Show annotated file Show diff for this revision Revisions of this file
QEI.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
motordriver.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Encoder.lib	Mon Mar 18 04:48:40 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/porizou3/code/Encoder/#6d62a5947f59
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QEI.lib	Mon Mar 18 04:48:40 2019 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/aberk/code/QEI/#5c2ad81551aa
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Mon Mar 18 04:48:40 2019 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/SDFileSystem/#8db0d3b02cec
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Mar 18 04:48:40 2019 +0000
@@ -0,0 +1,71 @@
+#include "mbed.h"
+#include "Encoder.h"
+#include "SDFileSystem.h"
+#include "motordriver.h"
+
+#define SAMPLETIME 0.001
+ 
+SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
+
+Serial pc(USBTX, USBRX); // tx, rx
+
+Encoder Enc(p21, p22, 12, 0.0001, 0.001);
+Motor motor(p25 , p23 , p24 , 10000);
+
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+
+Ticker timer;
+FILE* fp;
+
+double Velocity[1000] = { 0 };
+double Time[1000] = { 0 };
+
+double t = 0.0;
+
+int n = 0;
+
+void SDwrite() {
+    double velocity = -Enc.getVelocity();
+    
+    Velocity[n] = velocity;
+    Time[n] = t;
+    
+    n += 1;
+    t += SAMPLETIME;
+}
+
+int main() {
+    
+    pc.baud(115200);
+    
+    led2 = 1;   
+    fp = fopen("/sd/motor.csv", "w");
+    if(fp == NULL) {
+        pc.printf("Could not open file for write\n");
+    }
+    
+    timer.attach(&SDwrite, SAMPLETIME);
+    
+    motor.rotate(1.0);
+    
+    while(1) {
+        led1 = !led1;
+        pc.printf("Velocity: %5.2f [rad/s]\n\r", -Enc.getVelocity());
+        wait(0.0001);
+        if(t > 0.9) break;
+    }
+    timer.detach();
+    
+    motor.rotate(0.0);
+    led2 = 0;
+    led1 = 0;
+    
+    for( int i = 0; i < n; i++) {
+        fprintf(fp,"%f,%f\n",Time[i],Velocity[i]);
+    }
+    
+    
+    fclose(fp); 
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Mar 18 04:48:40 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/d75b3fe1f5cb
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motordriver.lib	Mon Mar 18 04:48:40 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/porizou3/code/motordriver/#876ba416c547