SGMP Coperations / Mbed 2 deprecated greenimugetithothot

Dependencies:   mbed

Fork of greenimugetithothot by SGMP Coperations

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "GETMPU9250.h"
00003 #include "math.h"
00004 
00005 ZMU9250 axis_Gen;
00006 
00007 Serial pc(D1, D0);
00008 
00009 DigitalIn get(PC_7);
00010 DigitalIn mon1(PA_7);
00011 DigitalIn mon2(PB_6);
00012 DigitalIn mon3(PA_5);
00013 
00014 float axis_gz, axis_gy, axis_gx;
00015 float axis_az, axis_ay, axis_ax;
00016 float CurAy, CurAx, CurAz, CurGx, CurGy, CurGz;
00017 float diffAy, diffAx, diffAz, diffGx, diffGy, diffGz;
00018 float getAy, getAx, getAz, getGx, getGy, getGz;
00019 int getitem = 1, monster1 = 1, monster2 = 1, monster3 = 1, boss1 = 1, boss2 = 1, boss3 = 1;
00020 
00021 int main(){
00022 
00023     while(1){
00024         //wait(0.1);
00025         axis_Gen.Update();
00026         axis_ax = (axis_Gen.g_ax()*1000)+0;
00027         axis_ay = (axis_Gen.g_ay()*1000)+0;
00028         axis_az = (axis_Gen.g_az()*1000)-1000;
00029         axis_gx = axis_Gen.g_gx()*4;
00030         axis_gy = axis_Gen.g_gy()*4;
00031         axis_gz = axis_Gen.g_gz()*4; 
00032         pc.printf(" Gaxis_x %f\t Gaxis_y %f\t Gaxis_z %f  ", axis_gx, axis_gy, axis_gz);     
00033         pc.printf(" Aaxis_x %f\t Aaxis_y %f\t Aaxis_z %f\n\n\n\r", axis_ax, axis_ay, axis_az);
00034 //        wait(0.2);     
00035 
00036         if(get == 0)
00037         {
00038             getAy = abs(axis_ay);
00039             getAx = abs(axis_ax);
00040             getAz = abs(axis_az);
00041             while(getitem)
00042             {
00043                 pc.printf("\n\nAZ = %f ", getAz);
00044                 wait(0.1);
00045                 axis_Gen.Update();
00046                 CurAy = axis_Gen.g_ay()*1000;
00047                 CurAx = axis_Gen.g_ax()*1000;
00048                 CurAz = axis_Gen.g_az()*1000;
00049                 pc.printf("\n\nCurrentZ = %f ", CurAz);
00050                 diffAy = abs(abs(CurAy)-getAy);
00051                 diffAx = abs(abs(CurAx)-getAx);
00052                 diffAz = abs(abs(CurAz)-getAz);
00053                 pc.printf("\n\nDiffAy = %f ", diffAy);
00054                 pc.printf("\n\nDiffAx = %f ", diffAx);
00055                 pc.printf("\n\nDiffAz = %f \n\n", diffAz);
00056                 if(diffAz > 1300 and diffAx < 200 and diffAy < 200 )
00057                 { 
00058                     pc.printf("\n\n ITEM \n\n");
00059                     getitem = 0;
00060                 }
00061             }
00062             getitem = 1;
00063         }
00064         if(mon1 == 0)
00065         {
00066             getAy = abs(axis_ay);
00067             getAx = abs(axis_ax);
00068             getAz = abs(axis_az);
00069             while(monster1)
00070             {
00071                 pc.printf("\n\nAx = %f ", getAx);
00072                 wait(0.1);
00073                 axis_Gen.Update();
00074                 CurAy = axis_Gen.g_ay()*1000;
00075                 CurAx = axis_Gen.g_ax()*1000;
00076                 CurAz = axis_Gen.g_az()*1000;
00077                 pc.printf("\n\nCurrentX = %f ", CurAx);
00078                 diffAy = abs(abs(CurAy)-getAy);
00079                 diffAx = abs(abs(CurAx)-getAx);
00080                 diffAz = abs(abs(CurAz)-getAz);
00081                 pc.printf("\n\nDiffAy = %f ", diffAy);
00082                 pc.printf("\n\nDiffAx = %f ", diffAx);
00083                 pc.printf("\n\nDiffAz = %f \n\n", diffAz);
00084                 if(diffAx > 600 and diffAz < 1000 and diffAy < 200 )
00085                 { 
00086                     pc.printf("\n\n Monster 1 \n\n");
00087                     monster1 = 0;
00088                 }
00089             }
00090             monster1 = 1;   
00091         }
00092         if(mon2 == 0)
00093         {
00094             getAy = abs(axis_ay);
00095             getAx = abs(axis_ax);
00096             getAz = abs(axis_az);
00097             while(monster2)
00098             {
00099                 pc.printf("\n\nAy = %f ", getAy);
00100                 wait(0.1);
00101                 axis_Gen.Update();
00102                 CurAy = axis_Gen.g_ay()*1000;
00103                 CurAx = axis_Gen.g_ax()*1000;
00104                 CurAz = axis_Gen.g_az()*1000;
00105                 pc.printf("\n\nCurrentY = %f ", CurAy);
00106                 diffAy = abs(abs(CurAy)-getAy);
00107                 diffAx = abs(abs(CurAx)-getAx);
00108                 diffAz = abs(abs(CurAz)-getAz);
00109                 pc.printf("\n\nDiffAy = %f ", diffAy);
00110                 pc.printf("\n\nDiffAx = %f ", diffAx);
00111                 pc.printf("\n\nDiffAz = %f \n\n", diffAz);
00112                 if(diffAy > 800 and diffAz < 1000 and diffAx < 200 )
00113                 { 
00114                     pc.printf("\n\n Monster 2 \n\n");
00115                     monster2 = 0;
00116                 }
00117             }
00118             monster2 = 1;   
00119         }
00120         if(mon3 == 0)
00121         {
00122             getAy = abs(axis_ay);
00123             getAx = abs(axis_ax);
00124             getAz = abs(axis_az);
00125             while(monster3)
00126             {
00127                 pc.printf("\n\nAx = %f ", getAx);
00128                 wait(0.1);
00129                 axis_Gen.Update();
00130                 CurAy = axis_Gen.g_ay()*1000;
00131                 CurAx = axis_Gen.g_ax()*1000;
00132                 CurAz = axis_Gen.g_az()*1000;
00133                 pc.printf("\n\nCurrentX = %f ", CurAx);
00134                 diffAy = abs(abs(CurAy)-getAy);
00135                 diffAx = abs(abs(CurAx)-getAx);
00136                 diffAz = abs(abs(CurAz)-getAz);
00137                 pc.printf("\n\nDiffAy = %f ", diffAy);
00138                 pc.printf("\n\nDiffAx = %f ", diffAx);
00139                 pc.printf("\n\nDiffAz = %f \n\n", diffAz);
00140                 if(diffAy > 200 and diffAz < 900 and diffAy < 300 )
00141                 { 
00142                     pc.printf("\n\n Monster 3 \n\n");
00143                     monster3 = 0;
00144                 }
00145             }
00146             monster3 = 1;   
00147         }
00148         if(get == 0 and mon1 == 0)
00149         {
00150             getAy = abs(axis_ay);
00151             getAx = abs(axis_ax);
00152             getAz = abs(axis_az);
00153             getGx = abs(axis_gx);
00154             getGy = abs(axis_gy);
00155             getGz = abs(axis_gz);
00156             while(boss1)
00157             {
00158                 pc.printf("\n\nAx = %f ", getAx);
00159                 wait(0.1);
00160                 axis_Gen.Update();
00161                 CurAy = axis_Gen.g_ay()*1000;
00162                 CurAx = axis_Gen.g_ax()*1000;
00163                 CurAz = axis_Gen.g_az()*1000;
00164                 CurGx = axis_Gen.g_gx()*4;
00165                 CurGy = axis_Gen.g_gy()*4;
00166                 CurGz = axis_Gen.g_gz()*4; 
00167                 pc.printf("\n\nCurrentX = %f ", CurAx);
00168                 diffAy = abs(abs(CurAy)-getAy);
00169                 diffAx = abs(abs(CurAx)-getAx);
00170                 diffAz = abs(abs(CurAz)-getAz);
00171                 diffGx = abs(abs(CurGx)-getGx);
00172                 diffGy = abs(abs(CurGy)-getGy);
00173                 diffGz = abs(abs(CurGz)-getGz);
00174                 if(diffAx > 600 and diffAz < 1000 and diffAy < 200 and diffGx > 700)
00175                 { 
00176                     pc.printf("\n\n Boss 1 \n\n");
00177                     boss1 = 0;
00178                 }
00179             }
00180             boss1 = 1;   
00181         }
00182         if(get == 0 and mon2 == 0)
00183         {
00184             getAy = abs(axis_ay);
00185             getAx = abs(axis_ax);
00186             getAz = abs(axis_az);
00187             getGx = abs(axis_gx);
00188             getGy = abs(axis_gy);
00189             getGz = abs(axis_gz);
00190             while(boss2)
00191             {
00192                 pc.printf("\n\nAx = %f ", getAx);
00193                 wait(0.1);
00194                 axis_Gen.Update();
00195                 CurAy = axis_Gen.g_ay()*1000;
00196                 CurAx = axis_Gen.g_ax()*1000;
00197                 CurAz = axis_Gen.g_az()*1000;
00198                 CurGx = axis_Gen.g_gx()*4;
00199                 CurGy = axis_Gen.g_gy()*4;
00200                 CurGz = axis_Gen.g_gz()*4; 
00201                 pc.printf("\n\nCurrentX = %f ", CurAx);
00202                 diffAy = abs(abs(CurAy)-getAy);
00203                 diffAx = abs(abs(CurAx)-getAx);
00204                 diffAz = abs(abs(CurAz)-getAz);
00205                 diffGx = abs(abs(CurGx)-getGx);
00206                 diffGy = abs(abs(CurGy)-getGy);
00207                 diffGz = abs(abs(CurGz)-getGz);
00208                 if(diffAx > 200 and diffAz < 1000 and diffAy < 200 and diffGz > 500)
00209                 { 
00210                     pc.printf("\n\n Boss 2 \n\n");
00211                     boss2 = 0;
00212                 }
00213             }
00214             boss2 = 1;   
00215         }
00216         if(get == 0 and mon3 == 0)
00217         {
00218             getAy = abs(axis_ay);
00219             getAx = abs(axis_ax);
00220             getAz = abs(axis_az);
00221             getGx = abs(axis_gx);
00222             getGy = abs(axis_gy);
00223             getGz = abs(axis_gz);
00224             while(boss3)
00225             {
00226                 pc.printf("\n\nAx = %f ", getAx);
00227                 wait(0.1);
00228                 axis_Gen.Update();
00229                 CurAy = axis_Gen.g_ay()*1000;
00230                 CurAx = axis_Gen.g_ax()*1000;
00231                 CurAz = axis_Gen.g_az()*1000;
00232                 CurGx = axis_Gen.g_gx()*4;
00233                 CurGy = axis_Gen.g_gy()*4;
00234                 CurGz = axis_Gen.g_gz()*4; 
00235                 pc.printf("\n\nCurrentX = %f ", CurAx);
00236                 diffAy = abs(abs(CurAy)-getAy);
00237                 diffAx = abs(abs(CurAx)-getAx);
00238                 diffAz = abs(abs(CurAz)-getAz);
00239                 diffGx = abs(abs(CurGx)-getGx);
00240                 diffGy = abs(abs(CurGy)-getGy);
00241                 diffGz = abs(abs(CurGz)-getGz);
00242                 if(diffAx > 500 and diffAy > 500 and diffAz > 800 and diffGx > 500 and diffGy > 500 and diffGz > 500)
00243                 { 
00244                     pc.printf("\n\n Boss 3 \n\n");
00245                     boss3 = 0;
00246                 }
00247             }
00248             boss3 = 1;   
00249         }
00250      }
00251 }
00252 
00253