James Heavey / Mbed 2 deprecated 3875_DISSERTATION

Dependencies:   mbed 3875_Individualproject

Committer:
jamesheavey
Date:
Fri Apr 17 13:20:19 2020 +0000
Revision:
48:76cf4521d342
Parent:
41:2b6b73dd897c
Child:
51:3148875bb9e5
dead end removal works, going to use it for bt instead, then can set start as unexplored

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jamesheavey 0:df5216b20861 1 #ifndef MAIN_H
jamesheavey 0:df5216b20861 2 #define MAIN_H
jamesheavey 0:df5216b20861 3
jamesheavey 0:df5216b20861 4 #include "m3pi.h"
jamesheavey 0:df5216b20861 5 #include "mbed.h"
jamesheavey 29:ecf497c3fdc0 6 #include <stdlib.h>
jamesheavey 20:5cf6a378801d 7
jamesheavey 20:5cf6a378801d 8 // Constants
jamesheavey 20:5cf6a378801d 9 #define A 0.5 // 20
jamesheavey 20:5cf6a378801d 10 #define B 1/10000 // 10000
jamesheavey 20:5cf6a378801d 11 #define C 1.5 // 2/3
jamesheavey 20:5cf6a378801d 12
jamesheavey 20:5cf6a378801d 13 #define SENS_THRESH 500 // >500 = black
jamesheavey 20:5cf6a378801d 14 #define TURN_SPEED 0.2
jamesheavey 0:df5216b20861 15
jamesheavey 0:df5216b20861 16 // API
jamesheavey 0:df5216b20861 17 extern m3pi robot;
jamesheavey 0:df5216b20861 18
jamesheavey 0:df5216b20861 19 // LEDs
jamesheavey 0:df5216b20861 20 extern BusOut leds;
jamesheavey 0:df5216b20861 21
jamesheavey 0:df5216b20861 22 // Buttons
jamesheavey 0:df5216b20861 23 extern DigitalIn button_A;
jamesheavey 0:df5216b20861 24 extern DigitalIn button_B;
jamesheavey 0:df5216b20861 25 extern DigitalIn button_X;
jamesheavey 0:df5216b20861 26 extern DigitalIn button_Y;
jamesheavey 0:df5216b20861 27 extern DigitalIn button_enter;
jamesheavey 0:df5216b20861 28 extern DigitalIn button_back;
jamesheavey 0:df5216b20861 29
jamesheavey 0:df5216b20861 30 // Potentiometers
jamesheavey 0:df5216b20861 31 extern AnalogIn pot_P;
jamesheavey 0:df5216b20861 32 extern AnalogIn pot_I;
jamesheavey 0:df5216b20861 33 extern AnalogIn pot_D;
jamesheavey 0:df5216b20861 34 extern AnalogIn pot_S;
jamesheavey 0:df5216b20861 35
jamesheavey 18:991658b628fc 36 // Sensors
jamesheavey 18:991658b628fc 37 extern DigitalInOut QTRA; //connected to digital P26
jamesheavey 18:991658b628fc 38 extern DigitalInOut QTRB; //connected to digital P25
jamesheavey 18:991658b628fc 39
jamesheavey 20:5cf6a378801d 40 // Timers
jamesheavey 21:54ea75f7984f 41 Timer t_L; // left encoder
jamesheavey 21:54ea75f7984f 42 Timer t_R; // right encoder
jamesheavey 21:54ea75f7984f 43 Timer t_coord; // coordinate timer
jamesheavey 0:df5216b20861 44
jamesheavey 0:df5216b20861 45 // Prototypes
jamesheavey 21:54ea75f7984f 46
jamesheavey 20:5cf6a378801d 47 void read_encoders();
jamesheavey 20:5cf6a378801d 48 void init();
jamesheavey 20:5cf6a378801d 49 void calibrate();
jamesheavey 20:5cf6a378801d 50 void follow_line();
jamesheavey 20:5cf6a378801d 51 bool junction_detect();
jamesheavey 20:5cf6a378801d 52 char junction_logic();
jamesheavey 20:5cf6a378801d 53 void turn_select( char turn );
jamesheavey 20:5cf6a378801d 54 void left();
jamesheavey 20:5cf6a378801d 55 void right();
jamesheavey 20:5cf6a378801d 56 void back();
jamesheavey 20:5cf6a378801d 57 void goal();
jamesheavey 29:ecf497c3fdc0 58 void looped_goal();
jamesheavey 20:5cf6a378801d 59 void simplify();
jamesheavey 20:5cf6a378801d 60 void invert_path();
jamesheavey 20:5cf6a378801d 61 void non_looped();
jamesheavey 20:5cf6a378801d 62 void looped();
jamesheavey 21:54ea75f7984f 63 void node_logic();
jamesheavey 24:adb946be4ce5 64 bool coord_check();
jamesheavey 25:7523239a2fc1 65 void update_index();
jamesheavey 28:63ff8290964a 66 void choose_turn();
jamesheavey 28:63ff8290964a 67 void back_track();
jamesheavey 29:ecf497c3fdc0 68 int path_to_point_index( int path_point );
jamesheavey 37:2967f3f9c936 69 void print_data( char *word );
jamesheavey 48:76cf4521d342 70 void dead_end_removal(int index1, int index2);
jamesheavey 0:df5216b20861 71
jamesheavey 20:5cf6a378801d 72 // Global Variables
jamesheavey 20:5cf6a378801d 73 char path[100];
jamesheavey 20:5cf6a378801d 74 char inv_path[100];
jamesheavey 20:5cf6a378801d 75 int path_length = 0;
jamesheavey 20:5cf6a378801d 76 unsigned int *sensor;
jamesheavey 20:5cf6a378801d 77 float speed;
jamesheavey 20:5cf6a378801d 78 float proportional = 0.0;
jamesheavey 20:5cf6a378801d 79 float prev_proportional = 0.0;
jamesheavey 20:5cf6a378801d 80 float integral = 0.0;
jamesheavey 20:5cf6a378801d 81 float derivative = 0.0;
jamesheavey 20:5cf6a378801d 82 int encoder[2];
jamesheavey 20:5cf6a378801d 83 int dist_est_1 = 0;
jamesheavey 20:5cf6a378801d 84 int dist_est_2 = 0;
jamesheavey 0:df5216b20861 85
jamesheavey 41:2b6b73dd897c 86 bool loop_check;
jamesheavey 38:b5b06625d06e 87 int dist = 0;
jamesheavey 23:71e84953b3f3 88 bool first = true;
jamesheavey 27:0a3f028f9365 89 bool goal_node = false;
jamesheavey 21:54ea75f7984f 90 bool t_restart = true;
jamesheavey 23:71e84953b3f3 91 char dir;
jamesheavey 25:7523239a2fc1 92 int curr_index;
jamesheavey 21:54ea75f7984f 93 int curr_coords[2];
jamesheavey 23:71e84953b3f3 94 int total_points;
jamesheavey 24:adb946be4ce5 95 unsigned int looped_path[100];
jamesheavey 27:0a3f028f9365 96 unsigned int point[100]; // use a struct
jamesheavey 22:02dda79d50b4 97 unsigned int type[100];
jamesheavey 22:02dda79d50b4 98 unsigned int explored[100];
jamesheavey 21:54ea75f7984f 99 int coords_x[100];
jamesheavey 21:54ea75f7984f 100 int coords_y[100];
jamesheavey 48:76cf4521d342 101 int shortest[100];
jamesheavey 0:df5216b20861 102 #endif