示例#1
0
文件: Atlas.c 项目: ddeo/sdp
/**********************************************************************
 * Function: initializeAtlas
 * @return None.
 * @remark Initializes the boat's master state machine and all modules.
 * @author David Goodman
 * @date 2013.04.24  
 **********************************************************************/
static void initializeAtlas() {
    Board_init();
    Serial_init();
    Timer_init();

    #ifdef USE_DRIVE
    Drive_init();
    #endif

    // I2C bus
    I2C_init(I2C_BUS_ID, I2C_CLOCK_FREQ);

    #ifdef USE_TILTCOMPASS
    TiltCompass_init();
    #endif

    #ifdef USE_GPS
    GPS_init();
    #endif

    #ifdef USE_NAVIGATION
    Navigation_init();

    #endif

    #ifdef USE_OVERRIDE
    Override_init();
    #endif

    #ifdef USE_BAROMETER
    Barometer_init();
    Timer_new(TIMER_BAROMETER_SEND, BAROMETER_SEND_DELAY);
    #endif
        
    // Start calibrating before use
    startSetOriginSM();

    Timer_new(TIMER_HEARTBEAT, HEARTBEAT_SEND_DELAY);

    Mavlink_sendStatus(MAVLINK_STATUS_ONLINE);
}
示例#2
0
文件: Override.c 项目: BananaSlug/sdp
int  main(void) {
    // Initialize the UART, Timers, and I2C
    Board_init();
    Serial_init();
    Timer_init();
    Override_init();
    printf("Override board initialized.\n");

    while(1){
        if (inOverride && !Override_isTriggered()) {
            inOverride = FALSE;
            printf("Override disabled.\n");
        }
        else if (!inOverride && Override_isTriggered()) {
            inOverride = TRUE;
            printf("Override enabled.\n");
        }
    }

    return (SUCCESS);
}
示例#3
0
文件: Drive.c 项目: SamChenzx/sdp
int main(){
    //Initializations
    Board_init();
    Serial_init();
    Timer_init();
    Drive_init();
    int spd = 10;


    ENABLE_OUT_TRIS = OUTPUT;            //Set Enable output pin to be an output, fed to the AND gates
    ENABLE_OUT_LAT = MICRO;             //Initialize control to that of Microcontroller

    enum{
        MICRO_FORWARD = 0x01,         //State where Microcontroller is driving forward
        MICRO_STOP = 0x02,        //State where Micro is driving backwards
        MICRO_LIMBO = 0x03,
        RECIEVER_STATE = 0x04,        //Reciever has taken over state
    }test_state;

    printf("Boat is Initialized\n");

    //Initialize the state to begin at forward
    test_state = MICRO_FORWARD;
    Drive_stop();
    Timer_new(TIMER_TEST,RECIEVER_DELAY);
    int state_flag = 0;
    Override_init();


    while(1){

        switch(test_state){
            case MICRO_FORWARD:
                printf("STATE: MICRO_FORWARD\n\n\n");
                Drive_forward(spd); //The input param is a pwm duty cycle percentage that gets translated to a RC Servo time pulse
                Timer_new(TIMER_TEST2,RECIEVER_DELAY);
                test_state = MICRO_STOP;

                break;
            case MICRO_STOP:
                if(Timer_isExpired(TIMER_TEST2)){
                    printf("STATE: MICRO_STOP\n\n\n:");
                    Drive_stop();
                    Timer_new(TIMER_TEST2,RECIEVER_DELAY);
                    test_state = MICRO_LIMBO;
                }

                break;
            case MICRO_LIMBO:
                if(Timer_isExpired(TIMER_TEST2)){
                    printf("STATE: MICRO_LIMBO\n\n\n");
                    test_state = MICRO_FORWARD;
                }
                Drive_stop();
                break;
            case RECIEVER_STATE:
                ;
                break;

        }
        //If we got a pulse, control to reciever.
        if (OVERRIDE_TRIGGERED == TRUE){
            printf("Reciever Control\n\n");
            Timer_new(TIMER_TEST, 1000);    //Set timer that is greater than the pulsewidth of the CH3 signal(54Hz)
            OVERRIDE_TRIGGERED = FALSE;     //Re-init to zero so that we know when our pulse is triggered again.
            test_state = RECIEVER_STATE;    //Set state equal to reciever where we do nothing autonomous
            ENABLE_OUT_LAT = RECIEVER;      //Give control over to Reciever using the enable line
            INTEnable(INT_CN,1);
        }
        if (Timer_isExpired(TIMER_TEST)){   //Reciever gave up control
            printf("Micro Has Control\n\n");
            Timer_clear(TIMER_TEST);        //Clear timer so that it doesn't keep registering an expired signal
            test_state = MICRO_LIMBO;     //Set state equal to forward for regular function
            OVERRIDE_TRIGGERED = FALSE;     //Set Override to false to be sure that we don't trigger falsely
            ENABLE_OUT_LAT = MICRO;         //Give Control back to microcontroller using enable line
            Timer_new(TIMER_TEST2, RECIEVER_DELAY);
        }

    }


}