Ejemplo n.º 1
0
func watchObs() {
	for {

		if elevdriver.GetObs() {
			go elevdriver.SetDoor()
		} else {
			go elevdriver.ClearDoor()
		}
	}
}
Ejemplo n.º 2
0
func (elevinf *Elevatorinfo) statemachineOpendoor() {
	switch elevinf.event {
	case ORDER:
		fmt.Printf("The door is open\n")
		elevdriver.SetDoor()
		elevinf.DeleteOrders()
		for i := 0; i < 300; i++ {
			if elevdriver.GetFloor() == -1 && elevdriver.GetObs() == false {
				elevdriver.ClearDoor()
				elevinf.state = IDLE
				break
			} else if elevdriver.GetStopButton() == true {
				elevinf.StopButtonPushed()
				elevinf.state = EMERGENCY
				break
			}
			elevinf.ReceiveOrders()
			elevinf.CheckLights()
			time.Sleep(10 * time.Millisecond)
			if elevdriver.GetObs() == true {
				fmt.Printf("Obstruction detected, door staying open\n")
				i = 0
			}
		}
		elevdriver.ClearDoor()
		elevinf.DeleteOrders()
		fmt.Printf("Door cleared\n")
		if elevinf.DetermineDirection() == -2 {
			elevinf.state = OPEN_DOOR
		} else if elevinf.DetermineDirection() == -1 {
			elevinf.state = DECENDING
			StartMotor(-1)
		} else if elevinf.DetermineDirection() == 1 {
			elevinf.state = ASCENDING
			StartMotor(1)
		} else if elevinf.DetermineDirection() == 2 {
			elevinf.state = IDLE
		}
	case STOP:
		elevinf.StopButtonPushed()
		elevinf.state = EMERGENCY
	case OBSTRUCTION:
	case SENSOR:
		fmt.Printf("Elevator reached floor %d\n", elevdriver.GetFloor())
		elevdriver.SetDoor()
		for i := 0; i < 300; i++ {
			if elevdriver.GetFloor() == -1 && elevdriver.GetObs() == false {
				elevdriver.ClearDoor()
				elevinf.state = IDLE
				break
			} else if elevdriver.GetStopButton() == true {
				elevinf.StopButtonPushed()
				elevinf.state = EMERGENCY
				break
			}
			elevinf.ReceiveOrders()
			elevinf.CheckLights()
			if elevdriver.GetObs() == true {
				i = 0
			}
		}
		elevinf.DeleteOrders()
		elevdriver.ClearDoor()
		if elevinf.DetermineDirection() == -2 {
			elevinf.state = OPEN_DOOR
		} else if elevinf.DetermineDirection() == -1 {
			elevinf.state = DECENDING
			StartMotor(-1)
		} else if elevinf.DetermineDirection() == 1 {
			elevinf.state = ASCENDING
			StartMotor(1)
		} else if elevinf.DetermineDirection() == 2 {
			elevinf.state = IDLE
		}
	case NO_EVENT:
	}
}