Skip to content

Commit

Permalink
dot_generator tweaks for tunnels (#884)
Browse files Browse the repository at this point in the history
* Unified comms parameters across circuits.

Signed-off-by: Carlos Agüero <caguero@openrobotics.org>
  • Loading branch information
caguero authored Apr 27, 2021
1 parent f4ce7ca commit 8dd0aa3
Show file tree
Hide file tree
Showing 5 changed files with 287 additions and 45 deletions.
9 changes: 2 additions & 7 deletions subt_ign/launch/competition.ign
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,9 @@
# CommsBrokerPlugin parameters
# (default parameters can be found in subt_rf_model.h)
$commsFadingExponent = 2.5
$commsScalingFactor = 1.0
$commsFadingExponent = 1.5
$commsScalingFactor = 0.55
$commsRangePerHop = 2.0
if $circuit == "cave" || $circuit == "finals"
$commsFadingExponent = 1.5
$commsScalingFactor = 0.55
$commsRangePerHop = 2.0
end
# spawn world offset
if $circuit == "urban"
Expand Down
154 changes: 154 additions & 0 deletions subt_ign/src/ConnectionHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,160 @@ std::map<std::string, subt::ConnectionHelper::ConnectionType>
{"4-Way Finals Transition 2 Lights", subt::ConnectionHelper::TURN},
};

