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

Portuguese Ledge world #172

Merged
merged 11 commits into from
Apr 14, 2022
Merged
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,45 @@ for example:
1. `~/lrauv_ws/src/lrauv-application-2/bin/LRAUV`
1. Start more `bin/LRAUV` as needed

## Levels

Some worlds support [levels](https://ignitionrobotics.org/api/gazebo/6.7/levels.html).
Levels are turned off by default, which means that all heightmap tiles will
be loaded at all times. When levels are enabled, only the tiles containing
vehicles (performers) spawned with `WorldCommPlugin` with an
[lrauv_init](https://github.com/osrf/lrauv/blob/main/lrauv_ignition_plugins/proto/lrauv_init.proto)
message will be loaded.

For example, loading without levels:

`ign gazebo -v 4 portuguese_ledge.sdf`

![portuguese_ledge_no_levels](https://user-images.githubusercontent.com/5751272/159629754-9206a9fe-eeed-4afc-a516-5c25a9fbdaf6.png)

And with levels:

`ign gazebo -v 4 portuguese_ledge.sdf --levels`

![portuguese_ledge_no_levels](https://user-images.githubusercontent.com/5751272/159813230-809d1cad-b3f5-457a-af19-3752bec0710f.gif)

#### Generating Portuguese Ledge world

The generated file is committed to the repository. Whenever it is changed, a
manual step is needed to regenerate it.
chapulina marked this conversation as resolved.
Show resolved Hide resolved

Pre-requisites:

```
sudo apt install python3-empy
```

Generate:

```
cd lrauv_ignition_plugins/worlds
python3 portuguese_ledge.py
```

### Troubleshoot

After issuing control commands, for example, rudder and thrust, if you then
Expand Down
13 changes: 13 additions & 0 deletions lrauv_ignition_plugins/src/WorldCommPlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ void WorldCommPlugin::Configure(

// Services
this->createService = "/world/" + topicWorldName + "/create";
this->performerService = "/world/" + topicWorldName + "/level/set_performer";
this->setSphericalCoordsService = "/world/" + topicWorldName
+ "/set_spherical_coordinates";

Expand Down Expand Up @@ -213,6 +214,18 @@ void WorldCommPlugin::SpawnCallback(
ignerr << "Failed to request service [" << this->createService
<< "]" << std::endl;
}
else
{
// Make spawned model a performer
ignition::msgs::StringMsg performerReq;
performerReq.set_data(_msg.id_().data());
if (!this->node.Request(this->performerService, performerReq,
&WorldCommPlugin::ServiceResponse, this))
{
ignerr << "Failed to request service [" << this->performerService
<< "]" << std::endl;
}
}
}

/////////////////////////////////////////////////
Expand Down
3 changes: 3 additions & 0 deletions lrauv_ignition_plugins/src/WorldCommPlugin.hh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ namespace tethys
/// Service to create entities
private: std::string createService;

/// Service to make spawned entities performers (for levels)
private: std::string performerService;

/// Whether the world origin's latitude and longitude have already been set.
private: bool hasWorldLatLon{false};
};
Expand Down
17 changes: 17 additions & 0 deletions lrauv_ignition_plugins/worlds/portuguese_ledge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Takes in a template and generates an SDF file.

import em
import os
import sys

def main():
in_file = 'portuguese_ledge.sdf.em'
out_file = 'portuguese_ledge.sdf'
chapulina marked this conversation as resolved.
Show resolved Hide resolved
template = open(in_file).read()
chapulina marked this conversation as resolved.
Show resolved Hide resolved
arguments = {}
result = em.expand(template, arguments)
with open(os.path.join(out_file), 'w') as outfile:
chapulina marked this conversation as resolved.
Show resolved Hide resolved
outfile.write(result)

if __name__ == '__main__':
sys.exit(main())
Loading