コード例 #1
0
ファイル: main.c プロジェクト: Arbeidsplass16/ttk4145
int main(){
    // Initialize hardware
    if (!elev_init()) {
        printf(__FILE__ ": Unable to initialize elevator hardware\n");
        return 1;
    }
    
    printf("Press STOP button to stop elevator and exit program.\n");

    elev_set_speed(300);
      
    while (1) {
        if (elev_get_floor_sensor_signal() == 0){
            elev_set_speed(300);
        } else if (elev_get_floor_sensor_signal() == N_FLOORS-1){
            elev_set_speed(-300);
        }

        if (elev_get_stop_signal()) {
            elev_set_speed(0);
            break;
        }
    }

    return 0;
}
コード例 #2
0
States fsm_going_up(system_state_t* system_state, States fsm_previous_state){

	if (elev_get_stop_signal()){
		return stop;
	}
	
	system_state->next_floor = system_state->current_floor + system_state->motor_direction;
	
    elev_set_door_open_lamp(0);
    elev_set_motor_direction(DIRN_UP);
    
    check_cmd_buttons(system_state);
    check_call_buttons(system_state);

	check_floor(system_state);
    if (elev_get_floor_sensor_signal() >= 0) { 	
		
		elev_set_floor_indicator(system_state->current_floor);
		
		
		if (should_stop(system_state, system_state->current_floor)){
			elev_set_direction(system_state, 0);
            orders_clearAt(system_state, system_state->current_floor);
	    	reset_button_indicators(system_state);     	
			return door_open;
		}
    }  
    return going_up;
}
コード例 #3
0
ファイル: main.c プロジェクト: KMikalsen/heisprosjekt
int main()
{
    // Initialize hardware
    if (!elev_init()) {
        printf(__FILE__ ": Unable to initialize elevator hardware\n");
        return 1;
    }
    printf("Best Elevator Software,  version: 2.27.14\n" );
    initialize();
    lastFloorReached = N_FLOORS+1;
    while (1) {
        queueIsEmpty = emptyQueue();
        obstructionSignal = elev_get_obstruction_signal();
        stoppedSignal = elev_get_stop_signal();
        thisFloor = elev_get_floor_sensor_signal();
        duration = clock()-start;

        if ( timerActive && duration > seconds ) {
            timerActive = 0;
            duration = 0;
            stateMachine( TIMEROUT );
        }

        if ( obstructionSignal != lastObstructionSignal ) {
            if ( obstructionSignal == 1 )
                stateMachine( OBSTRON );
            if ( obstructionSignal == 0 )
                stateMachine( OBSTROFF );
            lastObstructionSignal = obstructionSignal;
        }

        if ( stoppedSignal != lastStoppedSignal ) {
            if ( stoppedSignal == 1 )
                stateMachine( STOP );
            lastStoppedSignal = stoppedSignal;
        }

        if ( thisFloor != -1 && ( lastFloorReached != thisFloor ) ) {
            if ( thisFloor-lastFloorReached < 0 )
                direction = DOWN;
            if ( thisFloor-lastFloorReached > 0 )
                direction = UP;
            lastFloorReached = thisFloor;
            elev_set_floor_indicator( thisFloor );
        }

        if ( order() && directionToGo( thisFloor, getNextOrder( thisFloor ) ) == 0 )
            stateMachine( NEWORDERCURRENTFLOOR );

        if ( thisFloor != -1 && directionToGo( thisFloor , getNextOrder( thisFloor ) ) == 0 && !timerActive )
            stateMachine( FLOORREACHED );

        if( queueIsEmpty == 1 && order() )
            stateMachine( NEWORDEREMPTYQUEUE );
    }
    return 0;
}
コード例 #4
0
ファイル: sm_macro.c プロジェクト: sigvartmh/heis3.0
current_state_t sm_stop(int queues[N_QUEUES][N_FLOORS]) {
    elev_set_speed(0);
    ui_set_stop_lamp(1);
    //this takes the elevator out of the stop state
    if(queue_has_orders(queues) && !elev_get_stop_signal())
    {
    	ui_set_stop_lamp(0);
        return STATE_UNDEF;
    }
    queue_clear(queues);
	return STATE_STOP;
}
コード例 #5
0
ファイル: sm_macro.c プロジェクト: sigvartmh/heis3.0
//1 is up and 0 is down
current_state_t sm_door_open(int queues[N_QUEUES][N_FLOORS], int previousState) {

	elev_set_speed(0);
	int timer = 0;
	int currentFloor = elev_get_floor_sensor_signal();

	ui_set_door_open_lamp(1);
	startTimer();
	//bool
	while(timer != 1)
	{
		if(elev_get_stop_signal())
		{
            return STATE_STOP;
		}
		//listens for button signals, to take stop and order while the door is open
		ui_button_signals(queues);
		timer = checkTimer(3);
	}
	while(elev_get_obstruction_signal() != 0)
	{
		if(elev_get_stop_signal())
		{
			ui_set_door_open_lamp(0);
            return STATE_STOP;
		}
		ui_set_door_open_lamp(1);
	}
	ui_set_door_open_lamp(0);

    if (previousState == STATE_UP)
	{
		queues[QUEUE_COMMAND][currentFloor] = 0;
		//if on the top floor
		if(currentFloor == (N_FLOORS-1))
		{
			queues[QUEUE_DOWN][currentFloor] = 0;
		}
		//if orders over current in up queue
		else if(!queue_up_empty(queues, QUEUE_UP, currentFloor))
		{
			queues[QUEUE_UP][currentFloor] = 0;
		}
		//if no orders over current in up queue AND orders below in down queue
		else if(queue_up_empty(queues, QUEUE_UP, currentFloor) && !queue_down_empty(queues, QUEUE_DOWN, currentFloor))
		{
			queues[QUEUE_DOWN][currentFloor] = 0;
			return STATE_DOWN;
		}
		return STATE_UP;
	}

	else if(previousState == STATE_DOWN)
	{
		queues[QUEUE_COMMAND][currentFloor] = 0;
		//if on bottom floor
		if(currentFloor == 0)
		{
			queues[QUEUE_UP][currentFloor] = 0;
			//return IDLE??????????????????????????????
		}
		//if orders below in down queue
		else if(!queue_down_empty(queues, QUEUE_DOWN, currentFloor))
		{
			queues[QUEUE_DOWN][currentFloor] = 0;
		}
		//if no orders below in down queue and orders over in up queue
		else if(queue_down_empty(queues, QUEUE_DOWN, currentFloor) && !queue_up_empty(queues, QUEUE_UP, currentFloor))
		{
			queues[QUEUE_UP][currentFloor] = 0;
			return STATE_UP;
		}
		return STATE_DOWN;
	}
	return STATE_IDLE;
}
コード例 #6
0
States fsm_idle_state(system_state_t* system_state, States fsm_previous_state){

	int floor = elev_get_floor_sensor_signal();
    system_state->next_floor = system_state->prev_floor + system_state->motor_direction;

    if (elev_get_stop_signal()){
		return stop;
	}	
	
    if (floor == 0){
		if (elev_get_button_signal(BUTTON_COMMAND, floor) ||
        	elev_get_button_signal(BUTTON_CALL_UP, floor)){
			return door_open;
		}
    } 
    
    else if (floor == 3){
		if (elev_get_button_signal(BUTTON_COMMAND, floor) ||
        	elev_get_button_signal(BUTTON_CALL_DOWN, floor)){
			return door_open;
		}
	} 
	
	else{
    	if (elev_get_button_signal(BUTTON_COMMAND, floor) ||
            elev_get_button_signal(BUTTON_CALL_UP, floor) ||
            elev_get_button_signal(BUTTON_CALL_DOWN, floor)){
        	return door_open;
    	}
    }
    
    check_cmd_buttons(system_state);
    
    for (int i = 0; i < N_FLOORS; ++i){
        if (system_state->elev_active_floors[i] == 1){
            if (i < floor){
            	system_state->motor_direction = -1;
                return going_down;
            }           
            else if (i > floor){  
            	system_state->motor_direction = 1;    
                return going_up;
            }
        }
    }
	
	
	check_call_buttons(system_state);

	for (int i=0; i<N_FLOORS;++i){
		if (system_state->elev_called_floors_down[i] || system_state->elev_called_floors_up[i]){
			if (i < floor){
				system_state->motor_direction = -1;
				return going_down;
			}
			else if (i > floor){
				system_state->motor_direction = 1;
				return going_up;
			}
		}
	}


    return idle;
}
コード例 #7
0
States fsm_stop_button_pressed(system_state_t* system_state, States fsm_previous_state){
    
    system_state->next_floor = system_state->current_floor + system_state->motor_direction;

	elev_set_motor_direction(DIRN_STOP);
	reset_active_floors(system_state);
	reset_called_floors(system_state);
	initialize_button_indicators(system_state);
	
	if (elev_get_floor_sensor_signal() >= 0){
		elev_set_stop_lamp(1);
		elev_set_door_open_lamp(1);
		
		if (!elev_get_stop_signal()){
			elev_set_stop_lamp(0);
			return idle;
		}
		return stop;
	}
	
	else{
		
		while (elev_get_stop_signal())
			elev_set_stop_lamp(1);
			
		if (!elev_get_stop_signal()){
			elev_set_stop_lamp(0);
    		
    		check_cmd_buttons(system_state);
    
   			for (int i = 0; i < N_FLOORS; ++i){
        		if (system_state->elev_active_floors[i] == 1){
            		if (i < system_state->current_floor){
               			return going_down;
            		}           
            		else if (i > system_state->current_floor){      
               			return going_up;
            		}
            		else{ // if i is the floor currently indicated
            			if (system_state->next_floor > system_state->current_floor){
            				return going_down;
            			}
            			else            				
            				return going_up;
            		}
        		}
    		}
	
			check_call_buttons(system_state);
		
			for (int i = 0; i < N_FLOORS; ++i){
				if (system_state->elev_called_floors_down[i] || 
					system_state->elev_called_floors_up[i]){
					if (i < system_state->current_floor){
					
						return going_down;
					}
					else if (i > system_state->current_floor){
						return going_up;
					}
            		else{ // if i is the floor currently indicated0
            			if (system_state->next_floor > system_state->current_floor)
            				return going_down;
            			else 
            				return going_up;
            		}					
				}	
			}	
		}
	}

	return stop;
}
コード例 #8
0
/*
 * Class:     no_ntnu_stud_torbjovn_comedielevator_NativeInterface
 * Method:    elev_get_stop_signal
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_no_ntnu_stud_torbjovn_comedielevator_NativeInterface_elev_1get_1stop_1signal
  (JNIEnv * env, jobject obj) {
    return elev_get_stop_signal();
  }
コード例 #9
0
ファイル: main.c プロジェクト: kjetilkjeka/heisprosjekt
int main()
{
    if (!elev_init()) {
        printf(__FILE__ ": Unable to initialize elevator hardware\n");
        return 1;
    }


    slettAlleOrdre();
    elev_set_speed(0);    
    initHeisstyring();

    int forgjeEtasje = 0;
    int etasje;
    bool forgjeStopp;
    bool stopp;
    bool forgjeObstruksjon;
    bool obstruksjon;
    bool forgjeOpp[4];
    bool opp[4];
    bool forgjeInne[4];
    bool inne[4];
    bool forgjeNed[4];
    bool ned[4];

    while(1)
    {
	stopp = elev_get_stop_signal();
	obstruksjon = elev_get_obstruction_signal();
	etasje = elev_get_floor_sensor_signal();
	
	for(int i = 0; i < N_FLOORS; i++) // poller masse, fix
	{
	    if(i != N_FLOORS-1)
		opp[i] = elev_get_button_signal(BUTTON_CALL_UP, i);
    	    
	    if(i != 0)
		ned[i] = elev_get_button_signal(BUTTON_CALL_DOWN, i);
	    
	    inne[i] = elev_get_button_signal(BUTTON_COMMAND, i);
	}

	for(int i = 0; i < N_FLOORS; i++)
	{
	    if(opp[i] && !forgjeOpp[i])
		leggTilOrdre(i, false, true);
	    
	    if(ned[i] && !forgjeNed[i])
		leggTilOrdre(i, false, false);
	    
	    if(inne[i] && !forgjeInne[i])
		leggTilOrdre(i, true, true);
	    
	    forgjeOpp[i] = opp[i];
	    forgjeNed[i] = ned[i];
	    forgjeInne[i] = inne[i];
	}

	if(harTimetUt())
	    timeOut();

	if (etasje != -1 && etasje != forgjeEtasje)
	{
	    elev_set_floor_indicator(etasje);
	    etasjeAnkommet(etasje);
	    forgjeEtasje = etasje;
	}

	if(obstruksjon && !forgjeObstruksjon)
	{
	    forgjeObstruksjon = obstruksjon;
	    forgjeEtasje = -1;
	    if(obstruksjon)
		obstruksjonPa();
	    else
		obstruksjonAv();
	}
	
	if(stopp && !forgjeStopp)
	{
	    forgjeStopp = stopp;
	    forgjeEtasje = -1;
	    if(stopp)
		nodStopp();
	}
    }	
    return 0;
}
コード例 #10
0
void tilstandsMaskin2(event_t event)
{
    switch(tilstand2)
    {
    case(KLAR):
	switch(event)
	{
	case(NOD_STOPP):	
	    nodstopEntry();
	    break;
	case(OBSTRUKSJON_PA):
	    obstruksjonEntry();
	    break;
	}
	break;
	
    case(OBSTRUKSJON):
	switch(event)
	{	
	case(NOD_STOPP):
	    obstruksjonStoppEntry();
	    break;
	    
	case(OBSTRUKSJON_AV):
	    klarEntry(); 
	}
	break;
    	
    case(NODSTOPP):
	switch(event)
	{
	case(NY_ORDRE):	
	    if(finnestOrdreInniHeis() && !elev_get_stop_signal())
	    {
		klarEntry();
	    } else 
	    {
		nodstopEntry();
	    }
	    break;
	case(OBSTRUKSJON_PA):
	    obstruksjonStoppEntry();
	}
	break;
	
    case(OBSTRUKSJON_STOPP):
	switch(event)
	{
	case(NY_ORDRE):
	    
	    if(finnestOrdreInniHeis() && !elev_get_stop_signal())
		obstruksjonEntry();
	    else
		obstruksjonStoppEntry();
	    break;
	    
	case(OBSTRUKSJON_AV):
	    nodstopEntry();	
	}
	
	if(tilstand2 != NODSTOPP && tilstand2 != OBSTRUKSJON_STOPP)
	    elev_set_stop_lamp(false);
	
	break;
    }    
}