program_SensorBlock //{Ping,Ir,Lines,compass} Sensor

Dependencies:   HMC6352 mbed

Fork of program_BlockPIL by Fumiya Fujisawa

Files at this revision

API Documentation at this revision

Comitter:
ryuna
Date:
Mon Feb 24 07:05:48 2014 +0000
Parent:
2:f7da3aa0520a
Child:
4:1d54610dba80
Commit message:
program version.2

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
usart.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Feb 24 05:23:18 2014 +0000
+++ b/main.cpp	Mon Feb 24 07:05:48 2014 +0000
@@ -22,6 +22,7 @@
 Serial sensor(p13,p14);
 Serial pc(USBTX,USBRX);
 HMC6352 compass(p9, p10);
+
 Timer time_ping;
 Timer time_ir; 
 
@@ -35,7 +36,8 @@
 volatile unsigned int value_ir_min = 0;
 volatile unsigned int ir_min_num = 0;
 volatile unsigned int value_line[ALL_LINE] = {0};
-volatile unsigned int value_compass = 0;
+volatile unsigned int value_compass0 = 0;
+volatile unsigned int value_compass[2] = {0};
 
 
 /*unsigned int*/void moving_ave(enum sensors kind,int num, unsigned int data){
@@ -169,7 +171,7 @@
 }
 int main() {
     //enum sensors kinds;
-    uint8_t compassdef = 0;
+    int compassdef = 0;
     int num[ALL_KIND] = {0};
     //送信開始
     sensor.putc(1);
@@ -179,10 +181,16 @@
     compassdef = (compass.sample() / 10);
     
     while(1) {
-        value_compass = ((compass.sample() / 10) + 540 - compassdef) % 360;
+        value_compass0 = ((compass.sample() / 10) + 540 - compassdef) % 360;
+        if(value_compass0 >=255 ){
+            value_compass[0] = 255;
+            value_compass[1] = value_compass0 - 255 ;
+        }else{
+            value_compass[0] = value_compass0;
+            value_compass[1] = 0;
+        }
         moving_ave(Ping,num[Ping],ping_function(num[Ping]));
-        
-        pc.printf("value_compass=%d\n",value_compass);
+        pc.printf("compass0=%d compass[0]= %d  compass[1]= %d\n",value_compass0,value_compass[0],value_compass[1]);
         //ir_min_fun();
         //num[Ping]++;
         //num[Ir]++;
--- a/usart.cpp	Mon Feb 24 05:23:18 2014 +0000
+++ b/usart.cpp	Mon Feb 24 07:05:48 2014 +0000
@@ -3,7 +3,7 @@
 #define KEYCODE 0xAA
 #define TX_CHECKCODE (tx_data[1]^tx_data[2]^tx_data[3]^tx_data[4]^tx_data[5]^tx_data[6]^tx_data[7]^tx_data[8]^tx_data[9]^tx_data[10])
 #define RX_CHECKCODE (rx_data[1]^rx_data[2]^rx_data[3]^rx_data[4]^rx_data[5]^rx_data[6]^rx_data[7]^rx_data[8]^rx_data[9]^rx_data[10])
-#define DATA_NUM 13
+#define DATA_NUM 14
 #define CHECK (DATA_NUM - 1)
 #define ALL_IR 10
 #define ALL_PING 4
@@ -18,7 +18,7 @@
 extern unsigned int value_ir_min;
 extern unsigned int ir_min_num;
 extern unsigned int value_line[ALL_LINE];
-extern unsigned int value_compass;
+extern unsigned int value_compass[2];
 void micon_rx(){
     
     static uint8_t rx;
@@ -56,8 +56,9 @@
         tx_data[8] = value_line[1];
         tx_data[9] = value_line[2];
         tx_data[10] = value_line[3];
-        tx_data[11] = value_compass;
-        tx_data[12] = TX_CHECKCODE;
+        tx_data[11] = value_compass[0];
+        tx_data[12] = value_compass[1];
+        tx_data[13] = TX_CHECKCODE;
         
         tx = 0;
     }