Пример #1
0
	def drive_to_ball(self):

		self.i = 0

		while self.referee_module.game_status():
			coordinates = self.get_coordinates.get_coordinates()
			ball_coordinates = coordinates["ball"]
			self.mainboard_controller.ping()
			self.mainboard_controller.start_dribbler()  # just in case the dribbler did not start

			if ball_coordinates != -1 or self.mainboard_controller.has_ball():

				if self.mainboard_controller.has_ball():
					print("has ball")
					self.drive_controller.stop()
					self.to_goal.turns_searching = 0
					self.to_goal.turn()
					continue

				yellow_coordinates = coordinates["yellow"]
				blue_coordinates = coordinates["blue"]
				print(blue_coordinates)
				if blue_coordinates != -1:
					print(blue_coordinates[2])

				if (yellow_coordinates != -1 and yellow_coordinates[2] > 400) or (blue_coordinates != -1 and blue_coordinates[2] > 400):
					print("goal too close!")
					self.drive_controller.stop()
					self.turn_around()

				black_coordinates = coordinates["black"]

				if black_coordinates != -1 and black_coordinates[3] > 400 and black_coordinates[2] > 400:
					print("darkness ahead")

				if self.i > 5:
					self.drive_controller.stop()

				self.drive_controller.drive(ball_coordinates)
				self.i = 0

			else:
				# to avoid cases when just losing the blob for one frame
				self.i += 1
				if self.i > 3:
					self.drive_controller.circle()

				if self.i > 15:
					drive_to_goal(self.get_coordinates, self.drive_controller, self.mainboard_controller)
Пример #2
0
    def turn(self):

        goal_coordinates = self.get_goal_coordinates()

        while goal_coordinates == -1 and self.referee_module.game_status() and self.mainboard_controller.has_ball():
            self.mainboard_controller.ping()
            self.turns_searching += 1
            self.drive_controller.around_ball(-5)
            goal_coordinates = self.get_goal_coordinates()

            # it cannot find gate (might be in the corner)
            if self.turns_searching > 15:
                drive_to_goal(self.get_coordinates, self.drive_controller, self.mainboard_controller)

        self.drive_controller.stop()

        in_this = 0
        while self.referee_module.game_status() and self.mainboard_controller.has_ball():
            self.mainboard_controller.ping()
            in_this += 1
            goal_coordinates = self.get_goal_coordinates()

            if goal_coordinates == -1:
                if in_this < 2:
                    continue
                self.turn()
                break

            if in_this > 5:  # searching for the gate too long already
                print("Searched for too long")
                self.kick()

            opponent_x = goal_coordinates[0]
            width = goal_coordinates[2]

            if opponent_x < 350 - width / 4:
                self.drive_controller.around_ball(2)
            elif opponent_x > 350 + width / 4:
                self.drive_controller.around_ball(-2)
            else:  # facing goal
                print("facing!")
                self.drive_controller.stop()
                self.kick()
                break