Exemplo n.º 1
0
 def thread_buzzer(self):
     """
     Engages motor board to sound buzzer for 2 seconds.
     """
     motor.motor_move(self.data.BUZZER, 100)
     time.sleep(2)
     motor.stop_motor(self.data.BUZZER)
Exemplo n.º 2
0
    def move_rotational(self, rotation_direction):
        """
        Determine if rotational motor should move, and if so engage motor in appropriate direction.
        Return True if motor is engaged, false otherwise.
        """
        if rotation_direction == Rotation.ANTI_CLOCKWISE:
            if self.rotational_pos == Rotation.CLOCKWISE:
                try:
                    print "[SORTER] Moving rotational anti-clockwise"
                    motor.motor_move(self.rotational_motor,
                                     self.rotational_speed)
                    return True
                except:
                    print "[SORTER] I2C Error: Rotation anti-clockwise"
            else:
                return False

        elif rotation_direction == Rotation.CLOCKWISE:
            if self.rotational_pos == Rotation.ANTI_CLOCKWISE:
                try:
                    print "[SORTER] Moving rotational clockwise"
                    motor.motor_move(self.rotational_motor,
                                     -self.rotational_speed)
                    return True
                except:
                    print "[SORTER] I2C Error: Rotation clockwise"
            else:
                return False

        else:
            return False
Exemplo n.º 3
0
    def move_vertical(self, vertical_direction):
        """
        Determine if vertical motor should move, and if so engage motor in appropriate direction.
        Return True if motor is engaged, false otherwise.
        """
        if vertical_direction == Vertical.UP:
            if self.vertical_pos == Vertical.DOWN:
                try:
                    print "[SORTER] Moving vertical up"
                    motor.motor_move(self.vertical_motor, self.vertical_speed)
                    return True
                except:
                    print "[SORTER] I2C Error: Vertical up"
            else:
                return False

        elif vertical_direction == Vertical.DOWN:
            if self.vertical_pos == Vertical.UP:
                try:
                    print "[SORTER] Moving vertical down"
                    motor.motor_move(self.vertical_motor, -self.vertical_speed)
                    return True
                except:
                    print "[SORTER] I2C Error: Vertical down"
            else:
                return False

        else:
            return False
Exemplo n.º 4
0
    def __init__(self, io):
        threading.Thread.__init__(self)
        self.data = data.Data()
        self.get_sensors = io.interface_kit.getSensors

        # Inductive sensor is powered from the motor board output
        motor.motor_move(self.data.INDUCTIVE_PWR, 100)
Exemplo n.º 5
0
    def check_run_system(self):
        """
        Continuously checks the system control file, which will be written to by the
        server. This includes setting the speed of the conveyor belt and stopping the
        whole system.
        """
        initialised_running = False

        while not self.stopped_check_run_system():

            if self.data.get_shut_down():
                self.destroy()
                break

            with open('data/system_control.json') as json_file:
                try:
                    sys_data = json.load(json_file)
                    run_system = sys_data['system']['run']
                    self.data.set_run_system(run_system)

                    if run_system:
                        if initialised_running == False:
                            try:
                                # Sound buzzer 3 times
                                for i in range(3):
                                    motor.motor_move(self.data.BUZZER, 100)
                                    time.sleep(0.4)
                                    motor.stop_motor(self.data.BUZZER)
                                    time.sleep(0.5)

                                self.conveyor.set_belt_speed(100)
                                initialised_running = True
                            except:
                                print "[TODDLER] Failed to write to motor board"
                        time.sleep(0.2)
                    else:
                        initialised_running = False
                        self.conveyor.stop_belt()
                except:
                    print "[TODDLER] Failed to decode JSON"
        self.conveyor.stop_belt()
Exemplo n.º 6
0
def android(request):
    up_down = dict(request.POST)
    print(up_down)
    result = {'status': 'ok', 'switch_state': up_down}
    temp = up_down['switch_state'][0] 
    if temp == '4':
        motor.motor_move(-100, 0)
        print('left')
    if temp == '3':
        motor.motor_move(100, 0)
        print('right')
    if temp == '2':
        motor.motor_move(0, 100)
        print('forward')
    if temp == '1':
        motor.motor_move(0, -100)
        print('backward')
    if temp == '0':
        motor.motor_move(0, 0)
        print('stop')
    return HttpResponse(json.dumps(result))
Exemplo n.º 7
0
    def reset_sorter(self):
        """
        In the case of an I2C error or an item getting stuck, this function temporarily
        stops the conveyor belt and resets the sorting arm to its original position.
        """
        # Stop conveyor belt
        motor.stop_motor(self.data.ENTRANCE_MOTOR_INDUCTIVE_PWR)
        motor.stop_motor(self.data.EXIT_MOTOR)

        # Force sorting arm to original position by ignoring current position
        motor.motor_move(self.rotational_motor, self.rotational_speed)
        motor.motor_move(self.vertical_motor, self.vertical_speed)
        time.sleep(2)
        motor.stop_motor(self.vertical_motor)
        motor.stop_motor(self.rotational_motor)
        self.vertical_pos = Vertical.UP
        self.rotational_pos = Rotation.ANTI_CLOCKWISE

        # Restart conveyor belt
        motor.motor_move(self.data.ENTRANCE_MOTOR_INDUCTIVE_PWR, 70)
        motor.motor_move(self.data.EXIT_MOTOR, 70)
Exemplo n.º 8
0
 def set_belt_speed(self, speed):
     '''
     Sets the speed of the front and back motors of the conveyor belt
     '''
     motor.motor_move(self.id_motor_front, speed)
     motor.motor_move(self.id_motor_back, speed)