ft. button press reset
Dependencies: mbed
Fork of BeaconDemo_RobotCodeNew by
Diff: main.cpp
- Revision:
- 6:ff3c66f7372b
- Parent:
- 4:25039ea5eb09
- Child:
- 7:ef9ab01b9e26
--- a/main.cpp Tue Oct 13 11:47:14 2015 +0000 +++ b/main.cpp Thu Oct 22 00:46:14 2015 +0000 @@ -1,4 +1,4 @@ -/*********************************************************************** +/*********************************************************************** ** ██████╗ ███████╗██╗███████╗██╗ ██╗ █████╗ ██████╗ ███╗ ███╗ ** ** ██╔══██╗██╔════╝██║██╔════╝██║ ██║██╔══██╗██╔══██╗████╗ ████║ ** ** ██████╔╝███████╗██║███████╗██║ █╗ ██║███████║██████╔╝██╔████╔██║ ** @@ -9,55 +9,93 @@ **(C) Dr James Hilder - York Robotics Laboratory - University of York ** ***********************************************************************/ -/// PsiSwarm Example Main File +/// PsiSwarm Beautiful Meme Project Source Code +/// Version 0.1 +/// James Hilder, Alan Millard, Homero Elizondo, Jon Timmis +/// University of York /// Include psiswarm.h - this includes all the other necessary core files #include "psiswarm.h" -/// Use these variables to store the name for the program, the author and the version -/// NB: Keep the strings as short as possible (ie 12 chars or less) to ensure reliable comms and readability on display -char * program_name = "Blank"; +// IMPORTANT!!! +// Do not call the IR functions at all as they will interfere with the correct operation of this program +// Instead, use the values held in the variables below; they are updated every 500ms + +char beacon_found = 0; // This will be a 1 when a beacon was detected during the previous 500ms window +int beacon_heading = 0; // This is the heading from the last time a beacon was detected +char robots_found[8]; // These will be a 1 when the respective robot [excluding self] was detected during the previous 500ms window +char robots_heading[8]; // These are the headings from the last time the respective robots were detected +unsigned short robots_distance[8]; // This is the maximum sensor value from the last time the respective robot was detected +unsigned short reflected_sensor_data[8]; // The reflected IR values when this robots emitters are on +unsigned short background_sensor_data[8];// The raw IR values when no robot (or beacon) should have its IR on + +char * program_name = "B-Meme"; char * author_name = "YRL"; char * version_name = "1.0"; -// Place user variables here +char user_code_debug = 1; // Set to 1 to show terminal messages from "out" function [specific to this code] ///Place user code here that should be run after initialisation but before the main loop -void user_code_setup(){ +void user_code_setup() +{ + out("------------------------------------------------------\n"); + out("Beautiful Meme Project Demo Code \n"); + out("------------------------------------------------------\n"); + locate_beacon(); + while(beacon_found == 0) { + locate_beacon(); + } - pc.printf("User setup code block\n"); + start_infrared_timers(); } ///This function is the loop where user code should be placed -void user_code_loop(){ +void user_code_loop() +{ ///Do not place code within a loop, but consider this function to be a loop that is always run ///unless the user code is externally paused (such as by debug or recharging system) - - pc.printf("User loop code block\n"); - wait(1); + + //pc.printf("User loop code block\n"); + + + wait(0.5); } /// Code goes here to handle what should happen when the user switch is pressed void handle_switch_event(char switch_state) { - /// 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 + /// 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 /// NB For maximum compatability it is recommended to minimise reliance on center button press - - pc.printf("User switch code block: %d\n",switch_state); + + //pc.printf("User switch code block: %d\n",switch_state); } /// The main routine: it is recommended to leave this function alone and add user code to the above functions -int main() { +int main() +{ ///init() in psiswarm.cpp sets up the robot init(); user_code_setup(); user_code_running = 1; while(1) { - if(user_code_running)user_code_loop(); - if(demo_on) demo_mode(); - //wait_us(5); + if(user_code_running)user_code_loop(); + if(demo_on) demo_mode(); + //wait_us(5); + } +} + +/// Verbose output +void out(const char* format, ...) +{ + char buffer[256]; + if (debug_mode) { + va_list vl; + va_start(vl, format); + vsprintf(buffer,format,vl); + if(user_code_debug == 1) pc.printf("%s", buffer); + va_end(vl); } } \ No newline at end of file