Skip to content

Commit 96e0643

Browse files
MegMllMegane Millan
and
Megane Millan
authored
Fix Frames order in reducedModel (#2160)
* Add frame to model in the same order as in the input model * Test to make sure frames are in the same order in reduce and full model * Remove useless comments * Added to changelog --------- Co-authored-by: Megane Millan <[email protected]>
1 parent 07e8b00 commit 96e0643

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1010
- Set NOMINMAX as a public definitions on Windows ([#2139](https://github.com/stack-of-tasks/pinocchio/pull/2139))
1111

1212
### Fixed
13+
- Order of frames in ReducedModel is now the same as in the full model ([#2160](https://github.com/stack-of-tasks/pinocchio/pull/2160))
1314
- Remove a lot of warnings ([#2139](https://github.com/stack-of-tasks/pinocchio/pull/2139))
1415
- `MeshcatVisualizer` doesn't crash anymore when there is no collision model defined ([#2147](https://github.com/stack-of-tasks/pinocchio/pull/2147))
1516
- Fix MSVC build ([#2155](https://github.com/stack-of-tasks/pinocchio/pull/2155))

include/pinocchio/algorithm/model.hxx

+43-4
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ namespace pinocchio
339339
// Sort indexes
340340
std::sort(list_of_joints_to_lock.begin(),list_of_joints_to_lock.end());
341341

342+
typename Model::FrameVector::const_iterator frame_it = input_model.frames.begin();
343+
342344
// Check that they are not two identical elements
343345
for(size_t id = 1; id < list_of_joints_to_lock.size(); ++id)
344346
{
@@ -366,6 +368,7 @@ namespace pinocchio
366368

367369
for(JointIndex joint_id = 1; joint_id < (JointIndex)input_model.njoints; ++joint_id)
368370
{
371+
369372
const JointIndex joint_id_to_lock = (current_index_to_lock < list_of_joints_to_lock.size()) ? list_of_joints_to_lock[current_index_to_lock] : 0;
370373

371374
const JointIndex input_parent_joint_index = input_model.parents[joint_id];
@@ -394,6 +397,43 @@ namespace pinocchio
394397
if(joint_id == joint_id_to_lock)
395398
{
396399
// the joint should not be added to the Model but aggragated to its parent joint
400+
//Add frames up to the joint to lock
401+
while((*frame_it).name != joint_name)
402+
{
403+
++frame_it;
404+
const Frame & input_frame = *frame_it;
405+
if(input_frame.name == joint_name)
406+
break;
407+
const std::string & support_joint_name = input_model.names[input_frame.parent];
408+
409+
std::vector<JointIndex>::const_iterator support_joint_it = std::find(list_of_joints_to_lock.begin(),
410+
list_of_joints_to_lock.end(),
411+
input_frame.parent);
412+
413+
if(support_joint_it != list_of_joints_to_lock.end())
414+
{
415+
if( input_frame.type == JOINT
416+
&& reduced_model.existFrame(input_frame.name)
417+
&& support_joint_name == input_frame.name)
418+
continue; // this means that the Joint is now fixed and has been replaced by a Frame. No need to add a new one.
419+
420+
// The joint has been removed and replaced by a Frame
421+
const FrameIndex joint_frame_id = reduced_model.getFrameId(support_joint_name);
422+
const Frame & joint_frame = reduced_model.frames[joint_frame_id];
423+
Frame reduced_frame = input_frame;
424+
reduced_frame.placement = joint_frame.placement * input_frame.placement;
425+
reduced_frame.parent = joint_frame.parent;
426+
reduced_frame.previousFrame = reduced_model.getFrameId(input_model.frames[input_frame.previousFrame].name);
427+
reduced_model.addFrame(reduced_frame, false);
428+
}
429+
else
430+
{
431+
Frame reduced_frame = input_frame;
432+
reduced_frame.parent = reduced_model.getJointId(input_model.names[input_frame.parent]);
433+
reduced_frame.previousFrame = reduced_model.getFrameId(input_model.frames[input_frame.previousFrame].name);
434+
reduced_model.addFrame(reduced_frame, false);
435+
}
436+
}
397437

398438
// Compute the new placement of the joint with respect to its parent joint in the new kinematic tree.
399439
JointData joint_data = joint_input_model.createData();
@@ -437,7 +477,7 @@ namespace pinocchio
437477
= joint_input_model.jointVelocitySelector(input_model.rotorGearRatio);
438478
}
439479
}
440-
480+
441481
// Retrieve and extend the reference configurations
442482
typedef typename Model::ConfigVectorMap ConfigVectorMap;
443483
for(typename ConfigVectorMap::const_iterator config_it = input_model.referenceConfigurations.begin();
@@ -461,9 +501,8 @@ namespace pinocchio
461501
reduced_model.referenceConfigurations.insert(std::make_pair(config_name, reduced_config_vector));
462502
}
463503

464-
// Add all frames
465-
typename Model::FrameVector::const_iterator frame_it = input_model.frames.begin();
466-
for(++frame_it;frame_it != input_model.frames.end(); ++frame_it)
504+
// Add all the missing frames
505+
for(;frame_it != input_model.frames.end(); ++frame_it)
467506
{
468507
const Frame & input_frame = *frame_it;
469508
const std::string & support_joint_name = input_model.names[input_frame.parent];

unittest/model.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ BOOST_AUTO_TEST_CASE(test_buildReducedModel_with_geom)
462462
BOOST_CHECK_EQUAL(go1.overrideMaterial, go2.overrideMaterial);
463463
BOOST_CHECK_EQUAL(go1.meshColor, go2.meshColor);
464464
BOOST_CHECK_EQUAL(go1.meshTexturePath, go2.meshTexturePath);
465+
BOOST_CHECK_EQUAL(go1.parentFrame, go2.parentFrame);
465466
BOOST_CHECK_EQUAL(humanoid_model.frames[go1.parentFrame].name,
466467
reduced_humanoid_model.frames[go2.parentFrame].name);
467468
}

0 commit comments

Comments
 (0)