Skip to content

Commit 4134729

Browse files
committed
refactor start scripts and binaries for improved clarity and functionality
1 parent e1adfb8 commit 4134729

File tree

9 files changed

+61
-322
lines changed

9 files changed

+61
-322
lines changed

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
# Sample Python Base Code (gRPC)
1+
# PY2D Soccer Simulation Base Code
22

33
[![Documentation Status](https://readthedocs.org/projects/clsframework/badge/?version=latest)](https://clsframework.github.io/docs/introduction/)
44
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
55

6-
This repository contains a sample decision-making server for the RoboCup 2D Soccer Simulation, which allows you to create a team by using Python. This server is compatible with the [Cross Language Soccer Framework](https://arxiv.org/pdf/2406.05621). This server is written in Python and uses gRPC to communicate with the [proxy](https://github.com/CLSFramework/soccer-simulation-proxy).
7-
8-
The Soccer Simulation Server sends the observations to the proxy, which processes the data, create state message and sends it to the decision-making server. The decision-making server then sends the actions to the proxy, and then the proxy convert actions to the server commands and sends them to the server.
6+
![alt text](image.png)
7+
PY2D Soccer Simulation Base Code is a base code for RoboCup 2D Soccer Simulation teams, which is written in Python.
8+
This base code is powered by the [Cross Language Soccer Framework](https://arxiv.org/pdf/2406.05621), which allows you to create a team by using any programming language that supports gRPC or Thrift.
9+
This base code uses `Helios Base` as a proxy to communicate with the RoboCup 2D Soccer Simulation server.
10+
PY2D base is the most power full base code for RoboCup 2D Soccer Simulation which developed in Python.
911

1012
For more information, please refer to the [documentation](https://clsframework.github.io/).
1113

@@ -24,8 +26,8 @@ sudo apt-get install fuse #Used to run AppImages
2426
Clone this repository & install the required python libraries (such as gRPC). Don't forget to activate your virtual environment!
2527

2628
``` Bash
27-
git clone https://github.com/CLSFramework/sample-playmaker-server-python-grpc.git
28-
cd sample-playmaker-server-python-grpc
29+
git clone https://github.com/CLSFramework/py2d.git
30+
cd py2d
2931
# Activate venv/anaconda before this step!
3032
pip install -r requirements.txt
3133

@@ -63,7 +65,9 @@ cd scripts/rcssserver
6365
Then we must run the proxy & the decisionmaking server:
6466

6567
``` Bash
66-
./start-team.sh
68+
./start.sh
69+
// or
70+
python3 start.py
6771
```
6872

6973
### Options

image.png

3.72 MB
Loading

scripts/create_binary.sh

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,22 @@ cp -r ../src/formations binary/src/formations
2424

2525
# create binary
2626

27-
nuitka --standalone --onefile --output-dir=binary ../start_agent.py
27+
nuitka --standalone --onefile --output-dir=binary ../start.py
2828

2929
# remove build directory
3030

31-
rm -rf binary/start_agent.build
32-
rm -rf binary/start_agent.dist
33-
rm -rf binary/start_agent.onefile-build
31+
rm -rf binary/start.build
32+
rm -rf binary/start.dist
33+
rm -rf binary/start.onefile-build
3434

35-
# copy start_agents.sh to binary directory
35+
# copy start.sh to binary directory
3636

37-
cp ../start_agents.sh binary/start_agents.sh
37+
cp ../start.sh binary/start.sh
3838

39-
# change all `python3 start_agent.py`` to ./start_agent.bin in binary/start_agents.sh
39+
# change start.sh to run binary instead of python and to use separate rpc server
4040

41-
sed -i 's/run_bin=false/run_bin=true/g' binary/start_agents.sh
41+
sed -i 's/run_bin=false/run_bin=true/g' binary/start.sh
42+
sed -i 's/separate_rpc_server=false/separate_rpc_server=true/g' binary/start.sh
4243

4344
# copy start to binary directory
4445

scripts/start

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ options="--team_name $teamname --server-host $HOST --use-random-port --close-ser
1212

1313
case $NUM in
1414
1)
15-
./start_agent.bin $options --goalie
15+
./start.bin $options --goalie
1616
;;
1717
12)
18-
./start_agent.bin $options --coach
18+
./start.bin $options --coach
1919
;;
2020
*)
21-
./start_agent.bin $options
21+
./start.bin $options --player
2222
;;
2323
esac

scripts/start_agents.sh

Lines changed: 0 additions & 66 deletions
This file was deleted.

start_agent.py renamed to start.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
from server import main
1212
import random
1313

14-
1514
# Set up logging
1615
log_dir = None
1716
start_team_logger = None
1817

19-
2018
def run_server_script(args):
2119
# Define a wrapper function to pass the arguments to the main function
2220
def server_main():
2321
import sys
24-
sys.argv = ['server.py', '--rpc-port', str(args.rpc_port), '--log-dir', log_dir, '--disable-log-file' if args.disable_log_file else '']
22+
sys.argv = ['server.py', '--rpc-port', str(args.rpc_port), '--log-dir', log_dir]
23+
if args.disable_log_file:
24+
sys.argv += ['--disable-log-file']
2525
main()
2626

2727
# Start the main function as a new process
@@ -31,12 +31,18 @@ def server_main():
3131

3232
def run_start_script(args):
3333
# Start the start.sh script in its own directory as a new process group
34-
process = subprocess.Popen(
35-
['bash', 'start-agent.sh' if not args.debug else 'start-debug.sh',
36-
'-t', args.team_name,
34+
arguments = ['bash']
35+
if args.player or args.coach or args.goalie:
36+
arguments += ['start-agent.sh', '--coach' if args.coach else '--goalie' if args.goalie else '--player']
37+
else:
38+
arguments += ['start.sh' if not args.debug else 'start-debug.sh']
39+
40+
arguments += ['-t', args.team_name,
3741
'--rpc-port', args.rpc_port, '--rpc-type', 'grpc',
38-
'-p', args.server_port, '-h', args.server_host,
39-
'--coach' if args.coach else '--goalie' if args.goalie else '--player'],
42+
'-p', args.server_port, '-h', args.server_host]
43+
44+
process = subprocess.Popen(
45+
arguments,
4046
cwd='scripts/proxy', # Corrected directory to where start.sh is located
4147
preexec_fn=os.setsid, # Create a new session and set the process group ID
4248
stdout=subprocess.PIPE,
@@ -46,7 +52,6 @@ def run_start_script(args):
4652

4753
stop_thread = threading.Event()
4854

49-
5055
def stream_output_to_file(process, name, args):
5156
# Stream output from the process and log it to a file with the given name
5257
f = None if args.disable_log_file else open(f"{log_dir}/{name}.log", "a")
@@ -88,6 +93,7 @@ def kill_rpc_server_process(process):
8893
parser.add_argument('--server-host', required=False, help='The host of the server', default='localhost')
8994
parser.add_argument('--server-port', required=False, help='The port of the server', default='6000')
9095
parser.add_argument('--close-server', required=False, help='Close the server', default=False, action='store_true')
96+
parser.add_argument('--player', required=False, help='Use coach instead of proxy', default=False, action='store_true')
9197
parser.add_argument('--coach', required=False, help='Use coach instead of proxy', default=False, action='store_true')
9298
parser.add_argument('--goalie', required=False, help='Use goalie instead of proxy', default=False, action='store_true')
9399
parser.add_argument('--disable-log-file', required=False, help='Disable logging to a file', default=False, action='store_true')
@@ -99,9 +105,8 @@ def kill_rpc_server_process(process):
99105
log_dir = os.path.join(os.getcwd(), 'logs', f"{datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}_{random.randint(100000, 999999)}")
100106
else:
101107
log_dir = args.log_dir
102-
start_team_logger = setup_logger('start-team', log_dir, console_level=logging.DEBUG, file_level=logging.DEBUG if not args.disable_log_file else None,
103-
console_format_str='%(message)s')
104-
108+
start_team_logger = setup_logger('start-team', log_dir, console_level=logging.DEBUG, file_level=logging.DEBUG if not args.disable_log_file else None, console_format_str='%(message)s')
109+
105110
start_team_logger.debug(f"Arguments: {args=}")
106111

107112
try:

start_agents.sh renamed to start.sh

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ server_host=127.0.0.1
66
server_port=6000
77
disable_log_file=false
88
run_bin=false
9+
separate_rpc_server=false
910

1011
while [ $# -gt 0 ]
1112
do
@@ -24,6 +25,9 @@ do
2425
--run-bin)
2526
run_bin=true
2627
;;
28+
--separate-rpc-server)
29+
separate_rpc_server=true
30+
;;
2731
*)
2832
echo 1>&2
2933
echo "invalid option \"${1}\"." 1>&2
@@ -65,28 +69,33 @@ else
6569
options="$options --disable-log-file"
6670
fi
6771

68-
# Run start_agent.py or start_agent.bin
72+
# Run start.py or start.bin
6973
if [ $run_bin = true ]; then
70-
run_command="./start_agent.bin"
74+
run_command="./start.bin"
7175
else
7276
# active .venv
7377
source $python_env
74-
run_command="python3 start_agent.py"
78+
run_command="python3 start.py"
7579
fi
7680

77-
# Run start_agent.py 11 times and store each PID in the array
78-
$run_command $options --goalie &
79-
pids+=($!)
81+
if [ $separate_rpc_server = true ]; then
82+
# Run start_agent.py 11 times and store each PID in the array
83+
$run_command $options --goalie &
84+
pids+=($!)
8085

81-
sleep 2
86+
sleep 2
8287

83-
for i in {2..11}; do
88+
for i in {2..11}; do
89+
$run_command $options --player &
90+
pids+=($!)
91+
done
92+
93+
$run_command $options --coach &
94+
pids+=($!)
95+
else
8496
$run_command $options &
8597
pids+=($!)
86-
done
87-
88-
$run_command $options --coach &
89-
pids+=($!)
98+
fi
9099

91100
# Wait for all background processes to finish
92101
for pid in "${pids[@]}"; do

0 commit comments

Comments
 (0)