Coursework

Revision:
42:960c132136d9
Parent:
41:16cd48d6e834
Child:
43:c58a59e081eb
diff -r 16cd48d6e834 -r 960c132136d9 main.cpp
--- a/main.cpp	Fri Feb 04 13:30:01 2022 +0000
+++ b/main.cpp	Fri Feb 04 14:47:08 2022 +0000
@@ -46,6 +46,7 @@
 volatile int wallTotal;
 volatile int boxTotal;
 volatile int cartonTotal;
+volatile int triangleTotal;
 /**
 *..Bring in 5 arrays of 5 for each of the 5 required scans.
 *..array Ref starts at 0,
@@ -109,6 +110,7 @@
 void wallDecision();
 void boxDecision();
 void cartonDecision();
+void triangleDecision();
 int NoContinueExit();
 int buttonCountA();
 int buttonCountB();
@@ -292,13 +294,14 @@
 cout << Scan1[7];"/n";
 cout << Scan1[8];"/n";
 cout << Scan1[9];"/n";
-*/
+*//* Removing from coolterm printout
 printf("Debug : LoopCount1 : %i\n",LoopCountScan1);
 printf("Debug : LoopCount2 : %i\n",LoopCountScan2);
 printf("Debug : LoopCount3 : %i\n",LoopCountScan3);
 printf("Debug : LoopCount4 : %i\n",LoopCountScan4);
 printf("Debug : LoopCount5 : %i\n",LoopCountScan5);
 printf("press count = %i\n",g_ButtonAPress);
+*/
  printf("Scan1 1 :  %d cm\n", Scan1[0]);
   printf("Scan1 2 :  %d cm\n", Scan1[1]);
    printf("Scan1 3 :  %d cm\n", Scan1[2]);
@@ -1313,12 +1316,14 @@
         lcd.printString("Decide",0,0);
         lcd.refresh();
            NoContinueExitScan6();
- int box[5]= {90,19,19,90,90};// compared to the wall if the box is present this sequence should be recorded
- int carton[5] = {19,19,19,19,19}; // compared to the carton if the box is present this sequence should be recorded
- int wall [5] = {90,90,90,90,90}; // compared to the carton if the box is present this sequence should be recorded
+ int box[5]= {111,38,38,111,111};// compared to the wall if the box is present this sequence should be recorded
+ int carton[5] = {19,19,19,19,19}; // compared to the wall if the carton is present this sequence should be recorded
+ int wall [5] = {111,111,111,111,111}; // compared to the wall if the wall is present this sequence should be recorded
+ int triangle[5]= {111,38,19,38,111}; // compared to the wall if the triangle is present this sequence should be recorded
  int isBox[5];
  int isCarton[5];
  int isWall[5];
+ int isTriangle[5];
  //int wallTotal;
  //int cartonTotal;
  //int boxTotal;
@@ -1331,7 +1336,7 @@
 isBox[i]=1;}
 printf("DeBUGGING isBOX : %i\n", isBox[i]);
 boxTotal = accumulate(begin(isBox), end(isBox), 0, plus<int>());
-printf("DEBUGGING BOX total %i\n", boxTotal);
+//printf("DEBUGGING BOX total %i\n", boxTotal);
 
   isCarton[i] =abs(Scan1[i]-carton[i]);
    printf("DeBUGGING isCarton : %i\n", isCarton[i]);
@@ -1341,21 +1346,28 @@
 isCarton[i]=1;}
 printf("DeBUGGING isCarton : %i\n", isCarton[i]);
 cartonTotal = accumulate(begin(isCarton), end(isCarton), 0, plus<int>());
-printf("DEBUGGING CARTON total %i\n", cartonTotal);
+//printf("DEBUGGING CARTON total %i\n", cartonTotal);
 
-  isWall[i] =abs(Scan1[i]-wall[i]);
+  isWall[i] =abs(Scan1[i]-wall[i]); // calculation comparing the scan value with the model
    printf("DeBUGGING isWall : %i\n", isWall[i]);
-    if (isWall[i]<=5){
+    if (isWall[i]<=5){ // if the difference is less than 5 denote 0
     isWall[i]=0;}
-else if (isWall[i]>5){
+else if (isWall[i]>5){ //if the distance is greater than 5 denote 1
 isWall[i]=1;}
 printf("DeBUGGING isWall : %i\n", isWall[i]);
-wallTotal = accumulate(begin(isWall), end(isWall), 0, plus<int>());
-printf("DEBUGGING Wall total %i\n", wallTotal);
+wallTotal = accumulate(begin(isWall), end(isWall), 0, plus<int>()); // sum of array
+//printf("DEBUGGING Wall total %i\n", wallTotal);
 
-;}
+  isTriangle[i] =abs(Scan1[i]-triangle[i]);
+   printf("DeBUGGING isTriangle : %i\n", isTriangle[i]);
+    if (isTriangle[i]<=5){
+    isTriangle[i]=0;}
+else if (isTriangle[i]>5){
+isTriangle[i]=1;}
+printf("DeBUGGING isTriangle : %i\n", isTriangle[i]);
+triangleTotal = accumulate(begin(isTriangle), end(isTriangle), 0, plus<int>());
 
-printShape();
+printShape();}
      
         }
 /**
@@ -1364,37 +1376,49 @@
 void printShape(){
     
     if(wallTotal == 0){
- wallDecision();}
+ wallDecision();
+ return;}
      else if(boxTotal == 0){
- boxDecision();}
+ boxDecision();
+ return;}
          else if (cartonTotal == 0){
-cartonDecision();}
-    /*     else;           
-             
-         printf("Not in the Database \n");
-                  lcd.printString("Decide",0,0);
-         lcd.printString("Not in Database",0,2);
-          lcd.refresh(); */
-          
-printf("Im Free of the For Debug WallTotoal::  %i\n", wallTotal);
-printf("Im Free of the For Debug BoxTotoal::  %i\n", boxTotal);
-printf("Im Free of the For Debug cartonTotoal::  %i\n", cartonTotal);
-         }
+cartonDecision();
+return;}
+         else if (triangleTotal == 0){
+triangleDecision();
+return;}
+}
+
+
+
+         /**
+*.. Void for What to do while the Wall is in sight
+*/
  void wallDecision(){
                  printf("We Have a wall\n");
                    lcd.clear();
         lcd.printString("Decide",0,0);
         lcd.printString("Wall",0,2);
         lcd.refresh();}
+/**
+*.. Void for What to do while the Box is in sight
+*/        
 void boxDecision(){
                      printf("We Have Box\n");
          lcd.printString("Decide",0,0);
          lcd.printString("Box",0,2);
           lcd.refresh();}
-          
+/**
+*.. Void for What to do while the Carton is in sight
+*/
 void cartonDecision(){
              printf("We Have Carton\n");
          lcd.printString("Decide",0,0);
          lcd.printString("Carton",0,2);
           lcd.refresh();}
-            
\ No newline at end of file
+          
+            void triangleDecision(){
+                             printf("We Have Triangle\n");
+         lcd.printString("Decide",0,0);
+         lcd.printString("Triangle",0,2);
+          lcd.refresh();}
\ No newline at end of file