Example #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)
Example #2
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()
Example #3
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)
Example #4
0
    def move_sorter(self, vertical_direction, rotation_direction):
        """
        Sets each of the vertical and rotational motors. Each motor spins until the click thresholds
        for each motor are surpassed. If I2C error occurs, reset the sorting arm. 
        Allow motors to move until either rotary encoder clicks threshold is exceeded or motor
        motor timeouts are exceeded.
        """
        vertical_clicks = 0
        rotational_clicks = 0
        initial_time = time.time()
        vertical_moving = self.move_vertical(vertical_direction)
        rotation_moving = self.move_rotational(rotation_direction)

        while (vertical_moving or rotation_moving):
            if (vertical_clicks < self.vertical_clicks_thresh
                    and vertical_moving == True):
                vertical_clicks += self.data.get_vertical_position()
            else:
                vertical_moving = False
                try:
                    motor.stop_motor(self.vertical_motor)
                except:
                    print "[SORTER] I2C Error: Stop vertical motor"
                    self.reset_sorter()

            if (rotational_clicks < self.rotational_clicks_thresh
                    and rotation_moving == True):
                rotational_clicks += self.data.get_rotation_position()
            else:
                rotation_moving = False
                try:
                    motor.stop_motor(self.rotational_motor)
                except:
                    print "[SORTER] I2C Error: Stop rotational motor"
                    self.reset_sorter()

            if time.time() - initial_time > self.timeout_vertical:
                vertical_moving = False
                try:
                    motor.stop_motor(self.vertical_motor)
                except:
                    print "[SORTER] I2C Error: Stop vertical motor"
                    self.reset_sorter()

            if time.time() - initial_time > self.timeout_rotation:
                rotation_moving = False
                try:
                    motor.stop_motor(self.rotational_motor)
                except:
                    print "[SORTER] I2C Error: Stop rotational motor"
                    self.reset_sorter()

        motor.stop_motor(self.vertical_motor)
        motor.stop_motor(self.rotational_motor)

        self.set_motor_positions(vertical_direction, rotation_direction)
Example #5
0
def stop_forward() -> None:
    """Stop Spencer moving forwards."""
    motor.stop_motor(DRIVE_LEFT)
    motor.stop_motor(DRIVE_RIGHT)
    motor.stop_motor(DRIVE_BACK)
    motor.stop_motor(DRIVE_FWD)
Example #6
0
def stop_back() -> None:
    """Stops the back stepper"""
    motor.stop_motor(STEP_BACK)
Example #7
0
def stop_front() -> None:
    """Stops the front stepper"""
    motor.stop_motor(STEP_FRONT)
Example #8
0
 def stop_belt(self):
     '''
     Stops the front and back motors of the conveyor belt
     '''
     motor.stop_motor(self.id_motor_front)
     motor.stop_motor(self.id_motor_back)