How to visualize simulations in drake - a generic example

145 views Asked by At

I installed drake (tried both from apt and compiler from source) and then i want to to run some examples in order to start learning the software. (I have some-experience because i have run some notebooks in pydrake). However, the some examples that also include visualization do not seem to work.

What i want:

A working simple example that uses either drake-visualizer or meldis and meshcat, written in C++, to

  1. Completely test my installation and
  2. then use it as a standard practice to build my own simulations and learn drake. (Like ros tutorials)

What i have tried:

Apt installation - 1st way:

  1. I followed these instructions to install a pre-compiled version of drake. (Apart from updating my PATH and PYTHONPATH environmental variables).

  2. I downloaded drake-external-examples to test my installation. I compiled and run the drake_cmake_installed_apt examples, and all the tests passed.

  3. Then, as i wanted to test visualization, I built drake_cmake_installed that contains the example of uniformly_accerated_particle. Here one test failed. The output is:

Running tests...
Test project /home/papaveneti/drake2/drake_examples/drake_cmake_installed/build
    Start 1: import_all_test
1/6 Test #1: import_all_test ..................   Passed    0.35 sec
    Start 2: find_resource_example
2/6 Test #2: find_resource_example ............   Passed    0.02 sec
    Start 3: find_resource_example_py
3/6 Test #3: find_resource_example_py .........   Passed    0.11 sec
    Start 4: particle_test
4/6 Test #4: particle_test ....................   Passed    0.02 sec
    Start 5: simple_bindings_test
5/6 Test #5: simple_bindings_test .............***Failed    0.21 sec
    Start 6: simple_continuous_time_system
6/6 Test #6: simple_continuous_time_system ....   Passed    0.02 sec

83% tests passed, 1 tests failed out of 6

Total Test time (real) =   0.72 sec

The following tests FAILED:
      5 - simple_bindings_test (Failed)
Errors while running CTest
make: *** [Makefile:84: test] Error 8

But from what i understant, the problem is that the module simple_bindings that is created in the example, isn't being found during the execution of simple_bindings.py. So, this doesn't affect the visualiazation.

Then, i run:

$ /opt/drake/bin/drake-visualizer & ( cd src/particles/ && exec ./uniformly_accelerated_particle)

and i get an empty window: drake_visualization

Apt installation - 2nd way:

I did the same steps, but before building and running the examples, I run:

 export PATH="/opt/drake/bin${PATH:+:${PATH}}"
  export PYTHONPATH="/opt/drake/lib/python$(python3 -c 'import sys; print("{0}.{1}".format(*sys.version_info))')/site-packages${PYTHONPATH:+:${PYTHONPATH}}"

I got exactly the same results.

Source installation:

I had the same results, while trying to run the same examples. (I think the python bindings were succesful, but i have since uninstalled it).

extra

  1. OS: ubuntu 20.04 LTS
  2. I want to use cmake (not bazel) in order to use drake alongside ros1 in the future (after i have learned the basics of drake).
  3. I want to use the C++ version of drake.
1

There are 1 answers

2
jwnimmer-tri On

The file atlas_run_dynamics.cc is an OK demo for that purpose. You can copy that file to your project, build, and run it:

add_executable(atlas_run_dynamics atlas_run_dynamics.cc)
target_link_libraries(atlas_run_dynamics drake::drake)

It adds visualization of the simulation by calling visualization::AddDefaultVisualization(&builder);, which is the canonical way to visualize to drake-visualizer and/or meldis.

By default, it runs faster than realtime so I suggest running with --simulator_target_realtime_rate=1 to slow it down.

See also drake-ros which offers a way to visualize a Drake simulation using RViz.


p.s. Sorry that the particles was broken. We intended to delete that example code but forgot to delete all of the copies.