Skip to content

Commit 2aa7210

Browse files
authored
Merge branch 'sdf12' into pr_optical_frame
2 parents 0ead856 + 38f8bb0 commit 2aa7210

File tree

4 files changed

+210
-277
lines changed

4 files changed

+210
-277
lines changed

Migration.md

+9
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,15 @@ ABI was broken for `sdf::Element`, and restored on version 11.2.1.
283283
+ std::optional<std::string> GetMaxValueAsString() const;
284284
+ bool ValidateValue() const;
285285

286+
## libsdformat 9.8.0 to 9.8.1
287+
288+
### Modifications
289+
290+
1. URDF parser now properly transforms poses for lights, projectors and sensors
291+
from gazebo extension tags that are moved to a new link during fixed joint
292+
reduction.
293+
+ [pull request 1114](https://github.com/osrf/sdformat/pull/1114)
294+
286295
## libsdformat 9.4 to 9.5
287296

288297
### Additions

src/parser_urdf.cc

+41-159
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,12 @@ void InsertSDFExtensionJoint(tinyxml2::XMLElement *_elem,
9191
/// option is set
9292
bool FixedJointShouldBeReduced(urdf::JointSharedPtr _jnt);
9393

94-
/// reduced fixed joints: apply transform reduction for ray sensors
94+
/// reduced fixed joints: apply transform reduction for named elements
9595
/// in extensions when doing fixed joint reduction
96-
void ReduceSDFExtensionSensorTransformReduction(
96+
void ReduceSDFExtensionElementTransformReduction(
9797
std::vector<XMLDocumentPtr>::iterator _blobIt,
98-
ignition::math::Pose3d _reductionTransform);
99-
100-
/// reduced fixed joints: apply transform reduction for projectors in
101-
/// extensions when doing fixed joint reduction
102-
void ReduceSDFExtensionProjectorTransformReduction(
103-
std::vector<XMLDocumentPtr>::iterator _blobIt,
104-
ignition::math::Pose3d _reductionTransform);
98+
const ignition::math::Pose3d &_reductionTransform,
99+
const std::string &_elementName);
105100

106101

107102
/// reduced fixed joints: apply transform reduction to extensions
@@ -409,8 +404,8 @@ void ReduceVisualToParent(urdf::LinkSharedPtr _parentLink,
409404
// collision elements of the child link into the parent link
410405
void ReduceFixedJoints(tinyxml2::XMLElement *_root, urdf::LinkSharedPtr _link)
411406
{
412-
// if child is attached to self by fixed _link first go up the tree,
413-
// check it's children recursively
407+
// if child is attached to self by fixed joint first go up the tree,
408+
// check its children recursively
414409
for (unsigned int i = 0 ; i < _link->child_links.size() ; ++i)
415410
{
416411
if (FixedJointShouldBeReduced(_link->child_links[i]->parent_joint))
@@ -2479,8 +2474,7 @@ void ReduceSDFExtensionToParent(urdf::LinkSharedPtr _link)
24792474
for (std::vector<SDFExtensionPtr>::iterator ge = ext->second.begin();
24802475
ge != ext->second.end(); ++ge)
24812476
{
2482-
(*ge)->reductionTransform = TransformToParentFrame(
2483-
(*ge)->reductionTransform,
2477+
(*ge)->reductionTransform = CopyPose(
24842478
_link->parent_joint->parent_to_joint_origin_transform);
24852479
// for sensor and projector blocks only
24862480
ReduceSDFExtensionsTransform((*ge));
@@ -2568,11 +2562,12 @@ void ReduceSDFExtensionsTransform(SDFExtensionPtr _ge)
25682562
for (auto blobIt = _ge->blobs.begin();
25692563
blobIt != _ge->blobs.end(); ++blobIt)
25702564
{
2571-
/// @todo make sure we are not missing any additional transform reductions
2572-
ReduceSDFExtensionSensorTransformReduction(blobIt,
2573-
_ge->reductionTransform);
2574-
ReduceSDFExtensionProjectorTransformReduction(blobIt,
2575-
_ge->reductionTransform);
2565+
ReduceSDFExtensionElementTransformReduction(
2566+
blobIt, _ge->reductionTransform, "light");
2567+
ReduceSDFExtensionElementTransformReduction(
2568+
blobIt, _ge->reductionTransform, "projector");
2569+
ReduceSDFExtensionElementTransformReduction(
2570+
blobIt, _ge->reductionTransform, "sensor");
25762571
}
25772572
}
25782573

@@ -3364,12 +3359,13 @@ bool FixedJointShouldBeReduced(urdf::JointSharedPtr _jnt)
33643359
}
33653360

33663361
////////////////////////////////////////////////////////////////////////////////
3367-
void ReduceSDFExtensionSensorTransformReduction(
3362+
void ReduceSDFExtensionElementTransformReduction(
33683363
std::vector<XMLDocumentPtr>::iterator _blobIt,
3369-
ignition::math::Pose3d _reductionTransform)
3364+
const ignition::math::Pose3d &_reductionTransform,
3365+
const std::string &_elementName)
33703366
{
3371-
auto sensorElement = (*_blobIt)->FirstChildElement();
3372-
if ( strcmp(sensorElement->Name(), "sensor") == 0)
3367+
auto element = (*_blobIt)->FirstChildElement();
3368+
if ( strcmp(element->Name(), _elementName.c_str()) == 0)
33733369
{
33743370
// parse it and add/replace the reduction transform
33753371
// find first instance of xyz and rpy, replace with reduction transform
@@ -3383,166 +3379,51 @@ void ReduceSDFExtensionSensorTransformReduction(
33833379
// sdfdbg << " " << streamIn.CStr() << "\n";
33843380
// }
33853381

3386-
auto sensorPose {ignition::math::Pose3d::Zero};
3382+
auto pose {ignition::math::Pose3d::Zero};
33873383
{
3388-
auto sensorPosText = "0 0 0 0 0 0";
3389-
const auto& oldPoseKey = sensorElement->FirstChildElement("pose");
3384+
std::string poseText = "0 0 0 0 0 0";
3385+
3386+
const auto& oldPoseKey = element->FirstChildElement("pose");
33903387
if (oldPoseKey)
33913388
{
33923389
const auto& poseElemXml = oldPoseKey->ToElement();
33933390
if (poseElemXml->Attribute("relative_to"))
3394-
return;
3395-
3396-
// see below for explanation; if a sibling element exists, it stores the
3397-
// original <sensor><pose> tag content
3398-
const auto& sibling = sensorElement->NextSibling();
3399-
if (poseElemXml->GetText() && !sibling)
3400-
sensorPosText = poseElemXml->GetText();
3401-
else if (sibling && sibling->ToElement()->GetText())
3402-
sensorPosText = sibling->ToElement()->GetText();
3403-
else
34043391
{
3405-
sdferr << "Unexpected case in sensor pose computation\n";
34063392
return;
34073393
}
34083394

3409-
// delete the <pose> tag, we'll add a new one at the end
3410-
sensorElement->DeleteChild(oldPoseKey);
3411-
}
3412-
3413-
// parse the 6-tuple text into math::Pose3d
3414-
std::stringstream ss;
3415-
ss.imbue(std::locale::classic());
3416-
ss << sensorPosText;
3417-
ss >> sensorPose;
3418-
if (ss.fail())
3419-
{
3420-
sdferr << "Could not parse <sensor><pose>: [" << sensorPosText << "]\n";
3421-
return;
3422-
}
3423-
3424-
// critical part: we store the original <pose> tag from <sensor> actually
3425-
// as a sibling of <sensor>... only first element of the blob is processed
3426-
// further, so its siblings can be used as temporary storage; we store the
3427-
// original <pose> tag there so that we can use the <sensor><pose> tag
3428-
// for storing the reduced position
3429-
auto doc = (*_blobIt)->GetDocument();
3430-
const auto& poseTxt = doc->NewText(sensorPosText);
3431-
auto poseKey = doc->NewElement("pose");
3432-
poseKey->LinkEndChild(poseTxt);
3433-
(*_blobIt)->LinkEndChild(poseKey);
3434-
}
3435-
3436-
_reductionTransform = _reductionTransform * sensorPose;
3437-
3438-
// convert reductionTransform to values
3439-
urdf::Vector3 reductionXyz(_reductionTransform.Pos().X(),
3440-
_reductionTransform.Pos().Y(),
3441-
_reductionTransform.Pos().Z());
3442-
urdf::Rotation reductionQ(_reductionTransform.Rot().X(),
3443-
_reductionTransform.Rot().Y(),
3444-
_reductionTransform.Rot().Z(),
3445-
_reductionTransform.Rot().W());
3446-
3447-
urdf::Vector3 reductionRpy;
3448-
reductionQ.getRPY(reductionRpy.x, reductionRpy.y, reductionRpy.z);
3449-
3450-
// output updated pose to text
3451-
std::ostringstream poseStream;
3452-
poseStream << reductionXyz.x << " " << reductionXyz.y
3453-
<< " " << reductionXyz.z << " " << reductionRpy.x
3454-
<< " " << reductionRpy.y << " " << reductionRpy.z;
3455-
3456-
auto* doc = (*_blobIt)->GetDocument();
3457-
tinyxml2::XMLText *poseTxt = doc->NewText(poseStream.str().c_str());
3458-
tinyxml2::XMLElement *poseKey = doc->NewElement("pose");
3459-
3460-
poseKey->LinkEndChild(poseTxt);
3461-
3462-
sensorElement->LinkEndChild(poseKey);
3463-
}
3464-
}
3465-
3466-
////////////////////////////////////////////////////////////////////////////////
3467-
void ReduceSDFExtensionProjectorTransformReduction(
3468-
std::vector<XMLDocumentPtr>::iterator _blobIt,
3469-
ignition::math::Pose3d _reductionTransform)
3470-
{
3471-
auto projectorElement = (*_blobIt)->FirstChildElement();
3472-
if ( strcmp(projectorElement->Name(), "projector") == 0)
3473-
{
3474-
// parse it and add/replace the reduction transform
3475-
// find first instance of xyz and rpy, replace with reduction transform
3476-
//
3477-
// for (tinyxml2::XMLNode* elIt = (*_blobIt)->FirstChildElement();
3478-
// elIt; elIt = elIt->NextSibling())
3479-
// {
3480-
// std::ostringstream streamIn;
3481-
// streamIn << *elIt;
3482-
// sdfdbg << " " << streamIn << "\n";
3483-
// }
3484-
3485-
auto projectorPose {ignition::math::Pose3d::Zero};
3486-
{
3487-
auto projectorPosText = "0 0 0 0 0 0";
3488-
const auto& oldPoseKey = projectorElement->FirstChildElement("pose");
3489-
if (oldPoseKey)
3490-
{
3491-
const auto& poseElemXml = oldPoseKey->ToElement();
3492-
if (poseElemXml->Attribute("relative_to"))
3493-
return;
3494-
3495-
// see below for explanation; if a sibling element exists, it stores the
3496-
// original <projector><pose> tag content
3497-
const auto& sibling = projectorElement->NextSibling();
3498-
if (poseElemXml->GetText() && !sibling)
3499-
projectorPosText = poseElemXml->GetText();
3500-
else if (sibling && sibling->ToElement()->GetText())
3501-
projectorPosText = sibling->ToElement()->GetText();
3502-
else
3395+
if (poseElemXml->GetText())
35033396
{
3504-
sdferr << "Unexpected case in projector pose computation\n";
3505-
return;
3397+
poseText = poseElemXml->GetText();
35063398
}
35073399

35083400
// delete the <pose> tag, we'll add a new one at the end
3509-
projectorElement->DeleteChild(oldPoseKey);
3401+
element->DeleteChild(oldPoseKey);
35103402
}
35113403

35123404
// parse the 6-tuple text into math::Pose3d
3513-
std::stringstream ss;
3405+
std::stringstream ss;
35143406
ss.imbue(std::locale::classic());
3515-
ss << projectorPosText;
3516-
ss >> projectorPose;
3407+
ss << poseText;
3408+
ss >> pose;
35173409
if (ss.fail())
35183410
{
3519-
sdferr << "Could not parse <projector><pose>: ["
3520-
<< projectorPosText << "]\n";
3411+
sdferr << "Could not parse <" << _elementName << "><pose>: ["
3412+
<< poseText << "]\n";
35213413
return;
35223414
}
3523-
3524-
// critical part: we store the original <pose> tag from <projector>
3525-
// actually as a sibling of <projector>... only first element of the blob
3526-
// is processed further, so its siblings can be used as temporary storage;
3527-
// we store the original <pose> tag there so that we can use the
3528-
// <projector><pose> tag for storing the reduced position
3529-
auto doc = (*_blobIt)->GetDocument();
3530-
const auto& poseTxt = doc->NewText(projectorPosText);
3531-
auto poseKey = doc->NewElement("pose");
3532-
poseKey->LinkEndChild(poseTxt);
3533-
(*_blobIt)->LinkEndChild(poseKey);
35343415
}
35353416

3536-
_reductionTransform = _reductionTransform * projectorPose;
3417+
pose = _reductionTransform * pose;
35373418

35383419
// convert reductionTransform to values
3539-
urdf::Vector3 reductionXyz(_reductionTransform.Pos().X(),
3540-
_reductionTransform.Pos().Y(),
3541-
_reductionTransform.Pos().Z());
3542-
urdf::Rotation reductionQ(_reductionTransform.Rot().X(),
3543-
_reductionTransform.Rot().Y(),
3544-
_reductionTransform.Rot().Z(),
3545-
_reductionTransform.Rot().W());
3420+
urdf::Vector3 reductionXyz(pose.Pos().X(),
3421+
pose.Pos().Y(),
3422+
pose.Pos().Z());
3423+
urdf::Rotation reductionQ(pose.Rot().X(),
3424+
pose.Rot().Y(),
3425+
pose.Rot().Z(),
3426+
pose.Rot().W());
35463427

35473428
urdf::Vector3 reductionRpy;
35483429
reductionQ.getRPY(reductionRpy.x, reductionRpy.y, reductionRpy.z);
@@ -3555,10 +3436,11 @@ void ReduceSDFExtensionProjectorTransformReduction(
35553436

35563437
auto* doc = (*_blobIt)->GetDocument();
35573438
tinyxml2::XMLText *poseTxt = doc->NewText(poseStream.str().c_str());
3558-
auto poseKey = doc->NewElement("pose");
3439+
tinyxml2::XMLElement *poseKey = doc->NewElement("pose");
3440+
35593441
poseKey->LinkEndChild(poseTxt);
35603442

3561-
projectorElement->LinkEndChild(poseKey);
3443+
element->LinkEndChild(poseKey);
35623444
}
35633445
}
35643446

0 commit comments

Comments
 (0)