This repo introduces three executable ROS nodes: the Rewarder, StateFormer, and Teleop nodes. These nodes are instantiated automatically by the algorithm to train a policy, but can be run individually for debugging.
# clone this repo
git clone https://github.com/ogoudey/Minecraft-Agent.git
Next get the minecraft-ROS mod. The following fork of the original is bug-free and suffices.
cd Minecraft-Agent
git clone https://github.com/ogoudey/minecraft_ros2
Now start up the container.
cd minecraft_ros2
sudo xhost +local:root # for GUI permissions for docker
sudo docker compose up # build the container
Once the container is up, in another terminal:
cd Minecraft-Agent
./copy_scripts.sh # puts custom code in the container
./bash.sh # shortcut for entering the running container
. quickstart.sh # sources all the ROS workspaces, makes Python venv and moves cwd to the custom ROS workspace
- Start Minecraft (if container isn't already up):
cd minecraft_ros2
sudo xhost +local:root
sudo docker compose up
Then open up a Minecraft world.
- In another terminal:
cd Minecraft
./bash.sh
. quick_start.sh
- With the container's environments sourced, run a testing script.
ros2 run agent keys
Make sure the black popup window is in focus. WASD+space to move, arrow keys to orient, and B to dig.
Currently only one training environment is supported.
After . quick_start.sh, run:
python3 src/agent/agent/policy_performer.py --i 100 # Trains for 100 iterations.
Policy evaluation comes from the following redstone device, which senses if particular blocks are broken:
flowchart TD
Z((Minecraft))
Z -- redstone signal, RGB, D ----> R(ROS)
R -- reward, RGB, D ----> P((Agent))
P -- one-hot action --> R
R -- Twist, dig --> Z
For a tree at 0 -60 4, the Minecraft command block has the line:
execute if block 0 -60 4 minecraft:oak_log if block 0 -59 4 minecraft:oak_log if block 0 -58 4 minecraft:oak_log if block 0 -57 4 minecraft:oak_log
ROS subscribes to that particular command block by setting a redstone pub_sub block to publish from within Minecraft:
/data merge block -3 -60 16 {CustomName:"redstone/my_block",pollRate:10}
where the coordinates are of the minecraft_ros2:redstone_pub_sub block in the device above. (The ROS node Rewarder subscribes to /redstone/my_block/output so "my_block" is important.)
Hit F3 + P to enable/disable pause on lost focus. Hide the chat in settings.
(Will turn this into a CLI soon)
Brings a specified plot (any plots automatically saved in the container's workspace root) to the project root.
Brings a specified policy to the /figures. These policies are later loaded by the --checkpoint argument.
Saves the Minecraft save folder to /world_saves.
Folder of all saved Minecraft worlds
Puts the saved world into the container's Minecraft saved worlds folder, to be opened from the Minecraft GUI.
To push changes to the algorithm, performance, or reward system:
- Edit the files on host machine
- Run ./copy_scripts.sh
- From inside the container rebuild
custom_ws:colcon build && . install/setup.bash