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.
Dependencies: mbed 3875_Individualproject
Diff: main/main.cpp
- Revision:
- 24:adb946be4ce5
- Parent:
- 23:71e84953b3f3
- Child:
- 25:7523239a2fc1
--- a/main/main.cpp Wed Apr 08 21:57:10 2020 +0000 +++ b/main/main.cpp Thu Apr 09 00:52:46 2020 +0000 @@ -1,4 +1,5 @@ #include "main.h" +#include <math.h> // API m3pi robot; @@ -159,7 +160,7 @@ void looped() { - if(first) { // init the start node + if( first ) { // init the start node on first loop run only first = false; curr_coords[0] = 0; curr_coords[1] = 0; @@ -168,14 +169,13 @@ point[total_points] = total_points; coords_x[total_points] = curr_coords[0]; coords_y[total_points] = curr_coords[1]; - type[total_points] = 0b1000; - explored[total_points = 0b0000; // not sure if i set this as explored already or whether i do that at the next junction + type[total_points] = 0b1000; // start is always 1 exit type in the north direction + explored[total_points] = 0b0000; // not sure if i set this as explored already or whether i do that at the next junction looped_path[total_points] = 0; // start node is '0' - //total_points++; } // follow line until reaching a junction, determine its type and coordinates - if (t_restart){ // only start the timer if it isnt already started + if ( t_restart ){ // only start the timer if it isnt already started t_coord.start(); t_restart = false; } @@ -183,13 +183,13 @@ follow_line(); if ( junction_detect() ) { - path_length++; // index to path position + path_length++; // increment the path position index float time = t_coord.read(); - int dist_est = round(time); + int dist_est = floor(time); t_coord.stop(); t_coord.reset(); - t_restart = true; //restart the timer + t_restart = true; //restart the timer next loop if (dir == 'N'){ curr_coords[1] += dist_est; } // y coord if (dir == 'E'){ curr_coords[0] += dist_est; } // x coord @@ -199,18 +199,17 @@ // check that the coordinates are not already in the list, if not add the point, if it is already return the point number and increment the explored if (coord_check()) { // coord_check returns true if curr_coords coordinates are not present in (should set a variable as true) total_points++; - point[total_points] = total_points; // numbered 1 -> x + point[total_points] = total_points; // numbered 0 -> total_points coords_x[total_points] = curr_coords[0]; coords_y[total_points] = curr_coords[1]; node_logic(); // determines what junction type we are at updates the explored (path entered on) and type arrays accordingly - // update type and explored aswell might need to be done in node logic } // use current coords to find which point to place in path looped_path[path_length] = coord_to_node(); //returns an int of which point we are at what its called choose_turn(); //looks at the point we are at, examines the type vs explored and makes the appropriate turn also updates the explored - check_explored(); // iterates through all existing points, if all explored match type, then mapping is complete + // check_explored(); // iterates through all existing points, if all explored match type, then mapping is complete // if not, make a func that traverses back through the bath until reaching that node, then explore the unexplored path // assign new node with new coordinates @@ -262,11 +261,12 @@ } } - return point[i]; + return point[result]; } void node_logic() { + // is done when a new node is discovered, needs to update the nodes type and the path explored upon entry bool north = false; bool south = false; bool east = false; @@ -372,9 +372,7 @@ void choose_turn() { - // compares the type to the explored (type - explored), then uses that as an index for the struct of the turn order priority (turn_order[3] = {'E' , 'N', 'W', 'S'} - // also takes into account current direction (if facing north, it wont take the south path for example) - // do this in point type + // looks at the type vs the explored and does the turn that is equivalent to the first 1 in type that is a 0 in explored (WNES priority) }