# Apollo Mujoco base code for training on GPU

This is a Python-based base code developed for the RCSSServerMJ. It was created to simplify the onboarding process for new teams joining the RoboCup 3D Soccer Simulation League using the Mujoco Simulator.

This code was influenced by the early demonstrations from MagmaOffenburg team of a client for the RCSSServerMJ, and the FCPortugal base code for the SimSpark simulator.

## Installation

### Make sure the following are installed on your system:

- Python = 3.11

- Any Python dependency manager can be used, but **either Poetry is recommended**.

### Install Dependencies
The project dependencies are listed inside pyproject.toml

- IsaacLab and IsaacSim
```bash
# Create a virtual environment using one of the package managers:

  conda create -n env_isaaclab python=3.11
  conda activate env_isaaclab

# Ensure the latest pip version is installed. 
# To update pip, run the following command from inside the virtual environment:

  pip install --upgrade pip
  
# Install the Isaac Lab packages along with Isaac Sim:

  pip install isaaclab[isaacsim,all]==2.3.2.post1 --extra-index-url https://pypi.nvidia.com
  
# Install a CUDA-enabled PyTorch 2.7.0 build for CUDA 12.8 that matches your system architecture:

  pip install -U torch==2.7.0 torchvision==0.22.0 --index-url https://download.pytorch.org/whl/cu128

# To use rl_games for training and inferencing, install its Python 3.11 enabled fork:

  pip install # rl_games or rsl_rl or stable-baselines3 based on your model
```

## Instructions

### Run an agent
After installing the dependencies and setting up the environment, you can launch a player instance:

```bash
python3 run_player.py -n <player-number> -t <team-name>
```

CLI parameter (a usage help is also available):

- `--host <ip>` to specify the host IP (default: 'localhost')
- `--port <port>` to specify the agent port (default: 60000)
- `-n <number>` Player number (1–11) (default: 1)
- `-t <team_name>` Team name (default: 'Default')


### Run a team
You can also use a shell script to start the entire team, optionally specifying host and port:

```bash
./start.sh [host] [port]
```


CLI parameter:

- `[host]` Server IP address (default: 'localhost')
- `[port]` Server port for agents (default: 60000)

### Binary building
To compete, a binary is needed. It provides a compact, portable version and protects the source code. To create a binary, just run the script ```build_binary.sh```

```bash
./build_binary.sh <team-name>
```

Once binary generation is finished, the result will be inside the build folder, as ```<team-name>.tar.gz```

### Authors and acknowledgment
This project was developed and contributed by:
- **Chenxi Liu**
- **Xuehao Xu**

### Thanks for 
- **Alan Nascimento**
- **Luís Magalhães**
- **Pedro Rabelo**
- **Melissa Damasceno**

Contributions, bug reports, and feature requests are welcome via pull requests.
