Live Playback of a Simulation on a Remote Host¶
Overview¶
Using the “live playback” function of the world log file explained in Recording and Playing Back Logs, a simulation running on one Choreonoid can be played back and observed in real time on another Choreonoid. Furthermore, by synchronizing the log file between hosts in real time, this can also be done between different hosts. This can be utilized for monitoring a simulation running remotely, sharing the simulation status at a distant place, and so on. This page explains how to do this.
How Live Playback Works¶
In the normal playback of a world log file item, the existing log file is read and played back along the time of the time bar, and the playback ends when the end of the file is reached.
In the “live playback mode”, on the other hand, the end of the file is always read, and the time of the time bar is synchronized to it. Also, the playback does not stop when the end of the file is reached; instead, it waits for the file to be updated. With this behavior, when a simulation is running and the log file is being updated, the latest state of the simulation is always played back.
Live playback can be started by executing “Start Live Playback” from the context menu of the world log file item. To stop it, press the stop button of the time bar.
Checking on the Same Host¶
First, let’s try live playback on the same host. Prepare a project with a world log file item, start two Choreonoids on the same PC, and load the project into each of them. Then, when you run the simulation on one of them and start live playback on the other, you should be able to confirm that the scene on the live playback side is synchronized with the scene on the simulation side.
Note the following two points here:
The project on the playback side must have the models (body items) to be played back loaded. Playback is not possible with an empty project containing only the world log file item, because the log does not contain the models themselves. The project does not necessarily have to be identical to the one on the recording side, but the same models must be loaded in the same order. Loading the same project on both sides is the most reliable way.
It is recommended to set the “Time-stamp suffix” property of the world log file item to false. If this is true, the recording start time is automatically appended to the log file name, which makes it difficult to match the target log file between the two Choreonoids.
Synchronizing the Log File to a Remote Host¶
To perform live playback between different hosts, the log file on the simulation side must be synchronized to the host on the playback side in real time. With common network file systems such as sshfs, the updates of the file are not necessarily reflected in real time, and it may not work well. Therefore, Choreonoid provides a dedicated command “choreonoid-sync-logfile” for synchronizing a specified file in real time.
The actual body of this command is a shell script “misc/script/sync-logfile.sh” in the Choreonoid source. When you build and install Choreonoid with INSTALL_SYNC_LOGFILE_COMMAND set to ON in the CMake configuration, it is installed in the bin directory of Choreonoid as a command named “choreonoid-sync-logfile”. (This option is not normally displayed in the menu-style CMake configuration tools, and is displayed by switching to the Advanced Mode.)
This command is executed on the source host (the side running the simulation) as follows.
choreonoid-sync-logfile LOG_FILE USER@HOSTNAME [REMOTE_FILE]
When the remote file is omitted, the same path as the log file is used. When executed, the whole file is first copied to the remote host, and after that, the appended portions of the file are transferred to the remote host sequentially, so that the file on the remote side is synchronized in real time. Since ssh is used for the communication, synchronization is possible with any host that can be connected with ssh.
Note that if the log file does not exist yet at the time of execution, the command waits for the file to be created before starting the synchronization. This allows the arrangement of starting the synchronization command first and letting it wait, and then starting the simulation.
For example, if there is a log file “Tank.log” at “~/choreonoid/Tank.log”, executing the following in the “~/choreonoid” directory
./build/bin/choreonoid-sync-logfile Tank.log user@remotehost choreonoid/Tank.log
synchronizes “~/choreonoid/Tank.log” on the remote host.
Playback on the Remote Host¶
After starting the synchronization of the log file, start a project that loads the same log file on the remote host as well, and start live playback there. With this, what is being executed on the simulation side is played back on the remote side.
The reading behavior on the live playback side can be adjusted with the “Live playback read interval (ms)” and “Live playback read timeout” properties of the world log file item.
Note that since this mechanism only requires the log file to be synchronized, it is also possible to play back on multiple remote hosts simultaneously by executing multiple choreonoid-sync-logfile commands to synchronize to multiple hosts.
Utilizing the Log Playback Archive¶
As mentioned above, the playback side also needs a project with the same model configuration as the recording side. Preparing the set of models in advance on the playback-side host is time-consuming, and mistakes due to mismatches in the models and their arrangement are likely to happen.
By combining the “Save project as log playback archive” function explained in Recording and Playing Back Logs, this preparation can be done reliably. Specifically, the procedure is as follows:
On the simulation-side host, execute “Save project as log playback archive” for the world log file item of the target project
Transfer the saved archive zip file to the playback-side host
On the playback-side host, load the transferred zip file (the contents are extracted into the same directory as the zip file, and the playback project in it is loaded)
On the simulation-side host, start the choreonoid-sync-logfile command (with the synchronization destination set to the path of the log file in the directory extracted on the playback side)
Start live playback on the playback side, and start the simulation on the simulation side
Since the archive contains all the model files necessary for the playback, there is no need to prepare the models individually on the playback side, and no mismatch in the model configuration occurs. As only a single zip file is transferred, automating the transfer is also easy.
Note that the archive can be saved (with a confirmation) even when the log file has not been recorded yet, and an empty log file is included in the archive in that case. By utilizing this, you can finish steps 1 to 3 above and distribute the archive before executing the simulation, and then fill the empty log file with the log file transfer in step 4. This is convenient when you want to finish distributing the archive during the preparation time.