def setButtonIndicator(self, floor, direction, onoff):
     if direction: # Up
         if floor == 3: return
         io.setBit(OUTPUT.UP_LIGHTS[floor], onoff)
     else: #Down
         if floor == 0: return
         io.setBit(OUTPUT.DOWN_LIGHTS[floor-1], onoff)
Example #2
0
	def setButtonLamp(self, floor, buttonType, value):
		assert(floor >= 0), "ERR_ floor < 0"
		assert(floor < self.NUM_FLOORS), "ERR_ floor > NUM_FLOORS"
		assert(buttonType >= 0), "ERR_ buttonType < 0"
		assert(buttonType < self.NUM_FLOORS - 1), "ERR_ buttonType > NUM_FLOORS"

		io.setBit(INPUT.BUTTON_FLOORS[floor][buttonType], value)
Example #3
0
	def setButtonLamp(self, floor, buttonType, value):
		assert(floor >= 0), "ERR_ floor < 0"
		assert(floor < self.NUM_FLOORS), "ERR_ floor > NUM_FLOORS"
		assert(buttonType >= 0), "ERR_ buttonType < 0"
		assert(buttonType < self.NUM_FLOORS - 1), "ERR_ buttonType > NUM_FLOORS"

		io.setBit(INPUT.BUTTON_FLOORS[floor][buttonType], value)
Example #4
0
    def __init__(self):
        self.moving = False
        self.direction = OUTPUT.MOTOR_DOWN
        self.NUM_FLOORS = INPUT.NUM_FLOORS

        for light in OUTPUT.LIGHTS:
            if light != -1:
                io.setBit(light, 0)
Example #5
0
    def stop(self):
        """Stops the elevator, and flips direction for smoother stopping."""
        if self.direction is OUTPUT.MOTOR_UP:
            io.setBit(OUTPUT.MOTORDIR,OUTPUT.MOTOR_DOWN)
        elif self.direction is OUTPUT.MOTOR_DOWN:
            io.setBit(OUTPUT.MOTORDIR,OUTPUT.MOTOR_UP)

        io.write(OUTPUT.MOTOR,2048)
Example #6
0
	def __init__(self):
		self.moving = False
		self.direction = OUTPUT.MOTOR_DOWN
		self.NUM_FLOORS = INPUT.NUM_FLOORS

		for light in OUTPUT.LIGHTS:
			if light != -1:
				io.setBit(light, 0)
Example #7
0
    def stop(self):
        """Stops the elevator, and flips direction for smoother stopping."""
        if self.direction is OUTPUT.MOTOR_UP:
            io.setBit(OUTPUT.MOTORDIR, OUTPUT.MOTOR_DOWN)
        elif self.direction is OUTPUT.MOTOR_DOWN:
            io.setBit(OUTPUT.MOTORDIR, OUTPUT.MOTOR_UP)

        io.write(OUTPUT.MOTOR, 2048)
Example #8
0
 def stop(self):
     if not self.moving:
         return
     if self.direction is OUTPUT.MOTOR_DOWN:
         io.setBit(OUTPUT.MOTORDIR, OUTPUT.MOTOR_UP)
     else:
         io.setBit(OUTPUT.MOTORDIR, OUTPUT.MOTOR_DOWN)
     sleep(0.02)
     io.writeAnalog(OUTPUT.MOTOR, 2048)
Example #9
0
	def stop(self):
		if not self.moving:
			return
		if self.direction is OUTPUT.MOTOR_DOWN:
			io.setBit(OUTPUT.MOTORDIR, OUTPUT.MOTOR_UP)
		else:
			io.setBit(OUTPUT.MOTORDIR, OUTPUT.MOTOR_DOWN)
		sleep(0.02)
		io.writeAnalog(OUTPUT.MOTOR, 2048)
Example #10
0
    def setSpeed(self, speed):
        if speed > 0:
            self.direction = OUTPUT.MOTOR_UP
        elif speed < 0:
            self.direction = OUTPUT.MOTOR_DOWN
        else:
            self.stop()

        io.setBit(OUTPUT.MOTORDIR, self.direction)
        io.writeAnalog(OUTPUT.MOTOR, 2048 + 4 * abs(speed))
        self.moving = True
