Server Example: Heightmap From Png

Overview

Loads a PNG heightmap (Zurich dataset) and drops ANYmal on it. This is the reference for heightmap-from-image workflows.

Screenshot

../../../_images/heightMapUsingPNG.gif

Binary

CMake target and executable name: heightmap_from_png.

Run

Build and run from your build directory:

cmake --build . --target heightmap_from_png
./heightmap_from_png

On Windows, run heightmap_from_png.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 heightmap directly from a PNG file with scale/offset.

  • Drops ANYmal onto the terrain and sets a terrain appearance.

  • Reference for World::addHeightMap using images.

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 "rayrai_tcp_viewer_hint.hpp"
#include <raisim/RaisimServer.hpp>

int main(int argc, char* argv[]) {
  auto binaryPath = raisim::Path::setFromArgv(argv[0]);

  /// create raisim world
  raisim::World world;
  world.setTimeStep(0.001);

  /// create objects
  auto heightMap = world.addHeightMap(binaryPath.getDirectory() + "\\rsc\\xmlScripts\\heightMaps\\zurichHeightMap.png", 0, 0, 500, 500, 0.005, -10);
  auto anymal = world.addArticulatedSystem(binaryPath.getDirectory() + "\\rsc\\anymal\\urdf\\anymal.urdf");
  anymal->setGeneralizedCoordinate({0, 0, 10.8, 1.0, 0.0, 0.0, 0.0, 0.03, 0.4, -0.8, -0.03, 0.4, -0.8, 0.03, -0.4, 0.8, -0.03, -0.4, 0.8});
  anymal->setName("anymal");
  heightMap->setAppearance("soil1");

  /// launch raisim server
  raisim::RaisimServer server(&world);
  server.launchServer();


  raisim_examples::warnIfNoClientConnected(server);
  for (int i = 0; i < 50000; i++) {
    RS_TIMED_LOOP(int(world.getTimeStep()*1e6))
    server.integrateWorldThreadSafe();
  }

  server.killServer();
}