Search code examples
drake

AddDistanceConstraint() in Multibody Plant?


I am trying to implement a distance constraint between two point bodies, but when I try to use the AddDistanceConstraint() function I get the following error:

'MultibodyPlant_š¯“£floatš¯“¤' object has no attribute 'AddDistanceConstraint'

Here is the code I am using:

    builder = DiagramBuilder()
    compass_walker, scene_graph = AddMultibodyPlantSceneGraph(builder, time_step=0.0)
    Parser(compass_walker).AddModelsFromString(urdf, ".urdf")

    anchorpoint = compass_walker.GetBodyByName("anchorpoint")
    anchorpoint_vector = np.array([0, 0, 0])

    ground_mass = compass_walker.GetBodyByName("ground_mass")
    ground_mass_vector = np.array([0, 0, 0])

    anchor = compass_walker.AddDistanceConstraint(
                anchorpoint,
                anchorpoint_vector,
                ground_mass,
                ground_mass_vector,
                0.01,
            )

I've tried importing AddDistanceConstraint() but was unsuccessful. I've also tried to add the constraint without referencing the Multibody Plant: anchor = AddDistanceConstraint(...) but this also did not work.


Solution

  • I was using an older version of Drake (needed v.1.15.0 or newer). It is worth mentioning that currently distance constraints are only supported for discrete MultibodyPlant models.