Skip to content

Commit ceed898

Browse files
committed
initial draft of warning message functionality
1 parent 6d3672c commit ceed898

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

src/parser_urdf.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,12 +2108,14 @@ void InsertSDFExtensionVisual(tinyxml2::XMLElement *_elem,
21082108
void InsertSDFExtensionLink(tinyxml2::XMLElement *_elem,
21092109
const std::string &_linkName)
21102110
{
2111+
bool link_found = false;
21112112
for (StringSDFExtensionPtrMap::iterator
21122113
sdfIt = g_extensions.begin();
21132114
sdfIt != g_extensions.end(); ++sdfIt)
21142115
{
21152116
if (sdfIt->first == _linkName)
21162117
{
2118+
link_found = true;
21172119
sdfdbg << "inserting extension with reference ["
21182120
<< _linkName << "] into link.\n";
21192121
for (std::vector<SDFExtensionPtr>::iterator ge =
@@ -2153,6 +2155,13 @@ void InsertSDFExtensionLink(tinyxml2::XMLElement *_elem,
21532155
}
21542156
}
21552157
}
2158+
2159+
// If we didn't find the link, emit a warning
2160+
if (!link_found) {
2161+
sdfwarn << "<gazebo> tag with reference[" << _linkName << "] does not exist in the URDF model. Please "
2162+
<< "ensure that the referenced attribute matches the name of a link, consider checking unicode "
2163+
<< "representation for reference attribute in case of invisible characters and homoglyphs";
2164+
}
21562165
}
21572166

21582167
////////////////////////////////////////////////////////////////////////////////

src/parser_urdf_TEST.cc

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,6 +2460,64 @@ TEST(URDFParser, ZeroMassLeafLink)
24602460
}
24612461
}
24622462

2463+
/////////////////////////////////////////////////
2464+
TEST(URDFParser, ParseGazeboRefDoesntExistWarningMessage)
2465+
{
2466+
// Redirect sdfwarn output
2467+
std::stringstream buffer;
2468+
sdf::testing::RedirectConsoleStream redir(
2469+
sdf::Console::Instance()->GetMsgStream(), &buffer);
2470+
#ifdef _WIN32
2471+
sdf::Console::Instance()->SetQuiet(false);
2472+
sdf::testing::ScopeExit revertSetQuiet(
2473+
[]
2474+
{
2475+
sdf::Console::Instance()->SetQuiet(true);
2476+
});
2477+
#endif
2478+
2479+
// test if reference to link exists
2480+
{
2481+
// clear the contents of the buffer
2482+
buffer.str("");
2483+
2484+
std::string str = R"(
2485+
<robot name="test_robot">
2486+
<link name="link1">
2487+
<inertial>
2488+
<mass value="1" />
2489+
<inertia ixx="0.01" ixy="0.0" ixz="0.0" iyy="0.01" iyz="0.0" izz="0.01" />
2490+
</inertial>
2491+
</link>
2492+
<gazebo reference="lіnk1">
2493+
<sensor name="link1_imu" type="imu">
2494+
<always_on>1</always_on>
2495+
<update_rate>100</update_rate>
2496+
<pose>0.13525 0 -0.07019999999999993 0.0 -0.0 -2.0943952105869315</pose>
2497+
<plugin name="sensor_plugin" filename="example_plugin.so" />
2498+
</sensor>
2499+
</gazebo>
2500+
</robot>
2501+
)";
2502+
2503+
sdf::URDF2SDF parser;
2504+
tinyxml2::XMLDocument sdfResult;
2505+
sdf::ParserConfig config;
2506+
parser.InitModelString(str, config, &sdfResult);
2507+
2508+
EXPECT_PRED2(sdf::testing::contains, buffer.str(),
2509+
"<gazebo> tag with reference[link1] does not exist in the URDF model. Please "
2510+
"ensure that the referenced attribute matches the name of a link, consider checking unicode "
2511+
"representation for reference attribute in case of invisible characters and homoglyphs");
2512+
}
2513+
2514+
// TODO: Similar tests for -
2515+
// InsertSDFExtensionCollision,
2516+
// InsertSDFExtensionRobot,
2517+
// InsertSDFExtensionVisual,
2518+
// InsertSDFExtensionJoint
2519+
}
2520+
24632521
/////////////////////////////////////////////////
24642522
/// Main
24652523
int main(int argc, char **argv)

0 commit comments

Comments
 (0)