Example #11
0
	def setSpeed(self, speed):
		if speed > 0:
			self.direction = OUTPUT.MOTOR_UP
		elif speed < 0:
			self.direction = OUTPUT.MOTOR_DOWN
		else:
			self.stop()

		io.setBit(OUTPUT.MOTORDIR, self.direction)
		io.writeAnalog(OUTPUT.MOTOR, 2048+4*abs(speed))
		self.moving = True
Example #12
0
 def move(self,direction,speed=1000):
     """Asks the motor to move in a given direction and with a given speed.
     
     direction -- OUTPUT.MOTOR_UP or OUTPUT.MOTOR_DOWN, tells the direction to move in.
     speed     -- Defaults to 1000. Used for debugging purposes only.
     """
     self.direction = direction
     if (speed > 0):
         io.setBit(OUTPUT.MOTORDIR,direction)
     elif (speed < 0):
         io.setBit(OUTPUT.MOTORDIR,direction)
     io.write(OUTPUT.MOTOR,2048 + 2*abs(speed))
Example #13
0
 def move(self, direction, speed=1000):
     """Asks the motor to move in a given direction and with a given speed.
     
     direction -- OUTPUT.MOTOR_UP or OUTPUT.MOTOR_DOWN, tells the direction to move in.
     speed     -- Defaults to 1000. Used for debugging purposes only.
     """
     self.direction = direction
     if (speed > 0):
         io.setBit(OUTPUT.MOTORDIR, direction)
     elif (speed < 0):
         io.setBit(OUTPUT.MOTORDIR, direction)
     io.write(OUTPUT.MOTOR, 2048 + 2 * abs(speed))
Example #14
0
    def stop(self):
        """Stops the elevator, and flips direction for smoother stopping."""
		
        if not self.moving: return
        self.moving = False

        sleep(0.16)
        if self.direction is OUTPUT.MOTOR_UP:
            io.setBit(OUTPUT.MOTORDIR,OUTPUT.MOTOR_DOWN)
        elif self.direction is OUTPUT.MOTOR_DOWN:
            io.setBit(OUTPUT.MOTORDIR,OUTPUT.MOTOR_UP)
		
        io.write(OUTPUT.MOTOR,2048 + 1000)
        sleep(0.01)
        io.write(OUTPUT.MOTOR,2048)
        self.moving = False
Example #15
0
    def setFloorIndicator(self,floor):
        """Sets the floor indicator light in a floor and turns off the others."""
        #self.setChannel(OUTPUT.FLOOR_LIGHTS[0], (floor-1)%2)
        #self.setChannel(OUTPUT.FLOOR_LIGHTS[1], (floor-1)/2)
        if floor & 0x1: io.setBit(OUTPUT.FLOOR_IND1, 1)
        else: io.setBit(OUTPUT.FLOOR_IND1, 0)

        if floor & 0x2: io.setBit(OUTPUT.FLOOR_IND2, 1)
        else: io.setBit(OUTPUT.FLOOR_IND2, 0)
Example #16
0
    def setFloorIndicator(self, floor):
        assert (floor >= 0), "ERR_ floor < 0"
        assert (floor < self.NUM_FLOORS), "ERR_ floor > NUM_FLOORS"

        if floor & 0x02:
            io.setBit(OUTPUT.FLOOR_IND1, 1)
        else:
            io.setBit(OUTPUT.FLOOR_IND1, 0)

        if floor & 0x01:
            io.setBit(OUTPUT.FLOOR_IND2, 1)
        else:
            io.setBit(OUTPUT.FLOOR_IND2, 0)
