ft. button press reset
Dependencies: mbed
Fork of BeaconDemo_RobotCodeNew by
main.cpp@3:cd048f6e544e, 2015-10-05 (annotated)
- Committer:
- jah128
- Date:
- Mon Oct 05 20:42:37 2015 +0000
- Revision:
- 3:cd048f6e544e
- Parent:
- 2:a6214fd156ff
- Child:
- 4:25039ea5eb09
Added crude line following code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jah128 | 0:8a5497a2e366 | 1 | /*********************************************************************** |
jah128 | 0:8a5497a2e366 | 2 | ** ██████╗ ███████╗██╗███████╗██╗ ██╗ █████╗ ██████╗ ███╗ ███╗ ** |
jah128 | 0:8a5497a2e366 | 3 | ** ██╔══██╗██╔════╝██║██╔════╝██║ ██║██╔══██╗██╔══██╗████╗ ████║ ** |
jah128 | 0:8a5497a2e366 | 4 | ** ██████╔╝███████╗██║███████╗██║ █╗ ██║███████║██████╔╝██╔████╔██║ ** |
jah128 | 0:8a5497a2e366 | 5 | ** ██╔═══╝ ╚════██║██║╚════██║██║███╗██║██╔══██║██╔══██╗██║╚██╔╝██║ ** |
jah128 | 0:8a5497a2e366 | 6 | ** ██║ ███████║██║███████║╚███╔███╔╝██║ ██║██║ ██║██║ ╚═╝ ██║ ** |
jah128 | 0:8a5497a2e366 | 7 | ** ╚═╝ ╚══════╝╚═╝╚══════╝ ╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ** |
jah128 | 0:8a5497a2e366 | 8 | ************************************************************************ |
jah128 | 0:8a5497a2e366 | 9 | **(C) Dr James Hilder - York Robotics Laboratory - University of York ** |
jah128 | 0:8a5497a2e366 | 10 | ***********************************************************************/ |
jah128 | 0:8a5497a2e366 | 11 | |
jah128 | 1:f6356cf1cefc | 12 | /// PsiSwarm Example Main File |
jah128 | 0:8a5497a2e366 | 13 | |
jah128 | 1:f6356cf1cefc | 14 | /// Include psiswarm.h - this includes all the other necessary core files |
jah128 | 0:8a5497a2e366 | 15 | #include "psiswarm.h" |
jah128 | 0:8a5497a2e366 | 16 | |
jah128 | 1:f6356cf1cefc | 17 | /// Use these variables to store the name for the program, the author and the version |
jah128 | 1:f6356cf1cefc | 18 | /// NB: Keep the strings as short as possible (ie 12 chars or less) to ensure reliable comms and readability on display |
jah128 | 0:8a5497a2e366 | 19 | char * program_name = "Example"; |
jah128 | 0:8a5497a2e366 | 20 | char * author_name = "JAH-YRL"; |
jah128 | 1:f6356cf1cefc | 21 | char * version_name = "1.0"; |
jah128 | 0:8a5497a2e366 | 22 | |
jah128 | 0:8a5497a2e366 | 23 | // Place user variables here |
jah128 | 0:8a5497a2e366 | 24 | |
jah128 | 2:a6214fd156ff | 25 | //char green = 3; |
jah128 | 0:8a5497a2e366 | 26 | |
jah128 | 1:f6356cf1cefc | 27 | ///Place user code here that should be run after initialisation but before the main loop |
jah128 | 0:8a5497a2e366 | 28 | void user_code_setup(){ |
jah128 | 0:8a5497a2e366 | 29 | |
jah128 | 0:8a5497a2e366 | 30 | /* |
jah128 | 0:8a5497a2e366 | 31 | wait(2); |
jah128 | 0:8a5497a2e366 | 32 | calibrate_base_ir_sensors(); |
jah128 | 0:8a5497a2e366 | 33 | wait(2); |
jah128 | 0:8a5497a2e366 | 34 | */ |
jah128 | 0:8a5497a2e366 | 35 | } |
jah128 | 0:8a5497a2e366 | 36 | |
jah128 | 1:f6356cf1cefc | 37 | ///This function is the loop where user code should be placed |
jah128 | 1:f6356cf1cefc | 38 | void user_code_loop(){ |
jah128 | 3:cd048f6e544e | 39 | store_line_position(); |
jah128 | 1:f6356cf1cefc | 40 | ///Do not place code within a loop, but consider this function to be a loop that is always run |
jah128 | 1:f6356cf1cefc | 41 | ///unless the user code is externally paused (such as by debug or recharging system) |
jah128 | 0:8a5497a2e366 | 42 | |
jah128 | 3:cd048f6e544e | 43 | if(line_found == 1)pc.printf("%f\n",line_position); |
jah128 | 3:cd048f6e544e | 44 | wait(0.25); |
jah128 | 0:8a5497a2e366 | 45 | } |
jah128 | 0:8a5497a2e366 | 46 | |
jah128 | 0:8a5497a2e366 | 47 | |
jah128 | 1:f6356cf1cefc | 48 | /// Code goes here to handle what should happen when the user switch is pressed |
jah128 | 0:8a5497a2e366 | 49 | void handle_switch_event(char switch_state) |
jah128 | 0:8a5497a2e366 | 50 | { |
jah128 | 1:f6356cf1cefc | 51 | /// Switch_state = 1 if up is pressed, 2 if down is pressed, 4 if left is pressed, 8 if right is pressed and 16 if the center button is pressed |
jah128 | 1:f6356cf1cefc | 52 | /// NB For maximum compatability it is recommended to minimise reliance on center button press |
jah128 | 0:8a5497a2e366 | 53 | } |
jah128 | 0:8a5497a2e366 | 54 | |
jah128 | 1:f6356cf1cefc | 55 | /// The main routine: it is recommended to leave this function alone and add user code to the above functions |
jah128 | 0:8a5497a2e366 | 56 | int main() { |
jah128 | 1:f6356cf1cefc | 57 | ///init() in psiswarm.cpp sets up the robot |
jah128 | 0:8a5497a2e366 | 58 | init(); |
jah128 | 0:8a5497a2e366 | 59 | user_code_setup(); |
jah128 | 0:8a5497a2e366 | 60 | user_code_running = 1; |
jah128 | 0:8a5497a2e366 | 61 | while(1) { |
jah128 | 0:8a5497a2e366 | 62 | if(user_code_running)user_code_loop(); |
jah128 | 0:8a5497a2e366 | 63 | if(demo_on) demo_mode(); |
jah128 | 0:8a5497a2e366 | 64 | wait_us(250); |
jah128 | 0:8a5497a2e366 | 65 | } |
jah128 | 0:8a5497a2e366 | 66 | } |