Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/api_recv.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, match, address, port):
self.buffer_size = BUFFER_SIZE
self.decod_data = None

self.kill_recieved = False
self.kill_received = False

def connect_info(self,info_api):
self.info_api = info_api
Expand All @@ -27,7 +27,7 @@ def run(self):
self.obj_socket.bind((self.address, self.port))
print("Starting api_recv...")

while not self.kill_recieved:
while not self.kill_received:
data, origem = self.obj_socket.recvfrom(self.buffer_size)
decoded_data = json.loads(data.decode())
# Feedback commands from socket (e.g. an interface)
Expand Down
5 changes: 3 additions & 2 deletions api/new_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@ class Api(metaclass=SingletonMeta):
#sender_thread: threading.Thread

def __init__(self, address, port):
self.obj_socket: socket | None = None
self.address = address
self.port = port
self.kill_recieved = False
self.kill_received = False

# Initiate socket connection
def start(self):
self.obj_socket = socket(AF_INET, SOCK_DGRAM)

# Sends dict game data to socket listener
def send_data(self, info_api):
while not self.kill_recieved:
while not self.kill_received:
data_dict = info_api.organize_send()
msg = json.dumps(data_dict)
self.obj_socket.sendto(msg.encode(), (self.address, self.port))
Expand Down
16 changes: 16 additions & 0 deletions controller/Controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

class Controller(object):
v = 0.0; w = 0.0

def __init__(self, robot):
self.robot = robot
self.environment = robot.game.environment
self.match = robot.game.match
self.game = robot.game

def set_desired(self, desired):
self.v = desired[0]
self.w = desired[1]

def update(self):
return self.v, self.w
9 changes: 6 additions & 3 deletions controller/PID.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import math
import numpy as np

from controller.Controller import Controller


class PID(object):
def __init__(self, kp, kd ,ki, _ilimit=1000):
self.desired_PID = 0.0
Expand Down Expand Up @@ -35,10 +38,9 @@ def update_PID(self, now, fps):

return output

class Robot_PID(object):
class Robot_PID(Controller):
def __init__(self, robot, send_data=False):
self.robot = robot
self.game = self.robot.game
super().__init__(robot)

self.desired = np.array([0, 0])
self.linear_pid = PID(2, 1.2, 0)
Expand Down Expand Up @@ -75,6 +77,7 @@ def update(self):
def set_desired(self, vector):
self.desired = vector

linear_desired = 0.0; angular_desired = 0

def update_Speed(self, linear_desired, angular_desired, now_linear, now_angular):
self.linear_desired = linear_desired
Expand Down
7 changes: 3 additions & 4 deletions controller/PID_control.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import math
import numpy as np
from commons.math import speed_to_power, angle_between
from controller.Controller import Controller


def angle_adjustment(angle):
Expand All @@ -12,7 +13,7 @@ def angle_adjustment(angle):
return phi


class PID_control(object):
class PID_control(Controller):
"""
An implementation of the PID controller on linear and angular speed

Expand Down Expand Up @@ -72,12 +73,10 @@ class PID_control(object):
}

def __init__(self, robot, default_fps=60, **kwargs):
super().__init__(robot)
self.vision = robot.game.vision
self.field_w, self.field_h = robot.game.field.get_dimensions()
self.robot = robot
self.match = robot.game.match
self.desired = [0, 0]
self.environment = robot.game.environment

self.l = self.robot.dimensions.get('L')/2 # half_distance_between_robot_wheels
self.R = self.robot.dimensions.get('R') # radius of the wheel
Expand Down
11 changes: 6 additions & 5 deletions controller/noController.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
class NoController(object):
from controller.Controller import Controller


class NoController(Controller):
def __init__(self, robot):
self.robot = robot
self.environment = robot.game.environment
self.match = robot.game.match
super().__init__(robot)

def set_desired(self, desired):
self.v = desired[0]
self.w = desired[1]

def update(self):
return self.v, self.w
return self.v, self.w
9 changes: 5 additions & 4 deletions controller/simple_LQR.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import numpy as np
import numpy.linalg as la
from commons.math import speed_to_power

from controller.Controller import Controller


def py_ang(v1, v2):
""" Returns the angle in radians between vectors 'v1' and 'v2' """
cosang = np.dot(v1, v2)
Expand All @@ -15,11 +17,10 @@ def py_ang(v1, v2):
"""
EXPERIMENTAL_SPEED_CONSTANT = 7000

class SimpleLQR(object):
class SimpleLQR(Controller):
def __init__(self, robot, l=0.185):
super().__init__(robot)
self.desired = np.array([0, 0])
self.robot = robot
self.environment = robot.game.environment

self.l = l
self.L = self.robot.dimensions.get('L')
Expand Down
9 changes: 4 additions & 5 deletions controller/uni_controller.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import math
import numpy as np
from commons.math import speed_to_power
from controller.Controller import Controller

"""
Angle based controller
reffering to soccer robotics
"""


class UniController(object):
class UniController(Controller):
"""
An implementation of the Uni controller specified on the soccer robotics article

Expand All @@ -32,7 +33,7 @@ class UniController(object):
the target position used for calculating the linear speed P
"""

