From c4844175100fa2a91c5a6f79b4b070e906e012d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Carlos=20Tonon=20Campi?= Date: Wed, 13 Oct 2021 11:47:53 -0300 Subject: [PATCH 1/3] Testando alteracoes do 3v3 no 5v5 --- action.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++----- behaviours.py | 2 +- execution.py | 2 +- simClasses.py | 9 +++++--- 4 files changed, 63 insertions(+), 11 deletions(-) diff --git a/action.py b/action.py index 79f3f75..a8a18e4 100644 --- a/action.py +++ b/action.py @@ -24,7 +24,7 @@ def shoot(robot,ball,leftSide=True,friends=[],enemys=[]): robot.simSetVel(v,w) -def defenderSpin(robot,ball,leftSide=True,friends=[],enemys=[]): +def defenderSpin2(robot,ball,leftSide=True,friends=[],enemys=[]): if leftSide: arrivalTheta=arctan2(90-ball.yPos,235-ball.xPos) #? Angle between the ball and point (150,65) else: @@ -58,26 +58,75 @@ def defenderSpin(robot,ball,leftSide=True,friends=[],enemys=[]): robot.simSetVel(v,w) +def defenderSpin(robot,ball,leftSide=True,friends=[],enemys=[]): + if leftSide: + arrivalTheta=arctan2(90-ball.yPos,235-ball.xPos) #? Angle between the ball and point (150,65) + else: + arrivalTheta=arctan2(90-ball.yPos,15-ball.xPos) #? Angle between the ball and point (0,65) + #robot.target.update(ball.xPos,ball.yPos,0) + robot.target.update(ball.xPos,ball.yPos,arrivalTheta) + + if not friends: #? No friends to avoid + v,w=univecController(robot,robot.target,avoidObst=False,n=16, d=2) + else: #? Both friends to avoid + #robot.obst.update(robot,friend1,friend2,enemy1,enemy2,enemy3) + robot.obst.update2(robot, ball, friends, enemys) + v,w=univecController(robot,robot.target,True,robot.obst,n=4, d=4) + + d = robot.dist(ball) + if robot.spin and d < 10: + if not robot.teamYellow: + if robot.yPos > 90: + v = 0 + w = -30 + else: + v = 0 + w = 30 + else: + if robot.yPos > 90: + v = 0 + w = 30 + else: + v = 0 + w = -30 + if d < 30 and ball.xPos > robot.xPos: + if robot.teamYellow: + dx = 15-robot.xPos + else: + dx = 235 - robot.xPos + dy = tan(robot.theta)*dx + robot.yPos + if dy > 70 and dy < 110: + if robot.index == 2 or robot.index == 1: + robot.simSetVel2(50*robot.face, 50*robot.face) + else: + robot.simSetVel(v,w) + else: + robot.simSetVel(v,w) + else: + robot.simSetVel(v,w) + #TODO #2 Need more speed to reach the ball faster than our enemy def screenOutBall(robot,ball,staticPoint,leftSide=True,upperLim=200,lowerLim=0,friend1=None,friend2=None): + xPos = ball.xPos + ball.vx*100*22/60 # Só mudei isso + yPos = ball.yPos + ball.vy*100*22/60 #Check if ball is inside the limits - if ball.yPos >= upperLim: + if yPos >= upperLim: yPoint = upperLim - elif ball.yPos <= lowerLim: + elif yPos <= lowerLim: yPoint = lowerLim else: - yPoint = ball.yPos + yPoint = yPos #Check the field side if leftSide: - if robot.yPos <= ball.yPos: + if robot.yPos <= yPos: arrivalTheta=pi/2 else: arrivalTheta=-pi/2 robot.target.update(staticPoint,yPoint,arrivalTheta) else: - if robot.yPos <= ball.yPos: + if robot.yPos <= yPos: arrivalTheta=pi/2 else: arrivalTheta=-pi/2 diff --git a/behaviours.py b/behaviours.py index 9cd0382..3b1c663 100644 --- a/behaviours.py +++ b/behaviours.py @@ -7,7 +7,7 @@ class Univector: def __init__(self): #? Constants learned from EP self.d_e=6 # Constante relacionada ao tamanho das espirais - self.k_r=7 # Constante de suavização do campo + self.k_r=3 # Constante de suavização do campo self.delta=5 # Variancia da gaussiana de obstaculo self.k_o=0.5 # Constante de proporcionalidade velocidade do obstaculo self.d_min=5 #* => modified: EP = 3.48 # Distancia mínima em que o campo se torna puro repulsivo diff --git a/execution.py b/execution.py index fb1e6ea..74cd39e 100644 --- a/execution.py +++ b/execution.py @@ -35,7 +35,7 @@ def univecController(robot,target,avoidObst=True,obst=None,n=8,d=2,stopWhenArriv #robotLockedCorner(target, robot) navigate=Univector() #? Defines the navigation algorithm dl=0.000001 #? Constant to approximate phi_v - k_w=1.9 #? Feedback constant (k_w=1 means no gain) + k_w=1.8 #? Feedback constant (k_w=1 means no gain) k_p=1 #? Feedback constant (k_p=1 means no gain) #% Correção de ângulo caso o robô esteja jogando com a face de trás diff --git a/simClasses.py b/simClasses.py index 27ba019..956dda5 100644 --- a/simClasses.py +++ b/simClasses.py @@ -129,8 +129,8 @@ def __init__(self): #% This method gets position of the ball in FIRASim def simGetPose(self, data_ball): - self.xPos = data_ball.x + data_ball.vx*100*12/60 - self.yPos = data_ball.y + data_ball.vy*100*12/60 + self.xPos = data_ball.x + data_ball.vx*100*8/60 + self.yPos = data_ball.y + data_ball.vy*100*8/60 # check if prev is out of field, in this case reflect ball moviment to reproduce the collision if self.xPos > 235: @@ -174,7 +174,10 @@ def __init__(self, index, actuator, mray): self.vTheta=0 self.vL=0 #? Left wheel velocity (cm/s) => updated on simClasses.py -> simSetVel() self.vR=0 #? Right wheel velocity (cm/s) => updated on simClasses.py -> simSetVel() - self.vMax=35 #! Robot max velocity (cm/s) + if self.index == 0: + self.vMax=35 #! Robot max velocity (cm/s) + else: + self.vMax=50 self.rMax=3*self.vMax #! Robot max rotation velocity (rad*cm/s) self.L=7.5 #? Base length of the robot (cm) self.LSimulador=6.11 #? Base length of the robot on coppelia (cm) From 9c0881bd312bbdbb4b42014261972d1416ab394c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Carlos=20Tonon=20Campi?= Date: Thu, 14 Oct 2021 23:11:19 -0300 Subject: [PATCH 2/3] Mudando posicionamento do ataque --- strategy.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/strategy.py b/strategy.py index 5b07e05..d9caee5 100644 --- a/strategy.py +++ b/strategy.py @@ -39,8 +39,8 @@ def coach(self): def basicStgDef(self): """Basic original strategy""" - action.screenOutBall(self.robot3, self.ball, 135, leftSide=not self.mray, upperLim=85, lowerLim=5) - action.screenOutBall(self.robot4, self.ball, 135, leftSide=not self.mray, upperLim=175, lowerLim=95) + action.screenOutBall(self.robot3, self.ball, 150, leftSide=not self.mray, upperLim=85, lowerLim=5) + action.screenOutBall(self.robot4, self.ball, 150, leftSide=not self.mray, upperLim=175, lowerLim=95) if not self.mray: if self.ball.xPos < 40 and self.ball.yPos > 50 and self.ball.yPos < 130: action.defenderPenalty(self.robot0, self.ball, leftSide=not self.mray) @@ -79,7 +79,7 @@ def basicStgAtt(self): action.screenOutBall(self.robot1, self.ball, 90, leftSide=not self.mray, upperLim=85, lowerLim=5) action.screenOutBall(self.robot2, self.ball, 90, leftSide=not self.mray, upperLim=175, lowerLim=95) - def penaltyModeDefensive(self): + def penaltyModeDefensive(self): '''Strategy to defend penalty situations''' action.defenderPenalty(self.robot0, self.ball, leftSide=not self.mray) From 29c00d1d582417c501e86f2bae7a4c205973422c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Carlos=20Tonon=20Campi?= Date: Thu, 14 Oct 2021 23:13:16 -0300 Subject: [PATCH 3/3] agora vai --- strategy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strategy.py b/strategy.py index d9caee5..65e68ed 100644 --- a/strategy.py +++ b/strategy.py @@ -79,7 +79,7 @@ def basicStgAtt(self): action.screenOutBall(self.robot1, self.ball, 90, leftSide=not self.mray, upperLim=85, lowerLim=5) action.screenOutBall(self.robot2, self.ball, 90, leftSide=not self.mray, upperLim=175, lowerLim=95) - def penaltyModeDefensive(self): + def penaltyModeDefensive(self): '''Strategy to defend penalty situations''' action.defenderPenalty(self.robot0, self.ball, leftSide=not self.mray)