std::map<std::string, subt::ConnectionHelper::CircuitType>
subt::ConnectionHelper::circuitTypes =
{
{"Tunnel Tile 1", subt::ConnectionHelper::TUNNEL},
{"Tunnel Tile 1 Lights", subt::ConnectionHelper::TUNNEL},
{"Tunnel Tile 2", subt::ConnectionHelper::TUNNEL},
{"Tunnel Tile 2 Lights", subt::ConnectionHelper::TUNNEL},
{"Tunnel Tile 3", subt::ConnectionHelper::TUNNEL},
{"Tunnel Tile 3 Lights", subt::ConnectionHelper::TUNNEL},
{"Tunnel Tile 4", subt::ConnectionHelper::TUNNEL},
{"Tunnel Tile 4 Lights", subt::ConnectionHelper::TUNNEL},
{"Tunnel Tile 5", subt::ConnectionHelper::TUNNEL},
{"Tunnel Tile 5 Lights", subt::ConnectionHelper::TUNNEL},
{"Tunnel Tile 6", subt::ConnectionHelper::TUNNEL},
{"Tunnel Tile 6 Lights", subt::ConnectionHelper::TUNNEL},
{"Tunnel Tile 7", subt::ConnectionHelper::TUNNEL},
{"Tunnel Tile 7 Lights", subt::ConnectionHelper::TUNNEL},
{"Urban Straight", subt::ConnectionHelper::URBAN},
{"Urban Straight Lights", subt::ConnectionHelper::URBAN},
{"Urban Bend Right", subt::ConnectionHelper::URBAN},
{"Urban Bend Left", subt::ConnectionHelper::URBAN},
{"Urban Bend Left Lights", subt::ConnectionHelper::URBAN},
{"Urban Superpose", subt::ConnectionHelper::URBAN},
{"Urban 3-Way Right Intersection", subt::ConnectionHelper::URBAN},
{"Urban Straight Door Right", subt::ConnectionHelper::URBAN},
{"Urban Straight Door Left", subt::ConnectionHelper::URBAN},
{"Urban Straight Door Right Flipped", subt::ConnectionHelper::URBAN},
{"Urban Straight Door Right Flipped Lights",
subt::ConnectionHelper::URBAN},
{"Urban Straight Door Left Flipped", subt::ConnectionHelper::URBAN},
{"Urban Straight Door Right Extension", subt::ConnectionHelper::URBAN},
{"Urban Straight Door Right Extension Lights",
subt::ConnectionHelper::URBAN},
{"Urban Service Room Centered", subt::ConnectionHelper::URBAN},
{"Urban Service Room Centered Lights", subt::ConnectionHelper::URBAN},
{"Urban Service Room", subt::ConnectionHelper::URBAN},
{"Urban Service Room Lights", subt::ConnectionHelper::URBAN},
{"Urban Service Room Straight", subt::ConnectionHelper::URBAN},
{"Urban Service Room Straight Lights", subt::ConnectionHelper::URBAN},
{"Urban Platform", subt::ConnectionHelper::URBAN},
{"Urban Platform Open", subt::ConnectionHelper::URBAN},
{"Urban Stairwell Platform", subt::ConnectionHelper::URBAN},
{"Urban Stairwell Platform Lights", subt::ConnectionHelper::URBAN},
{"Urban Stairwell Platform Centered", subt::ConnectionHelper::URBAN},
{"Urban Stairwell Platform Centered Lights",
subt::ConnectionHelper::URBAN},
{"Urban Starting Area", subt::ConnectionHelper::URBAN},
{"Urban Elevation Up", subt::ConnectionHelper::URBAN},
{"Urban Elevation Up Lights", subt::ConnectionHelper::URBAN},
{"Urban Elevation Down", subt::ConnectionHelper::URBAN},
{"Urban 2 Story", subt::ConnectionHelper::URBAN},
{"Urban 2 Story Lights", subt::ConnectionHelper::URBAN},
{"Urban 2 Story Large Side 1 Lights", subt::ConnectionHelper::URBAN},
{"Urban 2 Story Large Side 2 Lights", subt::ConnectionHelper::URBAN},
{"Urban 2 Story Large Side 1", subt::ConnectionHelper::URBAN},
{"Urban 2 Story Large Side 2", subt::ConnectionHelper::URBAN},
{"Urban Large Room Split", subt::ConnectionHelper::URBAN},
{"Urban Large Room Split Lights", subt::ConnectionHelper::URBAN},
{"Cave Starting Area Type B", subt::ConnectionHelper::CAVE},
{"Cave Straight 01 Type B", subt::ConnectionHelper::CAVE},
{"Cave Straight 01 Lights Type B", subt::ConnectionHelper::CAVE},
{"Cave Straight 02 Type B", subt::ConnectionHelper::CAVE},
{"Cave Straight 02 Lights Type B", subt::ConnectionHelper::CAVE},
{"Cave Straight 03 Type B", subt::ConnectionHelper::CAVE},
{"Cave Straight 04 Type B", subt::ConnectionHelper::CAVE},
{"Cave Straight 04 Lights Type B", subt::ConnectionHelper::CAVE},
{"Cave Straight 05 Type B", subt::ConnectionHelper::CAVE},
{"Cave Straight 05 Lights Type B", subt::ConnectionHelper::CAVE},
{"Cave Corner 01 Type B", subt::ConnectionHelper::CAVE},
{"Cave Corner 01 Lights Type B", subt::ConnectionHelper::CAVE},
{"Cave Corner 02 Type B", subt::ConnectionHelper::CAVE},
{"Cave Corner 02 Lights Type B", subt::ConnectionHelper::CAVE},
{"Cave 3 Way 01 Type B", subt::ConnectionHelper::CAVE},
{"Cave 3 Way 01 Lights Type B", subt::ConnectionHelper::CAVE},
{"Cave Elevation Type B", subt::ConnectionHelper::CAVE},
{"Cave Elevation Lights Type B", subt::ConnectionHelper::CAVE},
{"Cave Vertical Shaft Type B", subt::ConnectionHelper::CAVE},
{"Cave Vertical Shaft Lights Type B", subt::ConnectionHelper::CAVE},
{"Cave Cavern Split 01 Type B", subt::ConnectionHelper::CAVE},
{"Cave Cavern Split 02 Type B", subt::ConnectionHelper::CAVE},
{"Cave Corner 30 Type B", subt::ConnectionHelper::CAVE},
{"Cave Corner 30F Type B", subt::ConnectionHelper::CAVE},
{"Cave Corner 30 D Type B", subt::ConnectionHelper::CAVE},
{"Cave Corner 30 D Lights Type B", subt::ConnectionHelper::CAVE},
{"Cave Corner 30F D Type B", subt::ConnectionHelper::CAVE},
{"Cave Corner 30F D Lights Type B", subt::ConnectionHelper::CAVE},

{"Cave 2 Way 01 Type A", subt::ConnectionHelper::CAVE},
{"Cave 3 Way 01 Type A", subt::ConnectionHelper::CAVE},
{"Cave 3 Way 02 Type A", subt::ConnectionHelper::CAVE},
{"Cave 3 Way Elevation 01 Type A", subt::ConnectionHelper::CAVE},
{"Cave 3 Way Elevation 02 Type A", subt::ConnectionHelper::CAVE},
{"Cave 3 Way Elevation 03 Type A", subt::ConnectionHelper::CAVE},
{"Cave 4 Way 01 Type A", subt::ConnectionHelper::CAVE},
{"Cave Cavern Type A", subt::ConnectionHelper::CAVE},
{"Cave Corner 01 Type A", subt::ConnectionHelper::CAVE},
{"Cave Corner 02 Type A", subt::ConnectionHelper::CAVE},
{"Cave Corner 03 Type A", subt::ConnectionHelper::CAVE},
{"Cave Corner 03 Type A Lights", subt::ConnectionHelper::CAVE},
{"Cave Corner 04 Type A", subt::ConnectionHelper::CAVE},
{"Cave Cap Type A", subt::ConnectionHelper::CAVE},
{"Cave Elevation 01 Type A", subt::ConnectionHelper::CAVE},
{"Cave Elevation 02 Type A", subt::ConnectionHelper::CAVE},
{"Cave Elevation Corner Type A", subt::ConnectionHelper::CAVE},
{"Cave Elevation Straight Type A", subt::ConnectionHelper::CAVE},
{"Cave Split Type A", subt::ConnectionHelper::CAVE},
{"Cave Straight Shift Type A", subt::ConnectionHelper::CAVE},
{"Cave Straight Type A", subt::ConnectionHelper::CAVE},
{"Cave U Turn 01 Type A", subt::ConnectionHelper::CAVE},
{"Cave U Turn Elevation Type A", subt::ConnectionHelper::CAVE},
{"Cave Vertical Shaft Cantilevered Type A", subt::ConnectionHelper::CAVE},
{"Cave Vertical Shaft Straight Bottom Type A", subt::ConnectionHelper::CAVE},
{"Cave Vertical Shaft Straight Top Type A", subt::ConnectionHelper::CAVE},
{"Cave Vertical Shaft Type A", subt::ConnectionHelper::CAVE},
{"Cave Vertical Shaft Dead End Type A", subt::ConnectionHelper::CAVE},
{"Cave 3 Way Elevation 02 Lights Type A", subt::ConnectionHelper::CAVE},
{"Cave 4 Way 01 Lights Type A", subt::ConnectionHelper::CAVE},
{"Cave Corner 01 Lights Type A", subt::ConnectionHelper::CAVE},
{"Cave Corner 02 Lights Type A", subt::ConnectionHelper::CAVE},
{"Cave Corner 04 Lights Type A", subt::ConnectionHelper::CAVE},
{"Cave Elevation Straight Lights Type A", subt::ConnectionHelper::CAVE},
{"Cave Straight Lights Type A", subt::ConnectionHelper::CAVE},
{"Cave U Turn Elevation Lights Type A", subt::ConnectionHelper::CAVE},
{"Cave Vertical Shaft Straight Bottom Lights Type A", subt::ConnectionHelper::CAVE},
{"Cave Transition Type A to and from Type B", subt::ConnectionHelper::CAVE},
{"Cave Transition Type A to and from Type B Lights", subt::ConnectionHelper::CAVE},

{"Jenolan Section 01", subt::ConnectionHelper::CAVE},
{"Jenolan Section 02", subt::ConnectionHelper::CAVE},
{"Jenolan Section 03", subt::ConnectionHelper::CAVE},
{"Jenolan Section 04", subt::ConnectionHelper::CAVE},
{"Jenolan Section 05", subt::ConnectionHelper::CAVE},
{"Jenolan Section 06", subt::ConnectionHelper::CAVE},
{"Jenolan Section 07", subt::ConnectionHelper::CAVE},
{"Jenolan Section 08", subt::ConnectionHelper::CAVE},
{"Jenolan Section 09", subt::ConnectionHelper::CAVE},
{"Jenolan Section 10", subt::ConnectionHelper::CAVE},
{"Jenolan Section 11", subt::ConnectionHelper::CAVE},
{"Universal Straight 10", subt::ConnectionHelper::UNIVERSAL},
{"Universal Straight 5", subt::ConnectionHelper::UNIVERSAL},
{"Universal Straight 2.5", subt::ConnectionHelper::UNIVERSAL},
{"Universal Shift 5x5", subt::ConnectionHelper::UNIVERSAL},
{"Universal Shift 2.5x2.5", subt::ConnectionHelper::UNIVERSAL},
{"Cave Tunnel Transition", subt::ConnectionHelper::TRANSITION},
{"Cave Tunnel Transition Lights", subt::ConnectionHelper::TRANSITION},
{"Urban Cave Transition", subt::ConnectionHelper::TRANSITION},
{"Urban Cave Transition Straight", subt::ConnectionHelper::TRANSITION},
{"Urban Tunnel Transition", subt::ConnectionHelper::TRANSITION},
{"Finals Staging Area", subt::ConnectionHelper::STAGING_AREA},
{"4-Way Finals Transition", subt::ConnectionHelper::TRANSITION},
{"4-Way Finals Transition 2", subt::ConnectionHelper::TRANSITION},
{"4-Way Finals Transition 2 Lights", subt::ConnectionHelper::TRANSITION},
};

