-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from LBBassani/pathplanning
Pathplanning
- Loading branch information
Showing
30 changed files
with
565 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
""" Nome do módulo : Campo | ||
Ano de criação : 2019/10 | ||
Descrição do módulo : Modelar o campo do jogo | ||
Versão : 1.0 | ||
Pré-requisitos : WeightedGridGraph | ||
Pattern.Singleton | ||
Membros : Lorena B Bassani | ||
""" | ||
from .Patterns.Singleton import Singleton | ||
from .PathPlanning.Graph import WeightedGridGraph | ||
|
||
|
||
class Campo(WeightedGridGraph, Singleton): | ||
|
||
def __init__(self, *args, **keyargs): | ||
pass | ||
|
||
def inicializa(self, celulasX, celulasY, dimX = 150, dimY = 130): | ||
if not hasattr(self, "grade"): | ||
WeightedGridGraph.__init__(self, celulasX, celulasY) | ||
self.__h = (dimX/(celulasX - 1), dimY/(celulasY - 1)) | ||
|
||
@property | ||
def tamanhoCelula(self): | ||
return self.__h | ||
|
||
def transform2Cart(self, cel): | ||
# TODO : Ver Se as grades possuem as mesmas características de crescimento de coordenadas | ||
i, j = WeightedGridGraph.transform2Cart(self, cel) | ||
return (i*self.__h[0], j*self.__h[1]) | ||
|
||
def transform2Grid(self, cel): | ||
# TODO : Redefinir trasnformação | ||
x, y = cel | ||
return WeightedGridGraph.transform2Grid(self, (x//self.__h[0], y//self.__h[1])) | ||
|
||
def cost(self, start, goal): | ||
# TODO : Redefinir custo para variar com a proximidade a um obstáculo | ||
return WeightedGridGraph.cost(self, start, goal) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 53 additions & 2 deletions
55
new_scripts/ComportamentosJogadores/ComportamentoGoleiro.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,63 @@ | ||
""" Nome do módulo : ComportamentoGoleiro | ||
Ano de criação : 2019/10 | ||
Descrição do módulo : Comportamento de Goleiro para Jogadores | ||
Versão : 1.0 | ||
Versão : 2.0 | ||
Pré-requisitos : IComportamento | ||
Geometria | ||
Mundo, Arena, Lado | ||
Ball | ||
Jogador | ||
math | ||
Membros : Lorena Bassani | ||
""" | ||
from .IComportamento import IComportamento | ||
from ..Geometria import Ponto | ||
from ..Mundo import Mundo, Arena, Lado | ||
from ..Ball import Ball | ||
from ..Jogador import Jogador | ||
import math as m | ||
|
||
class ComportamentoGoleiro(IComportamento): | ||
def __init__(self): | ||
IComportamento.__init__(self) | ||
IComportamento.__init__(self) | ||
|
||
def definirObjetivo(self, jogador : Jogador, mundo : Mundo): | ||
""" Ideia da implementação : | ||
Posicionar o robô de forma que ele impessa a trajetória da bola | ||
Como : Calcular o angulo de abertura entre a bola e o gol | ||
Posicionar o robô onde o "triangulo" tenha base de 7,5 (tamanho do robô) | ||
""" | ||
resp = Ponto() | ||
ball = mundo.ball | ||
bx, _ = ball.posicao | ||
bt = ball.theta | ||
""" a² = b² + c² - 2bc*cos α | ||
a² - b² - c² = -2bc* cos α | ||
(b² + c² - a²)/2bc = cos α | ||
α = acos(((b² + c² - a²)/2bc)) | ||
Onde : | ||
a <- lado oposto (tamanho do gol) | ||
b e c <- lados adjascentes (distancia da bola até um dos limites do gol) | ||
α <- angulo desejado | ||
""" | ||
gol = Arena.golDireito if mundo.lado == Lado.DIREITO else Arena.golEsquerdo | ||
a = Arena.metricas["Gol"][1] | ||
b = ball.ponto.distancia(gol["Superior"]) | ||
c = ball.ponto.distancia(gol["Inferior"]) | ||
alpha = (b**2 + c**2 - a**2)/2*b*c | ||
if alpha > 1: | ||
alpha = 1.0 | ||
elif alpha < -1: | ||
alpha = -1.0 | ||
alpha = m.acos(alpha) | ||
|
||
dx = 3.75/m.tan(alpha) if m.tan(alpha) != 0 else 0 # 3.75 é metade da largura do robô de 7.5x7.5 | ||
resp.x = bx + dx if mundo.lado == Lado.DIREITO else bx - dx | ||
|
||
theta = m.fabs(bt - jogador.theta) | ||
resp.y = (resp.x/m.tan(theta)) | ||
|
||
resp.y = 100 if resp.y > 100 else 30 if resp.y < 30 else resp.y | ||
resp.posicao = (10, 65) if mundo.lado == Lado.ESQUERDO and resp.x > 37.5 else (150, 65) if mundo.lado == Lado.DIREITO and resp.x < 112.5 else resp.posicao | ||
|
||
return resp |
36 changes: 36 additions & 0 deletions
36
new_scripts/ComportamentosJogadores/ComportamentoLissajous.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" Nome do módulo : ComportamentoLissajous | ||
Ano de criação : 2019/10 | ||
Descrição do módulo : Modela um comportamento que descreve uma curva de Lissajous | ||
Versão : 1.0 | ||
Pré-requisitos : IComportamento | ||
Geometria | ||
math | ||
Membros : Lorena B Bassani | ||
""" | ||
from .IComportamento import IComportamento | ||
from ..Geometria import Ponto | ||
from ..Mundo import Mundo, Arena, Lado | ||
from ..Jogador import Jogador | ||
from ..Ball import Ball | ||
import math as m | ||
|
||
class ComportamentoLissajous(IComportamento): | ||
__PI = 3.14159 | ||
def __init__(self, A = 30, B = 100, a = 3, b = 4, sig = (__PI/2)): | ||
IComportamento.__init__(self) | ||
self.A = A | ||
self.B = B | ||
self.a = a | ||
self.b = b | ||
self.sigma = sig | ||
self.__t = 0 | ||
|
||
def definirObjetivo(self, jogador, Mundo): | ||
""" Na matemática, a curva de Lissajous (figura de Lissajous ou curva de Bowditch) | ||
é o gráfico produzido por um sistema de equações paramétricas que descreve um complexo movimento harmônico. | ||
x = A*sen(at + sig), y = B*sen(bt) | ||
""" | ||
x = self.A*m.sin(self.a*self.__t + self.sigma) | ||
y = self.B*m.sin(self.b*self.__t) | ||
self.__t += 1 | ||
return Ponto(x, y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.