ダイセンの4chMDを動かす簡単なプログラム

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
ryuna
Date:
Sat Feb 27 06:01:52 2016 +0000
Commit message:
???????????????

Changed in this revision

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
wordString.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 617b63d4a532 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Feb 27 06:01:52 2016 +0000
@@ -0,0 +1,51 @@
+#include "mbed.h"
+#include <math.h>
+#include <sstream>
+
+DigitalOut myled(LED1);
+
+Serial      motor(p13,p14);//tx,rx
+extern string StringFIN;
+extern void array(int,int,int,int);
+
+int speed[4] = {0};
+int x = 0, y = 0,i;
+
+
+//通信(モータ用)
+void tx_motor(){
+    array(speed[0],speed[1],speed[3],speed[2]);
+    motor.printf("%s",StringFIN.c_str());
+}
+
+void move(int vx, int vy){
+    double pwm[4] = {0};
+    
+    pwm[0] = 0;
+    pwm[1] = -100;//(double)((-0.5 * vx) + ((sqrt(3.0) / 2.0)  * vy));
+    pwm[2] = //(double)((-0.5 * vx) + ((-sqrt(3.0) / 2.0) * vy));
+    pwm[3] = 100;//(double)((vx));
+    for(i = 0; i < 4; i++){
+        if(pwm[i] > 100){
+            pwm[i] = 100;
+        } else if(pwm[i] < -100){
+            pwm[i] = -100;
+        }
+        speed[i] = pwm[i];
+    }
+}
+int main() {
+    
+     wait(1);
+    motor.baud(115200);                             //ボーレート設定
+    motor.printf("1F0002F0003F0004F000\r\n");       //モータ停止
+    motor.attach(&tx_motor,Serial::TxIrq);          //送信空き割り込み(モータ用)
+    
+    
+    x = -10;
+    y = 10;
+    move(x,y);
+    while(1) {
+         wait(1);
+    }
+}
diff -r 000000000000 -r 617b63d4a532 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Feb 27 06:01:52 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/165afa46840b
\ No newline at end of file
diff -r 000000000000 -r 617b63d4a532 wordString.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wordString.cpp	Sat Feb 27 06:01:52 2016 +0000
@@ -0,0 +1,71 @@
+
+#include <sstream>
+#include "mbed.h"
+
+string StringFIN;
+
+using namespace std;
+
+
+//extern Serial pc; // tx, rx 
+
+string IntToString(int number)
+{
+  stringstream ss;
+  ss << number;
+  return ss.str();
+}
+
+void array(int power1,int power2,int power3,int power4)
+{
+    int input[4] = {power1,power2,power3,power4};
+    int value = 0;
+    string StringA[4] = {"0","0","0","0"};
+    
+    
+    string StringX = "0";
+    string StringY = "0";
+    string StringZ = "0";
+    string String0 = "0";
+    
+    StringFIN = "0";
+    
+    for(uint8_t i = 0 ; i < 4; i++){
+        
+        value = input[i];
+        
+        StringX =  IntToString(i+1);
+        
+        if( (value < 0) && (value >= -100) ){
+            StringY = "R";
+            value = abs(value);
+            StringZ = IntToString(value);
+        }else if( (value >= 0) && (value <= 100) ){
+            StringY = "F";
+            StringZ = IntToString(value);
+        }else{
+            value = abs(value);
+            StringY = "F";
+            StringZ = "000";
+        }
+        
+        if(value < 10){
+            String0 = "00";
+            StringZ = String0 + StringZ;
+        }else if(value < 100)
+        {
+            String0 = "0";
+            StringZ = String0 + StringZ;
+        }else{
+            
+        }
+        
+        StringA[i] = (StringX + StringY + StringZ);
+        
+        if(i == 0)StringFIN  = StringA[i];
+        else StringFIN  += StringA[i];
+        
+    }
+    
+    StringFIN += "\r\n";   
+}
\ No newline at end of file