08/13

Dependencies:   ADXL345 BME280 HMC5883L ITG3200 MBed_Adafruit-GPS-Library XBee agzIDLIST cansat2 mbed

Fork of Cansat_program4 by CanSat2015aizu

Files at this revision

API Documentation at this revision

Comitter:
s1200058
Date:
Thu Aug 20 08:42:58 2015 +0000
Parent:
23:8581b740beef
Commit message:
add some comments for codes

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 8581b740beef -r d5fe0afc4565 main.cpp
--- a/main.cpp	Wed Aug 19 07:49:59 2015 +0000
+++ b/main.cpp	Thu Aug 20 08:42:58 2015 +0000
@@ -147,7 +147,7 @@
 
 }
 
-void Kalman(double Latitude,double Longitude){
+void Kalman(double Latitude,double Longitude){ //カルマンフィルターにGPSの値をかける
 
     zx = Latitude;
     zy = Longitude;
@@ -171,7 +171,7 @@
 //
 /////////////////////////////////////////
 
-void Get_GPS(Adafruit_GPS *myGPS){
+void Get_GPS(Adafruit_GPS *myGPS){ //GPSが取得できている時0を返し、取得できていない時1を返す
     static int flag = 0;
     
     if (myGPS->fix) {
@@ -320,28 +320,28 @@
 ******************************/
 void standby(){
     
-    cansat.control_Motor(1, cansat.get_speed());
-    cansat.set_temperature(sensor.getTemperature()); 
-    cansat.set_pressure(sensor.getPressure());
-    cansat.set_humidity(sensor.getHumidity());
+    cansat.control_Motor(1, cansat.get_speed()); //モーターに電流を流さない
+    cansat.set_temperature(sensor.getTemperature()); //気温の設定
+    cansat.set_pressure(sensor.getPressure()); //気圧の設定
+    cansat.set_humidity(sensor.getHumidity()); //湿度の設定
     
-    if(cansat.get_pressure() > goal_Pressure){
+    if(cansat.get_pressure() > goal_Pressure){ //最も高い気圧の値をgoal_Pressureに格納する
         goal_Pressure = cansat.get_pressure();
     }
     
-    if(!short_in){
+    if(!short_in){ //ショートピンが抜けた時
         xbee.printf("change mode: falling\n");
         short_flag++;
     }
     else{
-        if(running_Timer.read_ms() >= running_Time){
+        if(running_Timer.read_ms() >= running_Time){ //50msecごとに動作
             running_Timer.reset();
-            xbee.printf("stand by, %f, %f\n", goal_Pressure, cansat.get_pressure());
+            xbee.printf("stand by, %f, %f\n", goal_Pressure, cansat.get_pressure()); //ゴールと現在の気圧をプリントする
         }
     }
-    if(short_flag >= 5){
-        mode = 1;
-        goal_Pressure = goal_Pressure - 0.5;
+    if(short_flag >= 5){ //short_flagが5以上の場合
+        mode = 1; //落下モードに変更
+        goal_Pressure = goal_Pressure - 0.5; //気圧のゴール判定をgoal_Pressureよりも0.5低くする
         pressure_Timer.start();
         parachute_Timer.start();
     }
@@ -353,7 +353,7 @@
 ******************************/
 void falling_print(){
     
-    xbee.printf("%d: %04.2f hPa\n", log_number, cansat.get_pressure());
+    xbee.printf("%d: %04.2f hPa\n", log_number, cansat.get_pressure()); //現在の気圧の値をプリントする
 
     log_number++;
     
@@ -384,11 +384,11 @@
     
    if(fall_flag == 0 && parachute_Timer.read_ms() >= parachute_Time){   // 取得した気圧が閾値より小さく、落下してから30秒以上経過しているとき
         mode = 2;   // 走行モードに移る
-        nic = 1;    // ニクロム線を切る
+        nic = 1;    // ニクロム線に電流を流す
         xbee.printf("Time out!\n");
         xbee.printf("remove the parachute\n");
-        wait_ms(3000);
-        nic = 0;
+        wait_ms(3000); //3秒間停止
+        nic = 0; //ニクロム線に電流を流し終わる
         xbee.printf("change mode: running\n");
 
     }    
@@ -402,14 +402,14 @@
 
 void running_print(){
     
-    if(running_flag <= 20){
-        xbee.printf("%d: %f, %f, %d\n", log_number, cansat.get_robot_x(), cansat.get_robot_y(), cansat.get_speed());
+    if(running_flag <= 20){ //走り初めの時
+        xbee.printf("%d: %f, %f, %d\n", log_number, cansat.get_robot_x(), cansat.get_robot_y(), cansat.get_speed()); //生のGPSデータなどをログとしてプリントする
     }
     else{
-        xbee.printf("%d: %f, %f, %d\n", log_number, cansat.get_robotKalman_x(), cansat.get_robotKalman_y(), cansat.get_speed());
+        xbee.printf("%d: %f, %f, %d\n", log_number, cansat.get_robotKalman_x(), cansat.get_robotKalman_y(), cansat.get_speed()); //カルマンフィルターを通したGPSのデータなどをログとしてプリントする
     }       
-    xbee.printf("%c, %f\n", cansat.motor_command, cansat.get_compass_angle());
-    xbee.printf("%d, %d\n",cansat.get_robot_angle(), cansat.get_target_angle());
+    xbee.printf("%c, %f\n", cansat.motor_command, cansat.get_compass_angle()); //モーターのコマンド、コンパスから出た方向
+    xbee.printf("%d, %d\n",cansat.get_robot_angle(), cansat.get_target_angle()); //ロボットとターゲットの角度
  //   double y1 = cansat.get_target_y();
   //  double y2 = cansat.get_robot_y();
   //  double x1 = cansat.get_target_x();
@@ -436,55 +436,54 @@
     double y_sub;
     double x_sub;
   
-    if(running_flag < 20){
+    if(running_flag < 20){ //走り始めは生のGPSの値を用いて制御する
         y_sub = dy*111135.0;
         x_sub = dx*91191.0;
-        cansat.set_target_distance(sqrt(y_sub*y_sub + x_sub*x_sub));
-        cansat.set_target_angle(calc_angle(robot_compass(x1-x2, y1-y2)));
+        cansat.set_target_distance(sqrt(y_sub*y_sub + x_sub*x_sub)); //ゴール地点との距離を決める
+        cansat.set_target_angle(calc_angle(robot_compass(x1-x2, y1-y2))); //ロボットが行く方向を求める
         running_flag++;
     }
-    else{
+    else{ //カルマンフィルターの値を用いて制御する
         y_sub = dy_k*111135.0;
         x_sub = dx_k*91191.0;
         cansat.set_target_distance(sqrt(y_sub*y_sub + x_sub*x_sub));
         cansat.set_target_angle(calc_angle(robot_compass(x1-x_k2, y1-y_k2)));
     } 
     
-    if(cansat.get_target_distance() < 10) cansat.set_speed(64);
-    else if(cansat.get_target_distance() < 20 && cansat.get_target_distance() > 10) cansat.set_speed(128);
-    else cansat.set_speed(255);
+    if(cansat.get_target_distance() <= 10) cansat.set_speed(64); //ゴール地点との距離が10m以内の時,pwm:64
+    else if(cansat.get_target_distance() <= 20 && cansat.get_target_distance() > 10) cansat.set_speed(128); //ゴール地点との距離が10mより大きく20mm以内の時,pwm:128
+    else cansat.set_speed(255); //ゴール地点との距離が20mより大きい時,pwm:255
     
-    if(fall_flag == 1 && sep_Timer.read_ms() >= sep_Time){
+    if(fall_flag == 1 && sep_Timer.read_ms() >= sep_Time){ //落下後30秒がたった時ニクロム線の電源を切る
         nic = 0;
     }
-    if(compass_Timer.read_ms() >= compass_Time){
+    if(compass_Timer.read_ms() >= compass_Time){ //50msecごとに動作する
         compass_Timer.reset();
-        if(cansat.get_compass_z() < 0) {
-            //ひっくり返っている
-            cansat.control_Motor(0, cansat.get_speed());
+        if(cansat.get_compass_z() < 0) { //ひっくり返っているとき
+            cansat.control_Motor(0, cansat.get_speed()); //前進する
         } else {
-            cansat.motor_command = robot_Action(cansat.get_robot_angle(), cansat.get_target_angle());
+            cansat.motor_command = robot_Action(cansat.get_robot_angle(), cansat.get_target_angle()); //移動するときの方向を決める
             switch(cansat.motor_command) {
                 case 'f': //前進
                     cansat.control_Motor(0, cansat.get_speed());
                     break;
-                case 'l':
+                case 'l': //左
                     cansat.control_Motor(2, cansat.get_speed());
                     break;
-                case 'r':
+                case 'r': //右
                     cansat.control_Motor(3, cansat.get_speed());
                     break;
-                case 'b':
+                case 'b': //後退
                     cansat.control_Motor(4, cansat.get_speed());
                     break;
             }
         }
     }
     
-    running_print();
+    running_print(); //ログをプリントする
     
-    if(cansat.get_target_distance() <= 1){
-        mode = 100;
+    if(cansat.get_target_distance() <= 1){ //ゴール地点との距離が1m以下のとき
+        mode = 100; //停止モードに移行
         xbee.printf("change mode: stopping\n");
         xbee.printf("it is goal point.\n");
     }
@@ -495,7 +494,7 @@
 ******************************/
 void stopping(){
             
-            cansat.control_Motor(1, cansat.get_speed());
+            cansat.control_Motor(1, cansat.get_speed()); //モーターの動きを停止する
             
 }
 
@@ -549,9 +548,9 @@
     xbee.printf("target: %f, %f\n",cansat.get_target_x(), cansat.get_target_y());
     //int mode = -1;
     nic.output();
-    nic = 0;
+    nic = 0; //ニクロム線に電流を流さない
     
-    short_out = 1;
+    short_out = 1; //ショートピンに電流を流す
     wait_ms(1000);
 //    if(short_out){
 //       xbee.printf("HIGH\n");
@@ -581,7 +580,7 @@
             xbee.printf("robot_angle:%d, target_angle:%d, robot_compass:%f, %04.2f hPa\n",cansat.get_robot_angle(), cansat.get_target_angle(),  cansat.get_compass_angle(), cansat.get_pressure());
  */
         }
-        if(compass_refresh_Timer.read_ms() >= compass_refresh_Time){
+        if(compass_refresh_Timer.read_ms() >= compass_refresh_Time){ //コンパスの値を50msecごとに更新する
             Compass_intrpt();
             compass_refresh_Timer.reset();
         }