Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 47:e992a129ef44
- Parent:
- 46:7a0933676b13
- Child:
- 48:553716e13d45
--- a/main.cpp Mon Jun 18 14:48:13 2018 +0000 +++ b/main.cpp Mon Jun 18 22:46:49 2018 +0000 @@ -295,6 +295,9 @@ Train DR_train(true); //Position and going_cw Train LR_train(true); +//possibility of an array having {dr_train, lr_train}? for reuse and modularity of functions + + /** *Booleans that will determine if the train should be moving or not. *Booleans will switch to false to stop any of the trains and avoid collisions. @@ -323,7 +326,9 @@ /** * -* +*Initializes every position's vectors (prev_cw and prev_ccw) with the corresponding sensors. +*prev_cw - Sensors previous to the current in clockwise sense. +*prev_ccw - Sensors previous to the current in counter-clockwise sense. * **/ void init_positions(){ @@ -428,6 +433,9 @@ * *Returns the number of the sensor where the train was detected. * +*@number - +*@interrupt - +* **/ int get_sensor(unsigned int number,int interrupt){ @@ -452,7 +460,10 @@ /** * +*Checks if the element exists within the vector. * +*@v - The vector (of ints) the method will go through. +*@element - The element the method will look for. * **/ bool in_vector(vector<int>v,int element){ @@ -465,16 +476,18 @@ exist = true; } - } - + } return exist; } /** -* Check if there is an avodable frontal collision: -* Both trains in area A or B with different direction -* Trains in (D11 and D5) or (D9 and D3) with same direction +*This method will checks if there is a non-avoidable frontal collision(NAFC). +*A NAFC will happen if: +* +*Both trains in area A or B with different direction +*Trains in (D11 and D5) or (D9 and D3) with same direction +* */ bool check_NAC(bool DR_in_A, bool DR_in_B,bool LR_in_A,bool LR_in_B){ @@ -499,17 +512,20 @@ NAC = true; } } - return NAC; } /** -* Check if there is an Avoidable Frontal Collision -* Train in area A(ccw) and train in D4(cw) -* Train in area A(cw) and train in D10(ccw) -* Train in area B(cw) and train in D4(ccw) -* Train in area B(ccw) and train in D10(ccw) +* +*CThe function will check if there is an Avoidable Frontal Collision (AFC). +*AFC will occur if: +* +*Train in area A(ccw) and train in D4(cw) +*Train in area A(cw) and train in D10(ccw) +*Train in area B(cw) and train in D4(ccw) +*Train in area B(ccw) and train in D10(ccw) +* **/ bool check_AFC(bool DR_in_A, bool DR_in_B,bool LR_in_A,bool LR_in_B){ //TODO - Add same for LR train @@ -558,24 +574,27 @@ /** * -* +*The method check_position will check if any of the trains is in any of the areas. +*It will go through all the area vectors (A,B) and call the function in_vector to check inside the vectors. * **/ void check_position(){ bool DR_in_A, DR_in_B, LR_in_A, LR_in_B; - DR_in_A=in_vector(area_A,DR_train.get_position_number()); //Check if DR train is in area A - DR_in_B=in_vector(area_B,DR_train.get_position_number()); - LR_in_A=in_vector(area_A,LR_train.get_position_number()); - LR_in_B=in_vector(area_B,LR_train.get_position_number()); + DR_in_A = in_vector(area_A,DR_train.get_position_number()); //Check if DR train is in area A + DR_in_B = in_vector(area_B,DR_train.get_position_number()); + LR_in_A = in_vector(area_A,LR_train.get_position_number()); + LR_in_B = in_vector(area_B,LR_train.get_position_number()); } /** * +*Description * +*@sensor - * **/ void update_train_pos(int sensor){ @@ -708,10 +727,10 @@ /** * -* +*Clear current interrupts * **/ -void init() { // Clear current interrupts +void init() { mcp->_read(GPIOA); mcp->_read(GPIOB); // Register callbacks