gazebosim / gazebo_test_cases

4 stars 1 forks source link

gz-sim: Physics engines #1260

Closed azeey-test closed 1 week ago

azeey-test commented 2 weeks ago

Configuration

Links

Process

Step 1 - Instructions work

Step 2 - Images (if there are any) match the result

Combuster54 commented 1 week ago

Interested

Combuster54 commented 1 week ago

Ubuntu 24.04 Noble

Setting helloWorldPlugin

combuster@combuster54:~/test/gazebo-ionic-physics/hello_world_loader/build$ sudo ln -s ~/test/gazebo-ionic-physics/hello_world_loader/build/libHelloWorldPlugin.so /usr/lib/x86_64-linux-gnu/gz-physics-8/engine-plugins/libHelloWorldPlugin.so
combuster@combuster54:~/test/gazebo-ionic-physics/hello_world_loader/build$ sudo ln -s ~/test/gazebo-ionic-physics/hello_world_loader/build/libHelloWorldPlugin.so /home/physics_engines/libHelloWorldPlugin.so
combuster@combuster54:~/test/gazebo-ionic-physics/hello_world_plugin/build$ export GZ_SIM_PHYSICS_ENGINE_PATH=/home/physics_engines
combuster@combuster54:~/test/gazebo-ionic-physics/hello_world_plugin/build$ echo $GZ_SIM_PHYSICS_ENGINE_PATH
/home/physics_engines

Tell Gazebo what engine to load

From SDF

<?xml version="1.0" ?>
<sdf version="1.7">
  <world name="custom_world">

    <plugin
      filename="libHelloWorldPlugin.so"
      name="mock::HelloWorldPlugin">
      <engine>
        <filename>HelloWorld</filename>
      </engine>
    </plugin>

    <light name="sun" type="directional">
      <cast_shadows>true</cast_shadows>
      <pose>0 0 10 0 -0 0</pose>
      <diffuse>0.8 0.8 0.8 1</diffuse>
      <specular>0.2 0.2 0.2 1</specular>
      <attenuation>
        <range>1000</range>
        <constant>0.9</constant>
        <linear>0.01</linear>
        <quadratic>0.001</quadratic>
      </attenuation>
      <direction>-0.5 0.5 -1</direction>
    </light>

  </world>
</sdf>
combuster@combuster54:~/test/gazebo-ionic-physics/hello_world_loader/build$ ./hello_world_loader ~/test/gazebo-ionic-physics/hello_world_plugin/build/libHelloWorldPlugin.so 
Testing plugin: mock::HelloWorldPlugin
  engine name: HelloWorld
combuster@combuster54:~/test/gazebo-ionic-physics/hello_world_loader/build$ ./hello_world_loader /home/physics_engines/libHelloWorldPlugin.so 
Testing plugin: mock::HelloWorldPlugin
  engine name: HelloWorld
combuster@combuster54:~/test/gazebo-ionic-physics/hello_world_loader/build$ ./hello_world_loader /usr/lib/x86_64-linux-gnu/gz-physics-8/engine-plugins/libHelloWorldPlugin.so
Testing plugin: mock::HelloWorldPlugin
  engine name: HelloWorld
combuster@combuster54:~/test/gazebo-ionic-physics/hello_world_loader/build$ ls /home/physics_engines/libHelloWorldPlugin.so /usr/lib/x86_64-linux-gnu/gz-physics-8/engine-plugins/libHelloWorldPlugin.so
/home/physics_engines/libHelloWorldPlugin.so
/usr/lib/x86_64-linux-gnu/gz-physics-8/engine-plugins/libHelloWorldPlugin.so
combuster@combuster54:~/test/gazebo-ionic-physics/hello_world_loader/build$ cd
combuster@combuster54:/home$ gz sim ~/test/gazebo-ionic-physics/world/physic_plugin_world.sdf
(2024-09-03 14:22:37.770) [error] Failed to load system plugin [libHelloWorldPlugin.so] : Could not find shared library.

error (2024-09-03 14:22:37.770) [error] Failed to load system plugin [libHelloWorldPlugin.so] : Could not find shared library.

From command Trying with other names... same output

