Skip to content

Commit 3323de5

Browse files
[featherstone] Publish JointFeedback forces. (#628)
Signed-off-by: Davide Graziato <[email protected]> Signed-off-by: Ian Chen <[email protected]> Co-authored-by: Ian Chen <[email protected]>
1 parent a1cb989 commit 3323de5

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

bullet-featherstone/src/JointFeatures.cc

+46-5
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,59 @@ double JointFeatures::GetJointAcceleration(
158158

159159
/////////////////////////////////////////////////
160160
double JointFeatures::GetJointForce(
161-
const Identity &_id, const std::size_t _dof) const
161+
const Identity &_id, const std::size_t /*_dof*/) const
162162
{
163+
double results = gz::math::NAN_D;
163164
const auto *joint = this->ReferenceInterface<JointInfo>(_id);
164165
const auto *identifier = std::get_if<InternalJoint>(&joint->identifier);
166+
165167
if (identifier)
166168
{
167169
const auto *model = this->ReferenceInterface<ModelInfo>(joint->model);
168-
return model->body->getJointTorqueMultiDof(
169-
identifier->indexInBtModel)[_dof];
170+
auto feedback = model->body->getLink(
171+
identifier->indexInBtModel).m_jointFeedback;
172+
const auto &link = model->body->getLink(identifier->indexInBtModel);
173+
results = 0.0;
174+
if (link.m_jointType == btMultibodyLink::eRevolute)
175+
{
176+
// According to the documentation in btMultibodyLink.h,
177+
// m_axesTop[0] is the joint axis for revolute joints.
178+
Eigen::Vector3d axis = convert(link.getAxisTop(0));
179+
math::Vector3 axis_converted(axis[0], axis[1], axis[2]);
180+
btVector3 angular = feedback->m_reactionForces.getAngular();
181+
math::Vector3<double> angularTorque(
182+
angular.getX(),
183+
angular.getY(),
184+
angular.getZ());
185+
results += axis_converted.Dot(angularTorque);
186+
#if BT_BULLET_VERSION < 326
187+
// not always true
188+
return results / 2.0;
189+
#else
190+
return results;
191+
#endif
192+
}
193+
else if (link.m_jointType == btMultibodyLink::ePrismatic)
194+
{
195+
auto axis = convert(link.getAxisBottom(0));
196+
math::Vector3 axis_converted(axis[0], axis[1], axis[2]);
197+
btVector3 linear = feedback->m_reactionForces.getLinear();
198+
math::Vector3<double> linearForce(
199+
linear.getX(),
200+
linear.getY(),
201+
linear.getZ());
202+
results += axis_converted.Dot(linearForce);
203+
#if BT_BULLET_VERSION < 326
204+
// Not always true see for reference:
205+
// https://github.com/bulletphysics/bullet3/discussions/3713
206+
// https://github.com/gazebosim/gz-physics/issues/565
207+
return results / 2.0;
208+
#else
209+
return results;
210+
#endif
211+
}
170212
}
171-
172-
return gz::math::NAN_D;
213+
return results;
173214
}
174215

175216
/////////////////////////////////////////////////

0 commit comments

Comments
 (0)