@@ -331,29 +331,21 @@ void JointFeatures::SetJointMaxEffort(
331
331
// ///////////////////////////////////////////////
332
332
std::size_t JointFeatures::GetJointDegreesOfFreedom (const Identity &_id) const
333
333
{
334
- auto jointInfo = this ->ReferenceInterface <JointInfo>(_id);
335
- if (jointInfo->type == JointInfo::JointType::CONSTRAINT)
336
- return 0 ;
337
- return jointInfo->joint ->getNumDofs ();
334
+ return this ->ReferenceInterface <JointInfo>(_id)->joint ->getNumDofs ();
338
335
}
339
336
340
337
// ///////////////////////////////////////////////
341
338
Pose3d JointFeatures::GetJointTransformFromParent (const Identity &_id) const
342
339
{
343
- auto jointInfo = this ->ReferenceInterface <JointInfo>(_id);
344
- if (jointInfo->type == JointInfo::JointType::CONSTRAINT)
345
- return jointInfo->constraint ->getRelativeTransform ().inverse ();
346
- return jointInfo->joint ->getTransformFromParentBodyNode ();
340
+ return this ->ReferenceInterface <JointInfo>(_id)
341
+ ->joint ->getTransformFromParentBodyNode ();
347
342
}
348
343
349
344
// ///////////////////////////////////////////////
350
345
Pose3d JointFeatures::GetJointTransformToChild (const Identity &_id) const
351
346
{
352
- auto jointInfo = this ->ReferenceInterface <JointInfo>(_id);
353
- if (jointInfo->type == JointInfo::JointType::CONSTRAINT)
354
- return jointInfo->constraint ->getRelativeTransform ();
355
347
return this ->ReferenceInterface <JointInfo>(_id)
356
- ->joint ->getTransformFromChildBodyNode ().inverse ();
348
+ ->joint ->getTransformFromChildBodyNode ().inverse ();
357
349
}
358
350
359
351
// ///////////////////////////////////////////////
@@ -467,11 +459,6 @@ Identity JointFeatures::CastToFixedJoint(
467
459
const Identity &_jointID) const
468
460
{
469
461
auto jointInfo = this ->ReferenceInterface <JointInfo>(_jointID);
470
- if (jointInfo->type == JointInfo::JointType::CONSTRAINT)
471
- {
472
- // TODO(arjo): Handle constraint casts.
473
- return this ->GenerateInvalidId ();
474
- }
475
462
dart::dynamics::WeldJoint *const weld =
476
463
dynamic_cast <dart::dynamics::WeldJoint *>(
477
464
jointInfo->joint .get ());
@@ -499,15 +486,25 @@ Identity JointFeatures::AttachFixedJoint(
499
486
if (bn->getParentJoint ()->getType () != " FreeJoint" )
500
487
{
501
488
// child already has a parent joint
502
- // use a WeldJointConstraint between the two bodies
489
+ // Create a phantom link and a joint to attach the child to the phantom
490
+ const auto &[joint, phantomBody] =
491
+ bn->getSkeleton ()->createJointAndBodyNodePair <
492
+ dart::dynamics::WeldJoint,
493
+ dart::dynamics::BodyNode>(
494
+ bn, properties, dart::dynamics::BodyNode::AspectProperties ());
495
+ const std::size_t jointID = this ->AddJoint (joint);
496
+ phantomBody->setCollidable (false );
497
+
498
+ // use a WeldJointConstraint between the phantom joint and the link
503
499
auto worldId = this ->GetWorldOfModelImpl (
504
500
this ->models .IdentityOf (bn->getSkeleton ()));
505
501
auto dartWorld = this ->worlds .at (worldId);
506
502
507
503
auto constraint =
508
- std::make_shared<dart::constraint::WeldJointConstraint>(parentBn, bn);
504
+ std::make_shared<dart::constraint::WeldJointConstraint>(
505
+ parentBn, phantomBody);
509
506
dartWorld->getConstraintSolver ()->addConstraint (constraint);
510
- auto jointID = this ->AddJointConstraint ( constraint);
507
+ this ->AddJointWeldConstraint (jointID, constraint, phantomBody );
511
508
return this ->GenerateIdentity (jointID, this ->joints .at (jointID));
512
509
}
513
510
{
@@ -530,11 +527,6 @@ Identity JointFeatures::CastToFreeJoint(
530
527
const Identity &_jointID) const
531
528
{
532
529
auto jointInfo = this ->ReferenceInterface <JointInfo>(_jointID);
533
- if (jointInfo->type == JointInfo::JointType::CONSTRAINT)
534
- {
535
- // TODO(arjo): Handle constraint casts.
536
- return this ->GenerateInvalidId ();
537
- }
538
530
auto *const freeJoint =
539
531
dynamic_cast <dart::dynamics::FreeJoint *>(
540
532
jointInfo->joint .get ());
@@ -559,11 +551,6 @@ Identity JointFeatures::CastToRevoluteJoint(
559
551
const Identity &_jointID) const
560
552
{
561
553
auto jointInfo = this ->ReferenceInterface <JointInfo>(_jointID);
562
- if (jointInfo->type == JointInfo::JointType::CONSTRAINT)
563
- {
564
- // TODO(arjo): Handle constraint casts.
565
- return this ->GenerateInvalidId ();
566
- }
567
554
dart::dynamics::RevoluteJoint *const revolute =
568
555
dynamic_cast <dart::dynamics::RevoluteJoint *>(
569
556
jointInfo->joint .get ());
@@ -609,9 +596,26 @@ Identity JointFeatures::AttachRevoluteJoint(
609
596
610
597
if (bn->getParentJoint ()->getType () != " FreeJoint" )
611
598
{
612
- // child already has a parent joint
613
- // TODO(scpeters): use a WeldJointConstraint between the two bodies
614
- return this ->GenerateInvalidId ();
599
+ // Create a phantom link and a joint to attach the child to the phantom
600
+ const auto &[joint, phantomBody] =
601
+ bn->getSkeleton ()->createJointAndBodyNodePair <
602
+ dart::dynamics::RevoluteJoint,
603
+ dart::dynamics::BodyNode>(
604
+ bn, properties, dart::dynamics::BodyNode::AspectProperties ());
605
+ const std::size_t jointID = this ->AddJoint (joint);
606
+ phantomBody->setCollidable (false );
607
+
608
+ // use a WeldJointConstraint between the phantom joint and the link
609
+ auto worldId = this ->GetWorldOfModelImpl (
610
+ this ->models .IdentityOf (bn->getSkeleton ()));
611
+ auto dartWorld = this ->worlds .at (worldId);
612
+
613
+ auto constraint =
614
+ std::make_shared<dart::constraint::WeldJointConstraint>(
615
+ parentBn, phantomBody);
616
+ dartWorld->getConstraintSolver ()->addConstraint (constraint);
617
+ this ->AddJointWeldConstraint (jointID, constraint, phantomBody);
618
+ return this ->GenerateIdentity (jointID, this ->joints .at (jointID));
615
619
}
616
620
617
621
{
@@ -634,11 +638,6 @@ Identity JointFeatures::CastToPrismaticJoint(
634
638
const Identity &_jointID) const
635
639
{
636
640
auto jointInfo = this ->ReferenceInterface <JointInfo>(_jointID);
637
- if (jointInfo->type == JointInfo::JointType::CONSTRAINT)
638
- {
639
- // TODO(arjo): Handle constraint casts.
640
- return this ->GenerateInvalidId ();
641
- }
642
641
dart::dynamics::PrismaticJoint *prismatic =
643
642
dynamic_cast <dart::dynamics::PrismaticJoint*>(jointInfo->joint .get ());
644
643
@@ -683,9 +682,26 @@ Identity JointFeatures::AttachPrismaticJoint(
683
682
684
683
if (bn->getParentJoint ()->getType () != " FreeJoint" )
685
684
{
686
- // child already has a parent joint
687
- // TODO(scpeters): use a WeldJointConstraint between the two bodies
688
- return this ->GenerateInvalidId ();
685
+ // Create a phantom link and a joint to attach the child to the phantom
686
+ const auto &[joint, phantomBody] =
687
+ bn->getSkeleton ()->createJointAndBodyNodePair <
688
+ dart::dynamics::PrismaticJoint,
689
+ dart::dynamics::BodyNode>(
690
+ bn, properties, dart::dynamics::BodyNode::AspectProperties ());
691
+ const std::size_t jointID = this ->AddJoint (joint);
692
+ phantomBody->setCollidable (false );
693
+
694
+ // use a WeldJointConstraint between the phantom joint and the link
695
+ auto worldId = this ->GetWorldOfModelImpl (
696
+ this ->models .IdentityOf (bn->getSkeleton ()));
697
+ auto dartWorld = this ->worlds .at (worldId);
698
+
699
+ auto constraint =
700
+ std::make_shared<dart::constraint::WeldJointConstraint>(
701
+ parentBn, phantomBody);
702
+ dartWorld->getConstraintSolver ()->addConstraint (constraint);
703
+ this ->AddJointWeldConstraint (jointID, constraint, phantomBody);
704
+ return this ->GenerateIdentity (jointID, this ->joints .at (jointID));
689
705
}
690
706
691
707
{
0 commit comments