combuster@combuster54:~$ gz sim --physics-engine HelloWorld
(2024-09-03 14:13:02.207) [error] Failed to find plugin [HelloWorld]. Have you checked the GZ_SIM_PHYSICS_ENGINE_PATH environment variable?
libEGL warning: egl: failed to create dri2 screen
libEGL warning: egl: failed to create dri2 screen
libEGL warning: egl: failed to create dri2 screen
^Ccombuster@combuster54:~$ gz sim --physics-engine libHelloWorldPlugin
(2024-09-03 14:13:46.156) [error] No physics plugins found in library [/usr/lib/x86_64-linux-gnu/gz-physics-8/engine-plugins/libHelloWorldPlugin.so].
libEGL warning: egl: failed to create dri2 screen
libEGL warning: egl: failed to create dri2 screen
libEGL warning: egl: failed to create dri2 screen
^Ccombuster@combuster54:~$ 

Using absolute path inside filename

  filename="/home/physics_engines/libHelloWorldPlugin.so"
combuster@combuster54:/home$ gz sim ~/test/gazebo-ionic-physics/world/physic_plugin_world.sdf
libEGL warning: egl: failed to create dri2 screen
libEGL warning: egl: failed to create dri2 screen
libEGL warning: egl: failed to create dri2 screen

works as expected.

I create this repo to make these tests: https://github.com/Combuster54/gazebo-ionic-physics

It's a copy of gz-physics examples with some changes in CMakeLists.txt to use gz-sim8 and gz-plugin-3

I'm not sure if I've done something wrong... any feedback?

iche033 commented 1 week ago

Here's the updated SDF file that should fix the issue:

<?xml version="1.0" ?>
<sdf version="1.7">
  <world name="custom_world">

    <plugin
      filename="gz-sim-physics-system"
      name="gz::sim::systems::Physics">
      <engine>
        <filename>HelloWorldPlugin</filename>
      </engine>
    </plugin>

    <light name="sun" type="directional">
      <cast_shadows>true</cast_shadows>
      <pose>0 0 10 0 -0 0</pose>
      <diffuse>0.8 0.8 0.8 1</diffuse>
      <specular>0.2 0.2 0.2 1</specular>
      <attenuation>
        <range>1000</range>
        <constant>0.9</constant>
        <linear>0.01</linear>
        <quadratic>0.001</quadratic>
      </attenuation>
      <direction>-0.5 0.5 -1</direction>
    </light>

  </world>
</sdf>

This may be a little confusing but to clarify, there are different types of plugins. Your original SDF file tells gz sim to find and load a "gz-sim system" (also known as a plugin) named HelloWorldPlugin.

In the case of this tutorial, we want to load a "gz-physics plugin". This type of plugin is loaded by the gz-sim-physics-system. Effectively what gz sim is doing is that it first loads a gz-sim-physics-system which in turn loads a gz-physics plugin. So we'll need to keep the gz-sim-physics-system plugin in the SDF file and tell it to load the HelloWorldPlugin gz physics plugin. Hopefully that clears things up.

Note you'll still see this error msg:

(2024-09-06 00:50:05.722) [error] [Physics.cc:854] No physics plugins found in library [/home/iche/code/gz_i_ws_noble2/src/gz-physics/examples/hello_world_plugin/build/libHelloWorldPlugin.so].

which is fine (but misleading) for the purpose of this tutorial. There's an expectation by the gz-sim-physics-system that a physics plugin has to implement certain features but those features are missing in this simple HelloWorldPlugin.

Combuster54 commented 1 week ago

Oh... I try with this sintax before... I thought that I was wrong so I decided to find another way.

image

So, is this correct?

Combuster54 commented 1 week ago

Perhaps we can add a note inside this tutorial related to (2024-09-06 00:50:05.722) [error] [Physics.cc:854] No physics plugins found in library [/home/iche/code/gz_i_ws_noble2/src/gz-physics/examples/hello_world_plugin/build/libHelloWorldPlugin.so].

iche033 commented 1 week ago

updated the error msg and added an entry in the troubleshooting section about this msg in https://github.com/gazebosim/gz-sim/pull/2604