Skip to content

Commit 58b71c9

Browse files
committed
added other SDFExtensions
1 parent 2d221fe commit 58b71c9

File tree

2 files changed

+96
-8
lines changed

2 files changed

+96
-8
lines changed

src/parser_urdf.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,7 @@ void CopyBlob(tinyxml2::XMLElement *_src, tinyxml2::XMLElement *_blob_parent)
16041604
void InsertSDFExtensionCollision(tinyxml2::XMLElement *_elem,
16051605
const std::string &_linkName)
16061606
{
1607+
bool link_found = false;
16071608
// loop through extensions for the whole model
16081609
// and see which ones belong to _linkName
16091610
// This might be complicated since there's:
@@ -1615,6 +1616,7 @@ void InsertSDFExtensionCollision(tinyxml2::XMLElement *_elem,
16151616
{
16161617
if (sdfIt->first == _linkName)
16171618
{
1619+
link_found = true;
16181620
// std::cerr << "============================\n";
16191621
// std::cerr << "working on g_extensions for link ["
16201622
// << sdfIt->first << "]\n";
@@ -1908,12 +1910,19 @@ void InsertSDFExtensionCollision(tinyxml2::XMLElement *_elem,
19081910
}
19091911
}
19101912
}
1913+
// If we didn't find the link, emit a warning
1914+
if (!link_found) {
1915+
sdfwarn << "<collision> tag with reference[" << _linkName << "] does not exist"
1916+
<< " in the URDF model. Please ensure that the reference attribute"
1917+
<< " matches the name of a link.";
1918+
}
19111919
}
19121920

19131921
////////////////////////////////////////////////////////////////////////////////
19141922
void InsertSDFExtensionVisual(tinyxml2::XMLElement *_elem,
19151923
const std::string &_linkName)
19161924
{
1925+
bool link_found = false;
19171926
// loop through extensions for the whole model
19181927
// and see which ones belong to _linkName
19191928
// This might be complicated since there's:
@@ -1925,6 +1934,7 @@ void InsertSDFExtensionVisual(tinyxml2::XMLElement *_elem,
19251934
{
19261935
if (sdfIt->first == _linkName)
19271936
{
1937+
link_found=true;
19281938
// std::cerr << "============================\n";
19291939
// std::cerr << "working on g_extensions for link ["
19301940
// << sdfIt->first << "]\n";
@@ -2102,6 +2112,12 @@ void InsertSDFExtensionVisual(tinyxml2::XMLElement *_elem,
21022112
}
21032113
}
21042114
}
2115+
// If we didn't find the link, emit a warning
2116+
if (!link_found) {
2117+
sdfwarn << "<visual> tag with reference[" << _linkName << "] does not exist"
2118+
<< " in the URDF model. Please ensure that the reference attribute"
2119+
<< " matches the name of a link.";
2120+
}
21052121
}
21062122

21072123
////////////////////////////////////////////////////////////////////////////////
@@ -2168,13 +2184,15 @@ void InsertSDFExtensionLink(tinyxml2::XMLElement *_elem,
21682184
void InsertSDFExtensionJoint(tinyxml2::XMLElement *_elem,
21692185
const std::string &_jointName)
21702186
{
2187+
bool joint_found = false;
21712188
auto* doc = _elem->GetDocument();
21722189
for (StringSDFExtensionPtrMap::iterator
21732190
sdfIt = g_extensions.begin();
21742191
sdfIt != g_extensions.end(); ++sdfIt)
21752192
{
21762193
if (sdfIt->first == _jointName)
21772194
{
2195+
joint_found = true;
21782196
for (std::vector<SDFExtensionPtr>::iterator
21792197
ge = sdfIt->second.begin();
21802198
ge != sdfIt->second.end(); ++ge)
@@ -2309,6 +2327,13 @@ void InsertSDFExtensionJoint(tinyxml2::XMLElement *_elem,
23092327
}
23102328
}
23112329
}
2330+
2331+
// If we didn't find the link, emit a warning
2332+
if (!joint_found) {
2333+
sdfwarn << "<joint> tag with name[" << _jointName << "] does not exist"
2334+
<< " in the URDF model. Please ensure that the name attribute"
2335+
<< " matches the name of a joint.";
2336+
}
23122337
}
23132338

23142339
////////////////////////////////////////////////////////////////////////////////

src/parser_urdf_TEST.cc

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,8 +2476,8 @@ TEST(URDFParser, ParseGazeboRefDoesntExistWarningMessage)
24762476
});
24772477
#endif
24782478

2479-
// test if reference to link exists
2480-
{
2479+
// test if reference to link exists
2480+
{
24812481
// clear the contents of the buffer
24822482
buffer.str("");
24832483

@@ -2509,12 +2509,75 @@ TEST(URDFParser, ParseGazeboRefDoesntExistWarningMessage)
25092509
" in the URDF model. Please ensure that the reference attribute"
25102510
" matches the name of a link.");
25112511
}
2512-
2513-
/* TODO(aagrawal05): Similar tests for -
2514-
InsertSDFExtensionCollision,
2515-
InsertSDFExtensionRobot,
2516-
InsertSDFExtensionVisual,
2517-
InsertSDFExtensionJoint */
2512+
2513+
{
2514+
// clear the contents of the buffer
2515+
buffer.str("");
2516+
2517+
std::string str = R"(
2518+
<robot name="test_robot">
2519+
<link name="link1">
2520+
<inertial>
2521+
<mass value="1" />
2522+
<inertia ixx="0.01" ixy="0.0" ixz="0.0" iyy="0.01" iyz="0.0" izz="0.01" />
2523+
</inertial>
2524+
</link>
2525+
<visual reference="lіnk1">
2526+
<geometry>
2527+
<box>
2528+
<size>1 1 1</size>
2529+
</box>
2530+
</geometry>
2531+
<material>
2532+
<color rgba="0.8 0.1 0.1 1.0"/>
2533+
</material>
2534+
<origin xyz="0 0 0.5" rpy="0 0 0"/>
2535+
</visual>
2536+
</robot>)";
2537+
2538+
sdf::URDF2SDF parser;
2539+
tinyxml2::XMLDocument sdfResult;
2540+
sdf::ParserConfig config;
2541+
parser.InitModelString(str, config, &sdfResult);
2542+
2543+
EXPECT_PRED2(sdf::testing::contains, buffer.str(),
2544+
"<visual> tag with reference[link1] does not exist"
2545+
" in the URDF model. Please ensure that the reference attribute"
2546+
" matches the name of a link.");
2547+
}
2548+
2549+
{
2550+
// clear the contents of the buffer
2551+
buffer.str("");
2552+
2553+
std::string str = R"(
2554+
<robot name="test_robot">
2555+
<link name="link1">
2556+
<inertial>
2557+
<mass value="1" />
2558+
<inertia ixx="0.01" ixy="0.0" ixz="0.0" iyy="0.01" iyz="0.0" izz="0.01" />
2559+
</inertial>
2560+
</link>
2561+
<collision reference="lіnk1">
2562+
<geometry>
2563+
<sphere>
2564+
<radius>0.5</radius>
2565+
</sphere>
2566+
</geometry>
2567+
<origin xyz="0 0 0.5" rpy="0 0 0"/>
2568+
</collision>
2569+
</robot>)";
2570+
2571+
sdf::URDF2SDF parser;
2572+
tinyxml2::XMLDocument sdfResult;
2573+
sdf::ParserConfig config;
2574+
parser.InitModelString(str, config, &sdfResult);
2575+
2576+
EXPECT_PRED2(sdf::testing::contains, buffer.str(),
2577+
"<collision> tag with reference[link1] does not exist"
2578+
" in the URDF model. Please ensure that the reference attribute"
2579+
" matches the name of a link.");
2580+
}
25182581
}
25192582

25202583
/////////////////////////////////////////////////

0 commit comments

Comments
 (0)