YRL Maze lab made more script-y

Dependencies:   PsiSwarmLab-ScriptingBased mbed

Fork of UKESF_Lab by UKESF Headstart Summer School

main.cpp

Committer:
jah128
Date:
2015-10-22
Revision:
8:00558287a4ef
Parent:
7:ef9ab01b9e26
Child:
9:085e090e1ec1

File content as of revision 8:00558287a4ef:

/***********************************************************************
**  ██████╗ ███████╗██╗███████╗██╗    ██╗ █████╗ ██████╗ ███╗   ███╗  **
**  ██╔══██╗██╔════╝██║██╔════╝██║    ██║██╔══██╗██╔══██╗████╗ ████║  **
**  ██████╔╝███████╗██║███████╗██║ █╗ ██║███████║██████╔╝██╔████╔██║  **
**  ██╔═══╝ ╚════██║██║╚════██║██║███╗██║██╔══██║██╔══██╗██║╚██╔╝██║  **
**  ██║     ███████║██║███████║╚███╔███╔╝██║  ██║██║  ██║██║ ╚═╝ ██║  **
**  ╚═╝     ╚══════╝╚═╝╚══════╝ ╚══╝╚══╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝     ╚═╝  **
************************************************************************
**(C) Dr James Hilder - York Robotics Laboratory - University of York **
***********************************************************************/

/// 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"

//  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
int 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";

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()
{
    for(int i=0;i<10;i++){
        time_based_turn_degrees(1, 90);
        wait(1);   
    }
    
    out("------------------------------------------------------\n");
    out("Beautiful Meme Project Demo Code                      \n");
    out("------------------------------------------------------\n");
    locate_beacon();
    while(beacon_found == 0) {
        locate_beacon();
    }

    start_infrared_timers();
}

///This function is the loop where user code should be placed
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(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
    /// NB For maximum compatability it is recommended to minimise reliance on center button press

    //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()
{
    ///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);
    }
}

/// 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);
    }
}