Skip to content

Commit 1632c9c

Browse files
committed
[featherstone] Publish joint feedback forces.
1 parent d0a6e50 commit 1632c9c

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

bullet-featherstone/src/JointFeatures.cc

+32-6
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,42 @@ double JointFeatures::GetJointAcceleration(
8080
double JointFeatures::GetJointForce(
8181
const Identity &_id, const std::size_t _dof) const
8282
{
83+
double results = gz::math::NAN_D;
8384
const auto *joint = this->ReferenceInterface<JointInfo>(_id);
8485
const auto *identifier = std::get_if<InternalJoint>(&joint->identifier);
85-
if (identifier)
86-
{
86+
87+
if (identifier) {
8788
const auto *model = this->ReferenceInterface<ModelInfo>(joint->model);
88-
return model->body->getJointTorqueMultiDof(
89-
identifier->indexInBtModel)[_dof];
89+
auto feedback = model->body->getLink(identifier->indexInBtModel).m_jointFeedback;
90+
const auto &link = model->body->getLink(identifier->indexInBtModel);
91+
results = 0.0;
92+
if (link.m_jointType == btMultibodyLink::eRevolute) {
93+
// According to the documentation in btMultibodyLink.h, m_axesTop[0] is the
94+
// joint axis for revolute joints.
95+
Eigen::Vector3d axis = convert(link.getAxisTop(0));
96+
math::Vector3 axis_converted(axis[0], axis[1], axis[2]);
97+
btVector3 angular = feedback->m_reactionForces.getAngular();
98+
math::Vector3<double> angularTorque(
99+
angular.getX(),
100+
angular.getY(),
101+
angular.getZ());
102+
// BUG: The total force is 2 times the cmd one see:
103+
// https://github.com/bulletphysics/bullet3/discussions/3713
104+
results += axis_converted.Dot(angularTorque);
105+
return results / 2.0;
106+
} else if (link.m_jointType == btMultibodyLink::ePrismatic) {
107+
auto axis = convert(link.getAxisBottom(0));
108+
math::Vector3 axis_converted(axis[0], axis[1], axis[2]);
109+
btVector3 linear = feedback->m_reactionForces.getLinear();
110+
math::Vector3<double> linearForce(
111+
linear.getX(),
112+
linear.getY(),
113+
linear.getZ());
114+
results += axis_converted.Dot(linearForce);
115+
return results / 2.0;
116+
}
90117
}
91-
92-
return gz::math::NAN_D;
118+
return results;
93119
}
94120

95121
/////////////////////////////////////////////////

0 commit comments

Comments
 (0)