예제 #1
0
func fsm_onInitBetweenFloors() {
	Driver.ElevSetMotorDirection(int(D_Down))
	elevator.Dir = D_Down
	elevator.Behaviour = EB_Moving
	lastFloorTime = time.Now().Unix()
	for Driver.ElevGetFloorSensorSignal() == -1 {
	}
	Driver.ElevSetMotorDirection(int(D_Idle))
}
예제 #2
0
파일: main.go 프로젝트: stianlaa/SLH2016
func init() {
	driver.ElevInit()
	driver.ElevSetMotorDirection(1)

	for {
		if driver.ElevGetFloorSensorSignal() >= 0 {
			driver.ElevSetMotorDirection(0)
			break
		}
	}
}
예제 #3
0
파일: main.go 프로젝트: borgewi/SLH2016
func initMain() {
	driver.ElevInit()
	driver.ElevSetMotorDirection(1)
	var previousFloor = -1

	for {
		if driver.ElevGetFloorSensorSignal() >= 0 {
			driver.ElevSetMotorDirection(0)
			previousFloor = driver.ElevGetFloorSensorSignal()
			fmt.Println("I've reached floor", previousFloor)
			break
		}
	}
}
예제 #4
0
파일: fsm.go 프로젝트: stianlaa/SLH2016
func FsmOnOrderReceived(btnFloor int, btnType ButtonType) { //should be made to orderReceived
	switch E.Behaviour {
	case DOOROPEN:
		if E.Floor == btnFloor {
			TimerStart()
		} else {
			E.MasterOrders[btnFloor][btnType] = true
		}
	case IDLE:
		E.MasterOrders[btnFloor][btnType] = true
		E.Dir = ChooseDirection(E)

		if E.Dir == STOP {
			driver.ElevSetDoorLight(true)
			E = ClearOrdersAtFloor(E)
			TimerStart()
			E.Behaviour = DOOROPEN
		} else {
			driver.ElevSetMotorDirection(int(E.Dir))
			E.Behaviour = MOVING
		}
	case MOVING:
		E.MasterOrders[btnFloor][btnType] = true
	}
	SetAllLights(E)
}
예제 #5
0
func fsm_onNewActiveRequest(btn_floor int, btn_type Button) {
	switch elevator.Behaviour {
	case EB_DoorOpen:
		if elevator.Floor == btn_floor {
			timer_start(3000 * time.Millisecond)
		} else {
			elevator.Requests[btn_floor][btn_type] = true
		}
		break
	case EB_Moving:
		elevator.Requests[btn_floor][btn_type] = true
		break
	case EB_Idle:
		elevator.Requests[btn_floor][btn_type] = true
		elevator.Dir = requests_chooseDirection(elevator)
		if elevator.Dir == D_Idle {
			Driver.ElevSetDoorLight(true)
			elevator = requests_clearAtCurrentFloor(elevator)
			timer_start(3000 * time.Millisecond)
			elevator.Behaviour = EB_DoorOpen
		} else {
			Driver.ElevSetMotorDirection(int(elevator.Dir))
			elevator.Behaviour = EB_Moving
			lastFloorTime = time.Now().Unix()
		}
		break
	}
	setAllLights()
}
예제 #6
0
파일: fsm.go 프로젝트: stianlaa/SLH2016
func FsmOnDoorTimeout() {
	if E.Behaviour == DOOROPEN {
		E.Dir = ChooseDirection(E)
		driver.ElevSetDoorLight(false)
		driver.ElevSetMotorDirection(int(E.Dir))
		if E.Dir == STOP {
			E.Behaviour = IDLE
		} else {
			E.Behaviour = MOVING
		}
	}
}
예제 #7
0
파일: fsm.go 프로젝트: stianlaa/SLH2016
func FsmOnFloorArrival(newFloor int) {
	E.Floor = newFloor

	driver.ElevSetFloorIndicator(newFloor)

	if ShouldStop(E) && E.Behaviour == MOVING {
		driver.ElevSetMotorDirection(int(STOP))
		driver.ElevSetDoorLight(true)
		E = ClearOrdersInDirection(E)
		TimerStart()
		SetAllLights(E)
		E.Behaviour = DOOROPEN
	}
}
예제 #8
0
func fsm_onDoorTimeout() {
	switch elevator.Behaviour {
	case EB_DoorOpen:
		elevator.Dir = requests_chooseDirection(elevator)
		Driver.ElevSetMotorDirection(int(elevator.Dir))
		Driver.ElevSetDoorLight(false)
		if elevator.Dir == D_Idle {
			elevator.Behaviour = EB_Idle
		} else {
			elevator.Behaviour = EB_Moving
			lastFloorTime = time.Now().Unix()
		}
		break
	default:
		break
	}
}
예제 #9
0
func fsm_onFloorArrival(newFloor int) {
	lastFloorTime = time.Now().Unix()
	elevator.Floor = newFloor
	Driver.ElevSetFloorIndicator(newFloor)
	switch elevator.Behaviour {
	case EB_Moving:
		if requests_shouldStop(elevator) {
			Driver.ElevSetMotorDirection(int(D_Idle))
			Driver.ElevSetDoorLight(true)
			elevator = requests_clearAtCurrentFloor(elevator)
			timer_start(3000 * time.Millisecond)
			setAllLights()
			elevator.Behaviour = EB_DoorOpen
		}
		break
	default:
		break
	}
}
예제 #10
0
func main() {
	driver.ElevInit()
	driver.ElevSetMotorDirection(0)
}