Replace the Physical Twin with a Digital Twin Prototype and Connect it to a Digital Twin

The digital twin prototype can be used to replace the physical twin during development, including its sensors and actuators. The data from these components are provided through a virtual context. This shift from hardware-in-the-loop to software-in-the-loop development enables faster system development and allows for greater collaboration among developers, as it eliminates the need for each person to have their own PiCar-X and avoids the need to take turns using a physical device.

We have three options at this point:

Option 1: Start Digital Twin Prototype and Digital Twin with Separate Gazebo Silumation

You need to change the ROS Master Ports on one of the docker compose files, else they will conflict.

Start the Digital Twin with GAZEBO

# Build and execute the Docker Containers
docker compose -f docker-compose-core.yml build 
docker compose -f docker-compose-dtsim.yml build 
docker compose -f docker-compose-dtsim.yml up

Start the Digital Twin Prototype with GAZEBO

# Build and execute the Docker Containers
docker compose -f docker-compose-core.yml build 
docker compose -f docker-compose-dtp.yml build 
docker compose -f docker-compose-dtp.yml up

Send Commands from both directions

  • Commands on the DTP
  • Commands from the DT
# SWITCH INTO THE CONTAINER
docker exec -it picar-x-ackermann_skill-dtp-1 /bin/bash

# INSIDE CONTAINER
source /root/catkin_ws/devel/picarx_ackermann_drive/setup.bash

# PUBLISH A MESSAGE TO TURN RIGHT WITH 50 percent motor speed
rostopic pub /picarx/drive/command picarx_msgs/Drive "{speed: 50, angle: 20}"

# The status should be sent automatically to the DT and the DT also start to move. 
# SWITCH INTO THE CONTAINER
docker exec -it picar-x-ackermann_skill-dt-1 /bin/bash

# INSIDE CONTAINER
source /root/catkin_ws/devel/picarx_ackermann_drive/setup.bash

# PUBLISH A MESSAGE TO TURN RIGHT WITH 50 percent motor speed
rostopic pub /picarx/drive/command picarx_msgs/Drive "{speed: 50, angle: 20}"

# The command should be sent automatically to the DTP and the DTP also start to move. 

Option 2: Only the Digital Twin Prototype starts a simulation

Start the Digital Twin without GAZEBO

# Build and execute the Docker Containers
docker compose -f docker-compose-core.yml build 
docker compose -f docker-compose-dt.yml build 
docker compose -f docker-compose-dt.yml up

Start the Digital Twin Prototype with GAZEBO

# Build and execute the Docker Containers
docker compose -f docker-compose-core.yml build 
docker compose -f docker-compose-dtp.yml build 
docker compose -f docker-compose-dtp.yml up
  • Subscribe to Status on DT
  • Commands from the DTP
# SWITCH INTO THE CONTAINER
docker exec -it picar-x-ackermann_skill-dt-1 /bin/bash

# INSIDE CONTAINER
source /root/catkin_ws/devel/picarx_ackermann_drive/setup.bash

# SUBSCRIBE TO THE STATUS TOPIC
rostopic echo /picarx/drive/command picarx_msgs/Drive "{speed: 50, angle: 20}"

# The console should now print all incoming messages with the corresponding status from the DTP. 
# SWITCH INTO THE CONTAINER
docker exec -it picar-x-ackermann_skill-dtp-1 /bin/bash

# INSIDE CONTAINER
source /root/catkin_ws/devel/picarx_ackermann_drive/setup.bash

# PUBLISH A MESSAGE TO TURN RIGHT WITH 50 percent motor speed
rostopic pub /picarx/drive/command picarx_msgs/Drive "{speed: 50, angle: 20}"

# The status should be sent automatically to the DT and the DT prints all incoming messages. 

Option 3: Only the Digital Twin starts a simulation

Start the Digital Twin with GAZEBO

# Build and execute the Docker Containers
docker compose -f docker-compose-core.yml build 
docker compose -f docker-compose-dtsim.yml build 
docker compose -f docker-compose-dtsim.yml up

Start the Digital Twin Prototype without GAZEBO

# Build and execute the Docker Containers
docker compose -f docker-compose-core.yml build 
docker compose -f docker-compose-dtp-no-gazebo.yml build 
docker compose -f docker-compose-dtp-no-gazebo.yml up
  • Subscribe to Commands on the DTP
  • Commands from the DT
# SWITCH INTO THE CONTAINER
docker exec -it picar-x-ackermann_skill-dtp-1 /bin/bash

# INSIDE CONTAINER
source /root/catkin_ws/devel/picarx_ackermann_drive/setup.bash

# SUBSCRIBE TO THE COMMAND TOPIC
rostopic echo /picarx/drive/command

# The console should now print all incoming messages with the corresponding command from the DT. 
# SWITCH INTO THE CONTAINER
docker exec -it picar-x-ackermann_skill-dt-1 /bin/bash

# INSIDE CONTAINER
source /root/catkin_ws/devel/picarx_ackermann_drive/setup.bash

# PUBLISH A MESSAGE TO TURN RIGHT WITH 50 percent motor speed
rostopic pub /picarx/drive/command picarx_msgs/Drive "{speed: 50, angle: 20}"

# The DT sends a command to the DTP and there the command is printed.