Skip to content

Commit 42364b9

Browse files
authored
Merge pull request #140 from project-neon/feat/rcx2023
Feat/rcx2023
2 parents 8b3c4aa + ebbd10c commit 42364b9

File tree

15 files changed

+845
-37
lines changed

15 files changed

+845
-37
lines changed

algorithms/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@
1212

1313
from algorithms import univector_field
1414

15+
from algorithms.univector_field import UnivectorField
16+
1517
from algorithms.RRT import rrt

comm/rl_comm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def send(self, robot_commands = []):
4040
message = "<"
4141
robot_commands = sorted(robot_commands, key = lambda i: i['robot_id'])
4242
for rb in robot_commands:
43-
message += f"{rb['robot_id']},{round(rb['wheel_left'], 2)},{round(rb['wheel_right'], 2)},"
43+
message += f"{rb['robot_id']},{round(rb['wheel_left'], 4)},{round(rb['wheel_right'], 4)},"
4444

4545
message = message[:-1] + '>'
4646

config_real_life.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"match" : {
1717
"team_side": "left",
1818
"team_color": "yellow",
19-
"coach_name": "RSM_2023",
19+
"coach_name": "RCX_2023",
2020
"category": "3v3",
2121
"robot_ids": [
2222
1,

controller/PID_control.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ class PID_control(object):
5959
# Control params
6060
'K_RHO': 500, # Linear speed gain
6161
# PID of angular speed
62-
'KP': -1000, # -700, # Proportional gain of w (angular speed), respecting the stability condition: K_RHO > 0 and KP > K_RHO
62+
'KP': -3.5, # -700, # Proportional gain of w (angular speed), respecting the stability condition: K_RHO > 0 and KP > K_RHO
6363
'KD': 0, # -180, # Derivative gain of w
64-
'KI': 0, # Integral gain of w
64+
'KI': 0 , # Integral gain of w
6565
# Max speeds for the robot
66-
'V_MAX': 150, # linear speed
67-
'W_MAX': -1, # angular speed rad/s
68-
'V_MIN': 20,
66+
'V_MAX': 0.3, # linear speed
67+
'W_MAX': -0.5, # angular speed rad/s
68+
'V_MIN': 0.1,
6969

7070
'TWO_SIDES': True
7171
}
@@ -146,7 +146,7 @@ def _update(self):
146146

147147
self.alpha_old = alpha
148148

149-
return v, w
149+
return -v, w
150150

151151
def update(self):
152152
v, w = self._update()

controller/uni_controller.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ class UniController(object):
3939
'K_P': 10
4040
},
4141
'real_life': {
42-
'V_M': 10000,
43-
'R_M': 3 * 10000, # 20 * V_M
44-
'K_W': 270, # 313,
45-
'K_P': 100
42+
'V_M': 0.5,
43+
'R_M': 0.44, # 20 * V_M
44+
'K_W': 3.5, # 313,
45+
'K_P': 1
4646
}
4747
}
4848

@@ -133,5 +133,7 @@ def update(self):
133133

134134
if self.environment == 'simulation':
135135
return tuple(np.dot(250, speed_to_power(v, w, self.L, self.R)))
136-
137-
return v, -w
136+
137+
138+
# w = w if abs(w) < 4 else 4 * w / abs(w)
139+
return -v, -w

entities/coach/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212

1313
from entities.coach.rsm2023 import Coach as RSM_2023
1414

15+
from entities.coach.rcx2023 import Coach as RCX_2023
16+
1517
_coach_list = [
1618
# Tournament coaches
1719
GuideCoach,
1820
RSMCoach,
1921
IRON_2022,
2022
IRON_2023,
2123
RSM_2023,
24+
RCX_2023,
2225
TestCoach
2326
]
2427

entities/coach/rcx2023.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from commons.math import distance_between_points
2+
from entities.coach.coach import BaseCoach
3+
import strategy
4+
5+
6+
class Coach(BaseCoach):
7+
NAME = "RCX_2023"
8+
9+
def __init__(self, match):
10+
super().__init__(match)
11+
12+
self.SS_strategy = strategy.rcx2023.ShadowAttacker(self.match)
13+
self.ST_strategy = strategy.rcx2023.MainStriker(self.match)
14+
self.GK_strategy = strategy.rcx2023.Goalkeeper(self.match)
15+
self.GK_id = 1 # Goalkeeper fixed ID
16+
17+
# self.unstucks = {r.robot_id: strategy.rsm2023.Unstuck(self.match) for r in self.match.robots if r.robot_id != self.GK_id}
18+
19+
def decide(self):
20+
GK = [i for i, r in enumerate(self.match.robots) if r.robot_id is self.GK_id][0]
21+
strikers = [r for i, r in enumerate(self.match.robots) if r.robot_id is not self.GK_id]
22+
ST, SS = self.choose_main_striker(*strikers)
23+
24+
st_strat, ss_start = self.handle_stuck(ST, SS)
25+
26+
if self.match.robots[GK].strategy is None:
27+
self.match.robots[GK].strategy = self.GK_strategy
28+
self.match.robots[GK].start()
29+
else:
30+
if self.match.robots[GK].strategy.name != self.GK_strategy:
31+
self.match.robots[GK].strategy = self.GK_strategy
32+
self.match.robots[GK].start()
33+
34+
ST.strategy = st_strat
35+
ST.start()
36+
37+
SS.strategy = ss_start
38+
SS.start()
39+
40+
def choose_main_striker(self, r1, r2):
41+
b = self.match.ball
42+
43+
a1 = distance_between_points((b.x, b.y), (r1.x, r1.y))
44+
a2 = distance_between_points((b.x, b.y), (r2.x, r2.y))
45+
46+
b1, b2 = b.x - r1.x, b.x - r2.x
47+
48+
if b1 * b2 > 0:
49+
if a1 < a2:
50+
return r1, r2
51+
return r2, r1
52+
if b1 > 0:
53+
return r1, r2
54+
return r2, r1
55+
56+
def handle_stuck(self, ST, SS):
57+
game_runing = not (self.match.game_status == 'STOP' or self.match.game_status == None)
58+
stuck_st = ST.is_stuck() and game_runing
59+
stuck_ss = SS.is_stuck() and game_runing
60+
61+
# if stuck_st and stuck_ss:
62+
# return self.unstucks[ST.robot_id], self.unstucks[SS.robot_id]
63+
#
64+
# if stuck_st and not stuck_ss:
65+
# return self.unstucks[ST.robot_id], self.ST_strategy
66+
#
67+
# if not stuck_st and stuck_ss:
68+
# return self.ST_strategy, self.unstucks[SS.robot_id]
69+
70+
return self.ST_strategy, self.SS_strategy

entities/coach/test_coach.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ def __init__(self, match):
88
super().__init__(match) # chamada do metodo da classe mae
99

1010
# vamos usar strategies de teste por enquanto, essa deixa o robo parado
11-
self._1 = strategy.tests.Idle(self.match)
12-
self._2 = strategy.tests.Foward(self.match)
11+
self._1 = strategy.tests.PIDTuner(self.match)
12+
self._2 = strategy.tests.Idle(self.match)
1313
self._3 = strategy.tests.Idle(self.match)
1414

1515
def decide(self):

strategy/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from strategy import cbfr2022
66
from strategy import iron2023
77
from strategy import rsm2023
8+
from strategy import rcx2023
89
from strategy.BaseStrategy import Strategy
910

1011
# debug tools

0 commit comments

Comments
 (0)