Example #17
0
	def setFloorIndicator(self, floor):
		assert(floor >= 0), "ERR_ floor < 0"
		assert(floor < self.NUM_FLOORS), "ERR_ floor > NUM_FLOORS"

		if floor & 0x02:
			io.setBit(OUTPUT.FLOOR_IND1, 1)
		else:
			io.setBit(OUTPUT.FLOOR_IND1, 0)

		if floor & 0x01:
			io.setBit(OUTPUT.FLOOR_IND2, 1)
		else:
			io.setBit(OUTPUT.FLOOR_IND2, 0)
    def floor_listener(self, floor):
        print "Current floor:", self.current_floor
        if self.current_floor != floor:
            self.current_floor = floor
            self.send_event("update,%s,%s" % (floor, self.direction))
        print "New current floor:", self.current_floor


        # check if current floor is destination and poke system
        if floor == int(self.current_action.rsplit(',')[1]):
            io.setBit(OUTPUT.DOOR_OPEN, 1)

            if floor == 0:
                io.setBit(OUTPUT.LIGHT_COMMAND1, 0)
            elif floor == 1:
                io.setBit(OUTPUT.LIGHT_COMMAND2, 0)
            elif floor == 2:
                io.setBit(OUTPUT.LIGHT_COMMAND3, 0)
            elif floor == 3:
                io.setBit(OUTPUT.LIGHT_COMMAND4, 0)

            print 'I has done work %s' % self.current_action
            self.elevator.stop()
            self.send_event('done,%s,%s' % (self.current_action, self.elevator.direction))
Example #19
0
 def setChannels(self, channels, value):
     for channel in channels:
         io.setBit(channel, value)
    def recv(self, msg):
        # msg[0]: type - msg[1]: floor
        msg = msg.rsplit(',')

        if msg[0] == 'lighton':
            # turn on floor light
            self.elevator.elevator.setButtonIndicator(int(msg[1]), int(msg[2]), 1)
            pass
        elif msg[0] == 'lightoff':
            # turn off floor light
            self.elevator.elevator.setButtonIndicator(int(msg[1]), int(msg[2]), 0)
            pass
        elif msg[0] == 'light_in_on':
            if int(msg[1]) == 0:
                io.setBit(OUTPUT.LIGHT_COMMAND1, 1)
            elif int(msg[1]) == 1:
                io.setBit(OUTPUT.LIGHT_COMMAND2, 1)
            elif int(msg[1]) == 2:
                io.setBit(OUTPUT.LIGHT_COMMAND3, 1)
            elif int(msg[1]) == 3:
                io.setBit(OUTPUT.LIGHT_COMMAND4, 1)

        elif msg[0] == 'goto':
            io.setBit(OUTPUT.DOOR_OPEN, 0)
            # up: 1 - down: 0
            self.direction = 1 if msg[1] > self.current_floor else 0
            self.current_action = 'goto,%s,%i' % (int(msg[1]), self.direction)
            self.elevator.moveToFloor(int(msg[1]))

            if self.current_floor == int(msg[1]):
                if self.current_floor == 0:
                    io.setBit(OUTPUT.LIGHT_COMMAND1, 0)
                elif self.current_floor == 1:
                    io.setBit(OUTPUT.LIGHT_COMMAND2, 0)
                elif self.current_floor == 2:
                    io.setBit(OUTPUT.LIGHT_COMMAND3, 0)
                elif self.current_floor == 3:
                    io.setBit(OUTPUT.LIGHT_COMMAND4, 0)
                print 'I will not move to %s' % self.current_action
                self.send_event('done,%s,%s' % (self.current_action, self.elevator.direction))

        elif msg[0] == 'stop':
            self.elevator.stop()
            self.send_event('done,%s,%s' % (msg[0]+','+msg[1], self.elevator.direction))
            for l in OUTPUT.IN_LIGHTS:
                io.setBit(l, 0)
 def switch_lighting(self, channels, val):
     for chan in channels:
         io.setBit(chan, val)
Example #22
0
 def setChannels(self, channels, value):
     for channel in channels:
         io.setBit(channel, value)
Example #23
0
	def setDoorLamp(self, value):
		assert(value >= 0), "ERR: door lamp value < 0"
		assert(value < 1), "ERR: door lamp value > 1"
		io.setBit(OUTPUT.DOOROPEN, value)
Example #24
0
 def setDoorLamp(self, value):
     assert (value >= 0), "ERR: door lamp value < 0"
     assert (value < 1), "ERR: door lamp value > 1"
     io.setBit(OUTPUT.DOOROPEN, value)