@@ -80,16 +80,42 @@ double JointFeatures::GetJointAcceleration(
80
80
double JointFeatures::GetJointForce (
81
81
const Identity &_id, const std::size_t _dof) const
82
82
{
83
+ double results = gz::math::NAN_D;
83
84
const auto *joint = this ->ReferenceInterface <JointInfo>(_id);
84
85
const auto *identifier = std::get_if<InternalJoint>(&joint->identifier );
85
- if (identifier)
86
- {
86
+
87
+ if (identifier) {
87
88
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
+ }
90
117
}
91
-
92
- return gz::math::NAN_D;
118
+ return results;
93
119
}
94
120
95
121
// ///////////////////////////////////////////////
0 commit comments