Skip to content

Commit

Permalink
Fix pattern preset to be loaded using env variable (#13)
Browse files Browse the repository at this point in the history
* Locate presets with environment variable

* Move presets

* Update README

* Update README.md

Co-authored-by: Piotr Rybicki <piotr.rybicki@robotec.ai>

* Revert lidar_patterns name

---------

Co-authored-by: Piotr Rybicki <piotr.rybicki@robotec.ai>
  • Loading branch information
msz-rai and prybicki authored Apr 4, 2023
1 parent f2c5b35 commit 3995404
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 8 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Key features:

## Requirements:

- OS: Linux
- OS: [Ubuntu 20.04](https://releases.ubuntu.com/focal/) or [Ubuntu 22.04](https://releases.ubuntu.com/jammy/)

- Gazebo: [Fortress 6.14](https://gazebosim.org/docs/fortress/install)

Expand Down Expand Up @@ -73,6 +73,13 @@ ign gazebo sonoma_with_rgl.sdf
2. The lidar hits should be visible in the GUI
3. You can control the car using the Teleop plugin (preferably changing the steering to the keyboard and upping the speed to 15)

The second sample world (rgl_playground.sdf) contains all supported object types with this plugin. Since the pattern_type is configured as `pattern_preset`, it is required to set `RGL_PATTERNS_DIR` environment variable before running the simulation:
```shell
# From the top-level directory of this repository
export RGL_PATTERNS_DIR=`pwd`/lidar_patterns
ign gazebo test_world/rgl_playground.sdf
```

## Using the plugin:

RGLServerPlugin contains two plugins: `RGLServerPluginManager` and `RGLServerPluginInstance`. For the plugin to work properly, we need to include both.
Expand Down Expand Up @@ -146,7 +153,7 @@ Inside the link entity in your model, add a custom sensor:
```

- **pattern_preset**\
You can type in the name of a LiDAR to use its pattern (all available patterns are shown below).
We have prepared several lidar presets. You can type in the name of a LiDAR to use its pattern (all available patterns are shown below).
```xml
<pattern_preset>Alpha Prime</pattern_preset>
<pattern_preset>Puck</pattern_preset>
Expand All @@ -155,6 +162,11 @@ Inside the link entity in your model, add a custom sensor:
<pattern_preset>Pandar64</pattern_preset>
<pattern_preset>Pandar40P</pattern_preset>
```
**Note:** Before launching the simulation it is required to set `RGL_PATTERNS_DIR` environment variable with the path to pattern presets directory (`lidar_patterns` from repository).
```shell
# For example
export RGL_PATTERNS_DIR=`pwd`/lidar_patterns
```

- **pattern_preset_path**\
If you wish so, You can create your own preset by providing a binary file with the structure below repeated as many times as you fancy. Please note that an absolute path is required.
Expand Down
2 changes: 0 additions & 2 deletions RGLServerPlugin/include/LidarPatternLoader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ private:

static std::map<std::string, std::string> presetNameToFilename;
static std::map<std::string, LoadFuncType> patternLoadFunctions;

static const std::filesystem::path PRESETS_DIR;
};

} // namespace rgl
13 changes: 9 additions & 4 deletions RGLServerPlugin/src/LidarPatternLoader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <cstdlib>

#include "LidarPatternLoader.hh"

#define PATTERNS_DIR_ENV "RGL_PATTERNS_DIR"

using namespace std::placeholders;
namespace fs = std::filesystem;

namespace rgl
{

const fs::path LidarPatternLoader::PRESETS_DIR = fs::path(__FILE__).parent_path().parent_path() / "lidar_patterns";

std::map<std::string, std::string> LidarPatternLoader::presetNameToFilename = {
{"Alpha Prime", "VelodyneVLS128.mat3x4f"},
{"Puck", "VelodyneVLP16.mat3x4f"},
Expand Down Expand Up @@ -186,11 +188,14 @@ bool LidarPatternLoader::LoadPatternFromPreset(const sdf::ElementConstPtr& sdf,
ignerr << "Failed to load preset pattern. Preset '" << presetName << "' is not available.\n";
return false;
}
fs::path presetPath = PRESETS_DIR / presetNameToFilename[presetName];
fs::path presetPath = presetNameToFilename[presetName];
if (const char* presetDir = std::getenv(PATTERNS_DIR_ENV)) {
presetPath = fs::path(presetDir) / presetNameToFilename[presetName];
}
ignmsg << "Loading pattern_preset '" << presetName << "'...\n";
outPattern = LoadVector<rgl_mat3x4f>(presetPath);
if (outPattern.size() == 0) {
ignerr << "Failed to load preset.\n";
ignerr << "Failed to load preset. Make sure the environment variable '" << PATTERNS_DIR_ENV << "' is set correctly.\n";
return false;
}
return true;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 3995404

Please sign in to comment.