Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve standalone examples (and a bit of example CMake) #2387

Open
wants to merge 1 commit into
base: gz-sim8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions examples/standalone/acoustic_comms_demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ will receive the signal and start moving before Daphne.

From this directory, run the following to compile:

mkdir build
cd build
cmake ..
make
```bash
cmake -B build
cmake --build build
```

## Execute Instructions

From the `build` directory, run Gazebo Sim and the example controller:
Run Gazebo Sim and the example controller:

gz sim -r ../../../worlds/acoustic_comms_demo.sdf
./acoustic_comms_demo
```bash
gz sim -r ../../worlds/acoustic_comms_demo.sdf
./build/acoustic_comms_demo
azeey marked this conversation as resolved.
Show resolved Hide resolved
```

It can be seen visually that one of the vehicles (Triton) starts moving
immediately, then afer a while Tethys will start moving, and then finally Daphne.
15 changes: 8 additions & 7 deletions examples/standalone/custom_server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ using the C++ API, instead of using Gazebo from the command line.

## Build Instructions

From this directory:
From this directory, run the following to compile:

cd gz-sim/examples/standalone/custom_server
mkdir build
cd build
cmake ..
make
```bash
cmake -B build
cmake --build build
```

## Execute Instructions

./custom_server
```bash
./build/custom_server
```

The server will run `shapes.sdf` for 100 iterations and exit. No GUI will
show up.
35 changes: 25 additions & 10 deletions examples/standalone/each_performance/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
Example program to generate performance data

### Build
## Build Instructions

cd examples/standalong/each_performance
mkdir build
cd build
cmake ..
make
From this directory, run the following to compile:

```bash
cmake -B build
cmake --build build
```

### Run

./each
```bash
cd build
./each
```

This will generate `./build/each.data` which is the performance data.

### Generate and view plots

One the above program is complete, generate the plots.

```bash
cd build
# Generate plots
gnuplot -e "filename='each.data'" ../each.gp
eog *.png
```

### Generate and view plot
You can now scroll through two plots to view performance data.

gnuplot -e "filename='each.data'" ../each.gp
eog *.png
15 changes: 6 additions & 9 deletions examples/standalone/entity_creation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,21 @@

## Build

```
mkdir build
cd build
cmake ..
make
```bash
cmake -B build
cmake --build build
```

## Run

This example only works if the world is called `empty`. Start an empty world with:

```
```bash
gz sim empty.sdf
```

Then run the create program to spawn entities into the world:

```
cd build
./entity_creation
```bash
./build/entity_creation
```
28 changes: 14 additions & 14 deletions examples/standalone/external_ecm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@
Example showing how to get a snapshot of all entities and components in a
running simulation from an external program using the state message.

## Build
## Build Instructions

From the root of the `gz-sim` repository, do the following to build the example:
From this directory, run the following to compile:

~~~
cd gz-sim/examples/standalone/external_ecm
mkdir build
cd build
cmake ..
make
~~~
```bash
cmake -B build
cmake --build build
```

This will generate the `external_ecm` executable under `build`.

## Run

Start a simulation, for example:

gz sim shapes.sdf
```bash
gz sim shapes.sdf
```

On another terminal, run the `external_ecm` executable, passing the name of the
In another terminal, from this directory, run the `external_ecm` executable, passing the name of the
running world you want to inspect:

cd gz-sim/examples/standalone/external_ecm
./external_ecm shapes
```bash
./build/external_ecm shapes
```

You should see something like this:

```
```text
$ ./external_ecm shapes

Requesting state for world [shapes] on service [/world/shapes/state]...
Expand Down
52 changes: 24 additions & 28 deletions examples/standalone/gtest_setup/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
cmake_minimum_required(VERSION 3.11.0 FATAL_ERROR)
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)

azeey marked this conversation as resolved.
Show resolved Hide resolved
project(GTestSetup)

# Find Gazebo
find_package(gz-sim8 REQUIRED)
set(GZ_SIM_VER ${gz-sim8_VERSION_MAJOR})

# Fetch and configure GTest
include(FetchContent)
FetchContent_Declare(
googletest
# Version 1.14. Use commit hash to prevent tag relocation
URL https://github.com/google/googletest/archive/f8d7d77c06936315286eb55f8de22cd23c188571.zip
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
find_package(GTest REQUIRED)
if(NOT TARGET GTest::gtest_main AND TARGET gtest_main)
add_library(GTest::gtest_main ALIAS gtest_main)
endif()

enable_testing()
include(Dart)
include(CTest)
# CTest defines "BUILD_TESTING" so that users can easily disable tests in a common way.
if(BUILD_TESTING)
# Generate tests
foreach(TEST_TARGET
command_TEST
gravity_TEST)

# Generate tests
foreach(TEST_TARGET
command_TEST
gravity_TEST)

add_executable(
${TEST_TARGET}
${TEST_TARGET}.cc
)
target_link_libraries(${TEST_TARGET}
gtest_main
gz-sim${GZ_SIM_VER}::gz-sim${GZ_SIM_VER}
)
include(GoogleTest)
gtest_discover_tests(${TEST_TARGET})
endforeach()
add_executable(
${TEST_TARGET}
${TEST_TARGET}.cc
)
target_link_libraries(${TEST_TARGET}
GTest::gtest_main
gz-sim${GZ_SIM_VER}::gz-sim${GZ_SIM_VER}
)
include(GoogleTest)
gtest_discover_tests(${TEST_TARGET})
endforeach()
endif()
39 changes: 29 additions & 10 deletions examples/standalone/gtest_setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,37 @@ The example contains 2 tests:

See the comments on the source code for more explanations.

## Build
## Build Instructions

From the root of the repository:
From this directory, run the following to compile:

cd examples/standalone/gtest_setup
mkdir build
cd build
cmake ..
make
```bash
cmake -B build
cmake --build build
```

## Run tests

cd examples/standalone/gtest_setup/build
./gravity_TEST
./command_TEST
From this directory, run the following to run tests:

### CMake 3.20 or newer

```bash
ctest --test-dir build
```

By default, ctest hides stdout from tests.
To enable test output, add `-V`.
CTest also hides colors, which can be re-enabled.
```bash
GTEST_COLOR=1 ctest -V --test-dir build
```


### CMake 3.19 or earlier

```bash
cd build
ctest
```

Copy link
Contributor

@Blast545 Blast545 May 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧑‍🌾 I think CI is complaining on this trailing newline, can you remove it?

25 changes: 13 additions & 12 deletions examples/standalone/joy_to_twist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ messages and converts publishes
[gz::msgs::Twist](https://gazebosim.org/api/msgs/9/classgz_1_1msgs_1_1Twist.html)
messages according to user-defined configuration.

## Build
## Build Instructions

From the root of the `gz-sim` repository, do the following to build the example:
From this directory, run the following to compile:

~~~
cd examples/standalone/joy_to_twist
mkdir build
cd build
cmake ..
make
~~~
```bash
cmake -B build
cmake --build build
```

This will generate the `joy_to_twist` executable under `build`.

Expand All @@ -27,7 +24,9 @@ An example file, `joy_to_twist.sdf`, is provided.

You can run the example as follows:

./joy_to_twist ../joy_to_twist.sdf
```bash
./build/joy_to_twist joy_to_twist.sdf
```

This program by itself won't do much unless there is another source of joy
messages that it can consume. See the demo below for a full integrated example.
Expand All @@ -41,8 +40,10 @@ that can be controlled using a joystick. You can run it as follows:
messages. See that standalone program's instructions to details on how
to build it. Once it's built, you can run it as follows:

cd examples/standalone/joystick
./joystick ../joystick.sdf
```bash
cd examples/standalone/joystick
./build/joystick ../joystick.sdf
```

1. On another terminal, run the `joy_to_twist` executable as described above,
which will convert joy messages to twist messages:
Expand Down
Loading
Loading