CONSTANTS = {
CONSTANTS = { # TODO huh dá uma olhada nisso
'simulation': {
'V_M': 100,
'R_M': 3 * 100, # 3 * V_M
Expand All @@ -48,9 +49,7 @@ class UniController(object):
}

def __init__(self, robot, control_speed=False):
self.robot = robot
self.environment = robot.game.environment
self.match = robot.game.match
super().__init__(robot)
self.L = self.robot.dimensions.get("L") # m
self.R = self.robot.dimensions.get("R") # m

Expand Down
6 changes: 4 additions & 2 deletions entities/coach/coach.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from abc import ABC, abstractmethod
from os import replace


class BaseCoach(ABC):
NAME = "BASE_COACH"

def __init__(self, match):
self.match = match

@abstractmethod
def decide (self):
def decide(self):
raise NotImplementedError("Coach needs decide implementation!")

def get_positions(self, foul, team_color, foul_color, quadrant):
return None
pass
18 changes: 10 additions & 8 deletions fields/field.py → entities/fields/field.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
import json

# TODO possivelmente mover o field para o pacote entities (só tá ele aqui)

class Field():
def __init__(self, category="3v3"):
self.game_mode = category
self.source = json.loads(open('fields.json', 'r').read())
self.field = self.source.get(self.game_mode)

#the dimensios are defined in fields.json and all of them are in meters
# the dimensions are defined in fields.json and all of them are in meters
def get_dimensions(self):
#get field dimensions and return width and height
# get field dimensions and return width and height
field_size = self.field.get('field_size', 0)
return field_size

def get_small_area(self, team):
#this function return the coordinates (x1, y1, width, height) of the small area based on arg team,
#that recieves team color
# this function return the coordinates (x1, y1, width, height) of the small area based on arg team,
# that receives team color
areas = self.field.get('small_area', 0)
small_area = areas.get(team)
return small_area

def get_quadrant_position(self, quad):
#quadrants are definied as the quadrants from trigonometry, therefore, q1 is in upper right corner
#and they are in counterclockwise.
#return quadrant positions (x, y) based on arg quad, that recieves an integer number.
# quadrants are defined as the quadrants from trigonometry, therefore, q1 is in upper right corner
# and they are in counterclockwise.
# return quadrant positions (x, y) based on arg quad, that receives an integer number.
quadrants = self.field.get('quadrant_positions')
quad_dimen = quadrants.get(f'q{quad}')
return quad_dimen

def get_free_kick_position(self, side):
#return free kick position (x, y) based on arg side, that recieves the field side
# return free kick position (x, y) based on arg side, that receives the field side
free_kicks = self.field.get("free_kick")
fk_pos = free_kicks.get(side)
return fk_pos
1 change: 0 additions & 1 deletion fields/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import vision
import match
import argparse
import fields as pitch
from entities import fields as pitch
from pyVSSSReferee.RefereeComm import RefereeComm
from commons.utils import get_config
import time
Expand Down
4 changes: 2 additions & 2 deletions main_real_life.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import comm
import match
import argparse
import fields as pitch
from entities import fields as pitch
from commons.utils import get_config
from pyVSSSReferee.RefereeComm import RefereeComm
from pySSLVision.VisionComm import SSLVision, assign_empty_values
Expand Down Expand Up @@ -97,7 +97,7 @@ def update(self):

def stop(self):
for t in threading.enumerate():
t.kill_recieved = True
t.kill_received = True



Expand Down
2 changes: 1 addition & 1 deletion match/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def update(self, frame):
entity.update(frame)


def update_information(self, **kwargs): #Function to update values recieved in api
def update_information(self, **kwargs): #Function to update values received in api
for key, value in kwargs.items():
if hasattr(self, key):
setattr(self, key, value)
Expand Down
3 changes: 2 additions & 1 deletion match/match_real_life.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
}

class MatchRealLife(object):
# TODO possivelmente remover o Match e simplesmente usar o RealLife como Match?
def __init__(self, game, team_side, team_color, coach_name=None, category="3v3", robot_ids=[0,1,2], opposite_ids=[0,1,2]):
super().__init__()
self.game = game
Expand Down Expand Up @@ -94,7 +95,7 @@ def check_foul(self, ref):
self.match_event['mine'] = ref.get_color() == self.team_color.upper()


def update_information(self, info): #Function to update values recieved in api
def update_information(self, info): #Function to update values received in api
for key, value in info.items():
setattr(self, key.lower(), value)

Expand Down
6 changes: 1 addition & 5 deletions strategy/tests/newAttacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
#from random import betavariate
#from scipy.spatial.qhull import Voronoi
import algorithms
import numpy as np
import controller
from fields.field import Field as fd
from strategy.BaseStrategy import Strategy
from commons.math import unit_vector, distance
from strategy import DebugTools
from commons.math import distance
from algorithms.astar import AStar, Node
from algorithms.astar.fieldGraph import FieldGraph
from scipy.spatial import Voronoi
Expand Down