Exemplo n.º 1
0
class Launcher:

    def __init__(self):
        self.vision = VisionLauncher(0)
        self.com = Communication()
        self.pitch = Pitch()

    def launch(self):
        self.vision.launch_vision()
        pass

    def begin_task1(self):
        t = Thread(target=self.task1)
        t.start()
        return t

    def task1(self):
        self.vision.wait_for_start()
        sleep (3)

        def update_ball_position():
            self.pitch.positions['ball'] = self.vision.get_ball_pos()
        def update_robot_position():
            self.pitch.positions['robot'] = self.vision.get_robot_midpoint(self.pitch.robot_color)
        def update_robot_direction():
            angle = self.vision.get_robot_direction(self.pitch.robot_color)
            angle = -1 * angle
            while -180 >= angle or angle > 180:
                if -180 >= angle:
                    angle += 360
                else:
                    angle -= 360
            self.pitch.directions['robot'] = angle
        
        update_ball_position()
        update_robot_position()
        update_robot_direction()

        # TODO DELETE
        # self.pitch.positions['ball'] = (23,23)
        # self.pitch.positions['robot'] = (46,46)
        # self.pitch.directions['robot'] = 0

        distance_angle = self.pitch.get_distance('robot', 'ball')
        turning_angle = self.pitch.get_turn_object('robot', distance_angle[1])

        self.com.ungrab()
        self.com.unkick()
        
        sleep(1)

        if turning_angle > 0:
            self.com.turn_clockwise(turning_angle)
        else:
            self.com.turn_anticlockwise(-1 * turning_angle)

        sleep(5)

        self.com.move_forward(int(distance_angle[0] * self.pitch.ratio))

        sleep(5)

        self.com.grab()







    def end(self):
        self.com.close()
        pass
Exemplo n.º 2
0
 def __init__(self):
     self.vision = VisionLauncher(0)
     self.com = Communication()
     self.pitch = Pitch()