using namespace ignition;
using namespace subt;

Expand Down
21 changes: 21 additions & 0 deletions subt_ign/src/ConnectionHelper.hh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ namespace subt
TURN = 1,
};

/// \brief Enum of circuit type
public: enum CircuitType
{
/// \brief Tunnel tiles
TUNNEL = 0,
/// \brief Urban tiles
URBAN = 1,
/// \brief Cave tiles
CAVE = 2,
/// \brief Universal tiles
UNIVERSAL = 3,
/// \brief Transition tiles
TRANSITION = 4,
/// \brief Staging are
STAGING_AREA = 5,
};

/// \brief Compute the connection point between two tiles.
/// This uses a reference list of connection points for each tile type.
/// The function iterates over the connection points transformed into the
Expand All @@ -75,6 +92,10 @@ namespace subt
/// \brief Map of tile type to connection type
public: static std::map<std::string, subt::ConnectionHelper::ConnectionType>
connectionTypes;

/// \brief Map of tile type to circuit type
public: static std::map<std::string, subt::ConnectionHelper::CircuitType>
circuitTypes;
};
}
#endif
102 changes: 92 additions & 10 deletions subt_ign/src/apps/dot_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,19 @@
using namespace subt;
using namespace ignition;

/// \brief Print usage
void usage()
{
std::cerr << "Usage: dot_generator [--finals] <path_to_world_sdf_file>"
<< std::endl;
}

