PES 2 - Gruppe 1 / Mbed 2 deprecated Robocode_Random

Dependencies:   mbed

Fork of Robocode by PES 2 - Gruppe 1

source/Main.cpp

Committer:
aeschsim
Date:
2017-04-19
Revision:
63:87b615e4a842
Parent:
61:b57577b0072f
Child:
67:d1ac034668fc

File content as of revision 63:87b615e4a842:

#include "Main.h"


int state = 10;
bool positioning_state = 0;
bool mapping_state = 0;

int IMU();

int main()
{
    printf("start...\r\n");

    // while (timer() < 300) {
    while (1) {
        wait(0.001f);
        // 5min
        //*******************************************************************************
        //Non_state machine driven function
        //This functions will be called every cycle, use for safety and sensor functipons
        //*******************************************************************************

        safety();

        //scanning();
        


        if(positioning_state) {
            positioning();
        }
        if(mapping_state) {
            mapping();
        }

        //*******************************************************************************
        //state machine driven function
        //This functions will only be called when their state is active.
        //The state machine will be in the same state until this action is completed or
        //a safty function kicks in and stops the current function.
        //Every function will return the next active state upon its transition table.
        //State and Transition Table can be found in the State_Machine.xlsx
        //*******************************************************************************
        switch (state) {
            case 0:
                state = emergency_shutdown();
                break;
            case 1:
                state = colision_detected();
                break;
            case 2:
                state = current_to_high();
                break;
            case 3:
                state = overheating();
                break;


            case 10:
                state = idel();
                printf("idel1...\r\n");
                break;
            case 11:
                state = idel2();
                printf("idel2...\r\n");
                break;


            case 15:
                state = initialisation();
                break;
            case 16:
                state = inital_positioning();
                break;


            case 25:
                state = 26;
                positioning_state = 1;
                break;
            case 26:
                state = 27;
                mapping_state = 1;
                break;
            case 27:
                state = initial_turn();
                break;


            case 35:
                state = select_target();
                break;
            case 36:
                state = pathfinding();
                break;
            case 37:
                state = switch_target_red();
                break;


            case 40:
                state = moving();
                break;
            case 41:
                state = move_forward_for_distance(0);
                break;
            case 42:
                state = move_backward_for_distance();
                break;
            case 43:
                state = turn_for_deg(0);
                break;


            case 46:
                state = move_to_next_coord();
                break;
            case 47:
                state = move_in_search_for_brick();
                break;


            case 50:
                state = grabbing();
                break;
            case 51:
                state = arm_position_move();
                break;
            case 52:
                arm_position_grabbing();
                state = 56;
                wait_ms(1000);
                break;
            case 53:
                state = arm_position_release();
                state = 55;
                wait_ms(1000);
                break;

            case 55:
                state = open_grabber();
                state = 52;
                wait_ms(1000);
                break;
            case 56:
                state = close_grabber();
                state = 53;
                wait_ms(1000);
                break;

/*
            case 99:
                sate = init();
                break;
            case 100:
                state = turn_left(30);
                break;
            case 101:
                state = turn_right_for_brick;
                break;
            case 102:
                state = move_to_brick;
*/


//test states
            case 200:
                state = IMU();
                break;
            default:
                printf("Fatal Error, Unkonwn state!");
                state = 0;
                break;
        }
    }
}

int IMU()
{
    printf("%f\r\n", read_heading());
    return 200;
}

int init()
{
    Robot_init_all();
    return 100;
}


/*
int turn_left(float deg)
{
    bool in_function = false;
    if(in_function = false) {
        float current_deg = read_heading();
        set_speed(-50, 50);
        in_function = true;
    }
    if(current_deg - deg < read_heading() {
    set_speed(0, 0);
        return 101;
        in_function = false;
    }
    return 100;
}

int turn_right_for_brick {
    return 0
}*/