@@ -91,17 +91,12 @@ void InsertSDFExtensionJoint(tinyxml2::XMLElement *_elem,
91
91
// / option is set
92
92
bool FixedJointShouldBeReduced (urdf::JointSharedPtr _jnt);
93
93
94
- // / reduced fixed joints: apply transform reduction for ray sensors
94
+ // / reduced fixed joints: apply transform reduction for named elements
95
95
// / in extensions when doing fixed joint reduction
96
- void ReduceSDFExtensionSensorTransformReduction (
96
+ void ReduceSDFExtensionElementTransformReduction (
97
97
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);
105
100
106
101
107
102
// / reduced fixed joints: apply transform reduction to extensions
@@ -409,8 +404,8 @@ void ReduceVisualToParent(urdf::LinkSharedPtr _parentLink,
409
404
// collision elements of the child link into the parent link
410
405
void ReduceFixedJoints (tinyxml2::XMLElement *_root, urdf::LinkSharedPtr _link)
411
406
{
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
414
409
for (unsigned int i = 0 ; i < _link->child_links .size () ; ++i)
415
410
{
416
411
if (FixedJointShouldBeReduced (_link->child_links [i]->parent_joint ))
@@ -2479,8 +2474,7 @@ void ReduceSDFExtensionToParent(urdf::LinkSharedPtr _link)
2479
2474
for (std::vector<SDFExtensionPtr>::iterator ge = ext->second .begin ();
2480
2475
ge != ext->second .end (); ++ge)
2481
2476
{
2482
- (*ge)->reductionTransform = TransformToParentFrame (
2483
- (*ge)->reductionTransform ,
2477
+ (*ge)->reductionTransform = CopyPose (
2484
2478
_link->parent_joint ->parent_to_joint_origin_transform );
2485
2479
// for sensor and projector blocks only
2486
2480
ReduceSDFExtensionsTransform ((*ge));
@@ -2568,11 +2562,12 @@ void ReduceSDFExtensionsTransform(SDFExtensionPtr _ge)
2568
2562
for (auto blobIt = _ge->blobs .begin ();
2569
2563
blobIt != _ge->blobs .end (); ++blobIt)
2570
2564
{
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" );
2576
2571
}
2577
2572
}
2578
2573
@@ -3364,12 +3359,13 @@ bool FixedJointShouldBeReduced(urdf::JointSharedPtr _jnt)
3364
3359
}
3365
3360
3366
3361
// //////////////////////////////////////////////////////////////////////////////
3367
- void ReduceSDFExtensionSensorTransformReduction (
3362
+ void ReduceSDFExtensionElementTransformReduction (
3368
3363
std::vector<XMLDocumentPtr>::iterator _blobIt,
3369
- ignition::math::Pose3d _reductionTransform)
3364
+ const ignition::math::Pose3d &_reductionTransform,
3365
+ const std::string &_elementName)
3370
3366
{
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 )
3373
3369
{
3374
3370
// parse it and add/replace the reduction transform
3375
3371
// find first instance of xyz and rpy, replace with reduction transform
@@ -3383,166 +3379,51 @@ void ReduceSDFExtensionSensorTransformReduction(
3383
3379
// sdfdbg << " " << streamIn.CStr() << "\n";
3384
3380
// }
3385
3381
3386
- auto sensorPose {ignition::math::Pose3d::Zero};
3382
+ auto pose {ignition::math::Pose3d::Zero};
3387
3383
{
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" );
3390
3387
if (oldPoseKey)
3391
3388
{
3392
3389
const auto & poseElemXml = oldPoseKey->ToElement ();
3393
3390
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
3404
3391
{
3405
- sdferr << " Unexpected case in sensor pose computation\n " ;
3406
3392
return ;
3407
3393
}
3408
3394
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 ())
3503
3396
{
3504
- sdferr << " Unexpected case in projector pose computation\n " ;
3505
- return ;
3397
+ poseText = poseElemXml->GetText ();
3506
3398
}
3507
3399
3508
3400
// delete the <pose> tag, we'll add a new one at the end
3509
- projectorElement ->DeleteChild (oldPoseKey);
3401
+ element ->DeleteChild (oldPoseKey);
3510
3402
}
3511
3403
3512
3404
// parse the 6-tuple text into math::Pose3d
3513
- std::stringstream ss;
3405
+ std::stringstream ss;
3514
3406
ss.imbue (std::locale::classic ());
3515
- ss << projectorPosText ;
3516
- ss >> projectorPose ;
3407
+ ss << poseText ;
3408
+ ss >> pose ;
3517
3409
if (ss.fail ())
3518
3410
{
3519
- sdferr << " Could not parse <projector ><pose>: ["
3520
- << projectorPosText << " ]\n " ;
3411
+ sdferr << " Could not parse <" << _elementName << " ><pose>: ["
3412
+ << poseText << " ]\n " ;
3521
3413
return ;
3522
3414
}
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);
3534
3415
}
3535
3416
3536
- _reductionTransform = _reductionTransform * projectorPose ;
3417
+ pose = _reductionTransform * pose ;
3537
3418
3538
3419
// 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 ());
3546
3427
3547
3428
urdf::Vector3 reductionRpy;
3548
3429
reductionQ.getRPY (reductionRpy.x , reductionRpy.y , reductionRpy.z );
@@ -3555,10 +3436,11 @@ void ReduceSDFExtensionProjectorTransformReduction(
3555
3436
3556
3437
auto * doc = (*_blobIt)->GetDocument ();
3557
3438
tinyxml2::XMLText *poseTxt = doc->NewText (poseStream.str ().c_str ());
3558
- auto poseKey = doc->NewElement (" pose" );
3439
+ tinyxml2::XMLElement *poseKey = doc->NewElement (" pose" );
3440
+
3559
3441
poseKey->LinkEndChild (poseTxt);
3560
3442
3561
- projectorElement ->LinkEndChild (poseKey);
3443
+ element ->LinkEndChild (poseKey);
3562
3444
}
3563
3445
}
3564
3446
0 commit comments