/// \brief Print the DOT file
/// \param[in] _vertexData vector of vertex data containing
/// vertex and edge info
void printGraph(std::vector<VertexData> &_vertexData)
/// \param[in] _circuit Empty string or "--finals" .
void printGraph(std::vector<VertexData> &_vertexData,
const std::string &_circuit)
{
std::stringstream out;
out << "/* Visibility graph generated by dot_generator */\n\n";
Expand Down Expand Up @@ -80,6 +89,22 @@ void printGraph(std::vector<VertexData> &_vertexData)
auto tp2 =
subt::ConnectionHelper::connectionTypes[_vertexData[j].tileType];

// Get the circuit type for each tile (cave, urban, etc.)
auto ct1It = subt::ConnectionHelper::circuitTypes.find(
_vertexData[i].tileType);
if (ct1It == subt::ConnectionHelper::circuitTypes.end())
{
ignwarn << "No circuit information for: " << _vertexData[i].tileType
<< std::endl;
}
auto ct2It = subt::ConnectionHelper::circuitTypes.find(
_vertexData[j].tileType);
if (ct2It == subt::ConnectionHelper::circuitTypes.end())
{
ignwarn << "No circuit information for: " << _vertexData[j].tileType
<< std::endl;
}

// Is one of the tile a starting area? If so, the cost should be 1.
bool connectsToStaging =
_vertexData[i].tileType == "Cave Starting Area Type B" ||
Expand All @@ -93,12 +118,42 @@ void printGraph(std::vector<VertexData> &_vertexData)
cost = 1;
else if (tp1 == subt::ConnectionHelper::TURN &&
tp2 == subt::ConnectionHelper::STRAIGHT)
cost = 3;
{
// Both tiles are tunnels
if (_circuit == "--finals" &&
ct1It != subt::ConnectionHelper::circuitTypes.end() &&
ct1It->second == subt::ConnectionHelper::TUNNEL &&
ct2It != subt::ConnectionHelper::circuitTypes.end() &&
ct2It->second == subt::ConnectionHelper::TUNNEL)
cost = 2;
else
cost = 3;
}
else if (tp1 == subt::ConnectionHelper::STRAIGHT &&
tp2 == subt::ConnectionHelper::TURN)
cost = 3;
{
// Both tiles are tunnels
if (_circuit == "--finals" &&
ct1It != subt::ConnectionHelper::circuitTypes.end() &&
ct1It->second == subt::ConnectionHelper::TUNNEL &&
ct2It != subt::ConnectionHelper::circuitTypes.end() &&
ct2It->second == subt::ConnectionHelper::TUNNEL)
cost = 2;
else
cost = 3;
}
else
cost = 6;
{
// Both tiles are tunnels
if (_circuit == "--finals" &&
ct1It != subt::ConnectionHelper::circuitTypes.end() &&
ct1It->second == subt::ConnectionHelper::TUNNEL &&
ct2It != subt::ConnectionHelper::circuitTypes.end() &&
ct2It->second == subt::ConnectionHelper::TUNNEL)
cost = 3;
else
cost = 6;
}

if (connectsToStaging)
out << " /* Base station */\n";
Expand All @@ -120,7 +175,7 @@ void printGraph(std::vector<VertexData> &_vertexData)

/// \brief Main function to generate DOT from input sdf file
/// \param[in] _sdfFile Input sdf file.
void generateDOT(const std::string &_sdfFile)
void generateDOT(const std::string &_sdfFile, const std::string &_circuit)
{
std::ifstream file(_sdfFile);
if (!file.is_open())
Expand Down Expand Up @@ -155,22 +210,49 @@ void generateDOT(const std::string &_sdfFile)
str = str.substr(result);
}

printGraph(vertexData);
printGraph(vertexData, _circuit);

file.close();
}

//////////////////////////////////////////////////
int main(int argc, char **argv)
{
if (argc != 2)
if (argc != 2 && argc != 3)
{
std::cerr << "Usage: dot_generator <path_to_world_sdf_file>"
<< std::endl;
usage();
return -1;
}

std::string circuit = "";
std::string sdfFile = argv[1];
generateDOT(sdfFile);

if (argc == 2)
{
// Sanity check: --finals can't be used without the sdfFile argument.
if (argv[1] == std::string("--finals"))
{
usage();
return -1;
}
}

if (argc == 3)
{
// Sanity check: One of the two arguments needs to be --finals.
if (argv[1] != std::string("--finals") &&
argv[2] != std::string("--finals"))
{
usage();
return -1;
}

circuit = "--finals";
if (argv[1] == std::string("--finals"))
sdfFile = argv[2];
}

generateDOT(sdfFile, circuit);

return 0;
}
Loading

0 comments on commit 8dd0aa3

Please sign in to comment.