XML Example: Templated World

Overview

Instantiates a templated XML world with parameter overrides (spawn options, counts, offsets). Use this to see how parameterized XML files can generate variants of a scene without duplicating the XML.

Binary

CMake target and executable name: xml_templated_world.

Run

Build and run from your build directory:

cmake --build . --target xml_templated_world
./xml_templated_world

On Windows, run xml_templated_world.exe instead. This example uses RaisimServer. Start a visualizer client (RaisimUnity, RaisimUnreal, or the rayrai TCP viewer) and connect to port 8080.

Details

  • Loads a templated XML world and overrides parameters at runtime.

  • Uses World::ParameterContainer to set spawn flags and counts.

  • Runs the scene with RaisimServer for visualization.

Source

// This file is part of RaiSim. You must obtain a valid license from RaiSim Tech
// Inc. prior to usage.

#include "raisim/World.hpp"
#include "raisim/RaisimServer.hpp"

int main(int argc, char* argv[]) {
  auto binaryPath = raisim::Path::setFromArgv(argv[0]);
  raisim::World::setActivationKey(binaryPath.getDirectory() + "/rsc/activation.raisim");
  raisim::RaiSimMsg::setFatalCallback([](){throw;});

  std::vector<raisim::World::ParameterContainer> params;
  params.push_back({"spawn_sphere", "true"});
  params.push_back({"spawn_box", "false"});
  params.push_back({"sphere_count", "30"});
  params.push_back({"sphere_height_offset", "3"});
  params.push_back({"laikago_start_x", "-2"});
  params.push_back({"laikago_start_y", "0"});
  params.push_back({"floor_height", "-1"});

  raisim::World world(binaryPath.getDirectory() + "/rsc/xmlScripts/templatedWorld/templatedWorld.xml", params);
  raisim::RaisimServer server(&world);
  server.launchServer();
  for (int i=0; i<10000000; i++) {
    RS_TIMED_LOOP(int(world.getTimeStep()*1e6))
    server.integrateWorldThreadSafe();
  }

  server.killServer();
}