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
main/main.h@20:5cf6a378801d, 2020-03-24 (annotated)
- Committer:
- jamesheavey
- Date:
- Tue Mar 24 14:20:32 2020 +0000
- Revision:
- 20:5cf6a378801d
- Parent:
- 18:991658b628fc
- Child:
- 21:54ea75f7984f
pre loop code reorg save
Who changed what in which revision?
User | Revision | Line number | New 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 | 20:5cf6a378801d | 6 | |
jamesheavey | 20:5cf6a378801d | 7 | // Constants |
jamesheavey | 20:5cf6a378801d | 8 | #define A 0.5 // 20 |
jamesheavey | 20:5cf6a378801d | 9 | #define B 1/10000 // 10000 |
jamesheavey | 20:5cf6a378801d | 10 | #define C 1.5 // 2/3 |
jamesheavey | 20:5cf6a378801d | 11 | |
jamesheavey | 20:5cf6a378801d | 12 | #define SENS_THRESH 500 // >500 = black |
jamesheavey | 20:5cf6a378801d | 13 | #define TURN_SPEED 0.2 |
jamesheavey | 0:df5216b20861 | 14 | |
jamesheavey | 0:df5216b20861 | 15 | // API |
jamesheavey | 0:df5216b20861 | 16 | extern m3pi robot; |
jamesheavey | 0:df5216b20861 | 17 | |
jamesheavey | 0:df5216b20861 | 18 | // LEDs |
jamesheavey | 0:df5216b20861 | 19 | extern BusOut leds; |
jamesheavey | 0:df5216b20861 | 20 | |
jamesheavey | 0:df5216b20861 | 21 | // Buttons |
jamesheavey | 0:df5216b20861 | 22 | extern DigitalIn button_A; |
jamesheavey | 0:df5216b20861 | 23 | extern DigitalIn button_B; |
jamesheavey | 0:df5216b20861 | 24 | extern DigitalIn button_X; |
jamesheavey | 0:df5216b20861 | 25 | extern DigitalIn button_Y; |
jamesheavey | 0:df5216b20861 | 26 | extern DigitalIn button_enter; |
jamesheavey | 0:df5216b20861 | 27 | extern DigitalIn button_back; |
jamesheavey | 0:df5216b20861 | 28 | |
jamesheavey | 0:df5216b20861 | 29 | // Potentiometers |
jamesheavey | 0:df5216b20861 | 30 | extern AnalogIn pot_P; |
jamesheavey | 0:df5216b20861 | 31 | extern AnalogIn pot_I; |
jamesheavey | 0:df5216b20861 | 32 | extern AnalogIn pot_D; |
jamesheavey | 0:df5216b20861 | 33 | extern AnalogIn pot_S; |
jamesheavey | 0:df5216b20861 | 34 | |
jamesheavey | 18:991658b628fc | 35 | // Sensors |
jamesheavey | 18:991658b628fc | 36 | extern DigitalInOut QTRA; //connected to digital P26 |
jamesheavey | 18:991658b628fc | 37 | extern DigitalInOut QTRB; //connected to digital P25 |
jamesheavey | 18:991658b628fc | 38 | |
jamesheavey | 20:5cf6a378801d | 39 | // Timers |
jamesheavey | 20:5cf6a378801d | 40 | Timer t_L; |
jamesheavey | 20:5cf6a378801d | 41 | Timer t_R; |
jamesheavey | 0:df5216b20861 | 42 | |
jamesheavey | 0:df5216b20861 | 43 | // Prototypes |
jamesheavey | 20:5cf6a378801d | 44 | void read_encoders(); |
jamesheavey | 20:5cf6a378801d | 45 | void init(); |
jamesheavey | 20:5cf6a378801d | 46 | void calibrate(); |
jamesheavey | 20:5cf6a378801d | 47 | void follow_line(); |
jamesheavey | 20:5cf6a378801d | 48 | bool junction_detect(); |
jamesheavey | 20:5cf6a378801d | 49 | char junction_logic(); |
jamesheavey | 20:5cf6a378801d | 50 | void turn_select( char turn ); |
jamesheavey | 20:5cf6a378801d | 51 | void left(); |
jamesheavey | 20:5cf6a378801d | 52 | void right(); |
jamesheavey | 20:5cf6a378801d | 53 | void back(); |
jamesheavey | 20:5cf6a378801d | 54 | void goal(); |
jamesheavey | 20:5cf6a378801d | 55 | void simplify(); |
jamesheavey | 20:5cf6a378801d | 56 | void invert_path(); |
jamesheavey | 20:5cf6a378801d | 57 | void non_looped(); |
jamesheavey | 20:5cf6a378801d | 58 | void looped(); |
jamesheavey | 0:df5216b20861 | 59 | |
jamesheavey | 20:5cf6a378801d | 60 | // Global Variables |
jamesheavey | 20:5cf6a378801d | 61 | char path[100]; |
jamesheavey | 20:5cf6a378801d | 62 | char inv_path[100]; |
jamesheavey | 20:5cf6a378801d | 63 | int path_length = 0; |
jamesheavey | 20:5cf6a378801d | 64 | unsigned int *sensor; |
jamesheavey | 20:5cf6a378801d | 65 | float speed; |
jamesheavey | 20:5cf6a378801d | 66 | float proportional = 0.0; |
jamesheavey | 20:5cf6a378801d | 67 | float prev_proportional = 0.0; |
jamesheavey | 20:5cf6a378801d | 68 | float integral = 0.0; |
jamesheavey | 20:5cf6a378801d | 69 | float derivative = 0.0; |
jamesheavey | 20:5cf6a378801d | 70 | int encoder[2]; |
jamesheavey | 20:5cf6a378801d | 71 | int dist_est_1 = 0; |
jamesheavey | 20:5cf6a378801d | 72 | int dist_est_2 = 0; |
jamesheavey | 0:df5216b20861 | 73 | |
jamesheavey | 0:df5216b20861 | 74 | #endif |