RobotLocomotion / drake

Model-based design and verification for robotics.
https://drake.mit.edu
Other
3.17k stars 1.24k forks source link

Uninformative error message when calling AddMinimumDistanceLowerBoundConstraint on InverseKinematics objec #21541

Open wernerpe opened 3 weeks ago

wernerpe commented 3 weeks ago

Hi all,

I ran into an uninformative error message when trying to call ' AddMinimumDistanceLowerBoundConstraint' on an InverseKinematics object. I had incorrectly constructed the IK object without passing the plant_context (like this "ik = InverseKinematics(plant)") and subsequently called "ik.AddMinimumDistanceLowerBoundConstraint(0.01, 0.1)" which throws the error:

"ValueError: Kinematic constraint: Cannot get a valid geometry::QueryObject. Either the plant's geometry query input port is not properly connected to the SceneGraph's geometry query output port, or the plantcontext is incorrect. Please refer to AddMultibodyPlantSceneGraph on connecting MultibodyPlant to SceneGraph."

The solution in my case was simply to pass my plant_context like so "ik = InverseKinematics(plant, plant_context)" to prevent the IK constructor from creating its own. Would it be possible to add this information to this error message? E.g.

"Kinematic constraint: Cannot get a valid geometry::QueryObject. Either the plant's geometry query input port is not properly connected to the SceneGraph's geometry query output port, or the plantcontext is incorrect. Please refer to AddMultibodyPlantSceneGraph on connecting MultibodyPlant to SceneGraph. If this error is thrown while adding a constraint to InverseKinematics, try constructing the object while passing the plant_context in the constructor: InverseKinematics(plant, plant_context) "

Thanks!