Denver / Mbed 2 deprecated denver_train_proj

Dependencies:   mbed TextLCD

Revision:
68:9859a3ff9298
Parent:
67:7ff2425141ce
Child:
69:609c69e91b4e
--- a/main.cpp	Tue Jun 26 12:56:54 2018 +0000
+++ b/main.cpp	Tue Jun 26 14:22:47 2018 +0000
@@ -886,6 +886,24 @@
     
 }
 
+/**
+* Switch_n switch that needs to switch
+* cont_sensor sensor that when activated the stopped train continues
+* switch_sensor sensor where the switch should be activated
+*/
+void ALC_action(int cont_sensor, Train *stop_train, Train * cont_train ){
+    
+    //flip_switch(switch_n,5);
+    
+    while(cont_train->get_position_number() != cont_sensor){
+
+        stop_train->set_speed(STOP);
+        stop_train->run(); //Stopping train on sensor D4 or D10
+        cont_train->run();
+    }    
+    
+    stop_train->set_speed(MEDIUM);
+}
 
 
 /**
@@ -960,8 +978,66 @@
                 detected_AFC = true;
             }
         }
+    }else if(stop_train->get_position_number() == D9){
+    
+        if(stop_train->goes_cw()){
+            
+            if(cont_train->is_in_B() && !cont_train->goes_cw()){
+                
+                lcd.cls();
+                lcd.printf("AFC!!! STOP D9 CONT D8");
+                AFC_action(5, D10, D4, stop_train, cont_train);
+                //train in 9 stops
+                //when cont_train is at d10 stop train continues
+                detected_AFC = true;
+            }
+        }
+    
+    }else if(stop_train->get_position_number() == D11){
+        
+        if(!stop_train->goes_cw()){
+            
+            if(cont_train->is_in_A() && cont_train->goes_cw()){
+                
+                lcd.cls();
+                lcd.printf("AFC!!! STOP D11 CONT D12");
+                AFC_action(5, D10, D4, stop_train, cont_train);
+                //train in 11 stops
+                //when cont_train is at d10 stop train continues
+                detected_AFC = true;
+            }
+        }
+        
+    }else if(stop_train->get_position_number() == D3){
+
+        if(stop_train->goes_cw()){
+            
+            if(cont_train->is_in_A() && !cont_train->goes_cw()){
+                
+                lcd.cls();
+                lcd.printf("AFC!!! STOP D3 CONT D14");
+                AFC_action(5, D4, D10, stop_train, cont_train);
+                //train in 3 stops
+                //when cont_train is at d4 stop train continues
+                detected_AFC = true;
+            }
+        }
+        
+    }else if(stop_train->get_position_number() == D5){
+        
+        if(!stop_train->goes_cw()){
+            
+            if(cont_train->is_in_B() && cont_train->goes_cw()){
+                
+                lcd.cls();
+                lcd.printf("AFC!!! STOP D5 CONT D6");
+                AFC_action(5, D4, D10, stop_train, cont_train);
+                //train in 5 stops
+                //when cont_train is at d4 stop train continues
+                detected_AFC = true;
+            }
+        }
     }
-    
     return detected_AFC;
 }
 
@@ -970,7 +1046,7 @@
 *
 *
 *
-**//**
+**/
 bool check_ALC(Train *stop_train, Train *cont_train){   //TODO - Add same for LR train
 
     bool detected_ALC = false;
@@ -983,7 +1059,7 @@
                     lcd.cls();
                     lcd.printf("ALC!!! STOP D4 CONT D3");
                     
-                    ALC_action(14, stop_train, cont_train ) 
+                    ALC_action(2, stop_train, cont_train ); 
                     //When cont_train is at D22 stop_train continues
                 
                 detected_ALC = true;
@@ -993,12 +1069,12 @@
                 if(cont_train->get_position_number() == D5 && !cont_train->goes_cw()){
                     
                     lcd.cls();
-                    lcd.printf("AFC!!! STOP D4 SW3 CONT D5");
+                    lcd.printf("ALC!!! STOP D4 SW3 CONT D5");
                     
-                    ALC_action(6, stop_train, cont_train ) 
+                    ALC_action(7, stop_train, cont_train ); 
                     //Train stops
                     //When CONT is at D6 DR continues
-                    detected_AFC = true;
+                    detected_ALC = true;
                 }
             }
             
@@ -1009,49 +1085,31 @@
             if(cont_train->get_position_number() == D9 && cont_train->goes_cw()){
                 
                 lcd.cls();
-                lcd.printf("AFC!!! STOP D10 CONT D9");
+                lcd.printf("ALC!!! STOP D10 CONT D9");
                 
-                ALC_action(8, stop_train, cont_train ) 
+                ALC_action(8, stop_train, cont_train ); 
                 //D10 train stops
                 //When CONT is at D8, D10 continues
-                detected_AFC = true;
+                detected_ALC = true;
             }
         }else{
             
             if(cont_train->get_position_number() == D11 && !cont_train->goes_cw()){
                 
                 lcd.cls();
-                lcd.printf("AFC!!! STOP D10 CONT D11");
+                lcd.printf("ALC!!! STOP D10 CONT D11");
                 
-                ALC_action(12, stop_train, cont_train ) 
+                ALC_action(12, stop_train, cont_train ); 
                 //D10 train stops
                 //When CONT is at D12, D10 continues
-                detected_AFC = true;
+                detected_ALC = true;
             }
         }
     }
     
     return detected_ALC;
 }
-**/
 
-/**
-* Switch_n switch that needs to switch
-* cont_sensor sensor that when activated the stopped train continues
-* switch_sensor sensor where the switch should be activated
-*//**
-void ALC_action(int cont_sensor, Train *stop_train, Train * cont_train ){
-    
-    //flip_switch(switch_n,5);
-    
-    while(cont_train->get_position_number() != cont_sensor){
-
-        stop_train->set_speed(STOP);
-        stop_train->run(); //Stopping train on sensor D4 or D10
-        cont_train->run();
-    }    
-}
-**/
 
 /**
 *
@@ -1066,9 +1124,11 @@
         //lcd.printf("NAC!!!");
         NAC_action();
     }
-    //check_AFC(&DR_train,&LR_train);       
-        
-    //check_AFC(&LR_train,&DR_train);
+    check_AFC(&DR_train,&LR_train);       
+    check_AFC(&LR_train,&DR_train);
+    check_ALC(&LR_train,&DR_train);
+    check_ALC(&DR_train,&LR_train);
+
             
     
 }
@@ -1411,13 +1471,13 @@
     init();
        
     
-    int DR_init_sensor = select_sensor(D9,"DR");
+    int DR_init_sensor = select_sensor(D6,"DR");
     bool DR_init_dir = select_direction(true,"DR");
     
     wait(0.5);
     
-    int LR_init_sensor = select_sensor(D9,"LR");
-    bool LR_init_dir = select_direction(false,"LR");
+    int LR_init_sensor = select_sensor(D3,"LR");
+    bool LR_init_dir = select_direction(true,"LR");
     
     DR_train.set_position(DR_init_sensor);
     DR_train.set_goes_cw(DR_init_dir);