harurobo_sensor

Dependencies:   uw_28015 mbed

Files at this revision

API Documentation at this revision

Comitter:
yuki0701
Date:
Sat Jan 12 06:24:12 2019 +0000
Commit message:
a;

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
uw_28015.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Jan 12 06:24:12 2019 +0000
@@ -0,0 +1,88 @@
+#include "mbed.h"
+#include "uw.h"
+
+//CAN can1(p30,p29,1000000);
+CAN can1(PA_11,PA_12,1000000);
+DigitalOut led(LED1);
+Ticker ticker;
+Uw uw1(PF_1); //機体背面の超音波センサー(三宝アーム側)
+Uw uw2(PF_0); //機体正面の超音波センサー(果物アーム側)
+Uw uw3(PB_4); //機体左側の超音波センサー
+Uw uw4(PA_0); //機体右側の超音波センサー
+
+//char can_data1[2]={0,0};
+//char can_data2[2]={0,0};
+char can_data3[2]={0,0};
+//char can_data4[2]={0,0};
+int x;
+int data1, data2, data3, data4;
+
+void can_read(){
+    
+    CANMessage msg;
+    
+    if(can1.read(msg)){
+      
+      if(msg.id == 1){
+        led = 1;
+        x = (short)((msg.data[0]<<8) | msg.data[1]);
+       printf("%d:%d,%d\n\r",msg.data[0],msg.data[1],x);
+      }
+    }
+}
+
+void can_send(){
+   
+   //printf("%f\n\r",uw1.get_dist());
+   
+    //data1 = (short)(1000 * uw1.get_dist()); //超音波センサーの値を1000倍して送る(受信側で0.001倍して元に戻す)
+    //data2 = (short)1000 * uw2.get_dist(); 
+    data3 = 1000 * uw3.get_dist(); 
+    //data4 = 1000 * uw4.get_dist(); 
+    
+    //can_data1[0] = data1 >> 8;
+    //can_data1[1] = data1 &255;
+    
+    //can_data2[0] = data2 >> 8;
+    //can_data2[1] = data2 &255;
+    
+    can_data3[0] = data3 >> 8;
+    can_data3[1] = data3 &255;
+    
+    /*can_data4[0] = data4 >> 8;
+    can_data4[1] = data4 &255;*/
+    
+    /*if(can1.write(CANMessage(1,can_data1,2))){
+       led = 1;
+       printf("send-data1 = %f", uw1.get_dist());
+       printf("send-data1 = %f\n\r", 0.01 * data1);
+    }*/
+   // if(can1.write(CANMessage(2,can_data2,2))){
+        // led = 1;
+        //printf("send-data2\n\r");
+   // }
+    if(can1.write(CANMessage(3,can_data3,2))){
+        led = 1;
+        printf("send-data3 = %f\n\r", 0.01 * data3);
+    }
+    /*if(can1.write(CANMessage(4,can_data4,2))){
+        //led = 1;
+        //printf("send-data4\n\r");
+    }*/
+        led = 0;
+        //printf("send-data1 = %f, send-data2 = %f\n\r", 0.01 * data1, 0.01 * data2);
+}
+    
+    
+    
+int main() {
+
+   ticker.attach(&can_send,0.01);
+ //ticker.attach(&can_read,0.1);
+ 
+ while(1);
+     /*{
+      //printf("%f\n\r",uw3.get_dist());
+     }*/
+     
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Jan 12 06:24:12 2019 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed/builds/a330f0fddbec
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/uw_28015.lib	Sat Jan 12 06:24:12 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/ROBOSTEP_SHARE/code/uw_28015/#bf432b07f874