I am trying to include my URDF file with a robot that has contact tags activated, and I intend to use DirectCollocation to generate an optimal trajectory for my robot.
First I tried creating the plant using MultibodyPlant(), then created the scene_graph using SceneGraph() and then thought I connected the plant to the scene_graph using RegisterAsSourceForSceneGraph(). When I passed the context=plant.CreateDefaultContext() to the my SNOPT solver, I got an error saying the time derivatives and residuals are being evaluated, and was directed to https://drake.mit.edu/troubleshooting.html#system-framework
I modified my code to:
sim_time_step = 0.0
builder = DiagramBuilder()
plant, scene_graph = AddMultibodyPlantSceneGraph(
builder, time_step=sim_time_step)
parser = Parser(plant)
parser.AddModelFromFile("robot.urdf")
plant.Finalize()
diagram = builder.Build()
context = diagram.CreateDefaultContext()
plant_context = plant.GetMyContextFromRoot(root_context=context)
When I run this code, now I receive the error:
TypeError: GetMyContextFromRoot(): incompatible function arguments. The following argument types are supported:
1. (self: pydrake.systems.framework.System_float, arg0: pydrake.systems.framework.Context_float) -> pydrake.systems.framework.Context_float
Invoked with: <pydrake.multibody.plant.MultibodyPlant_float object at 0x7fbd2784e370>; kwargs: root_context=<pydrake.systems.framework.Context_float object at 0x7fbd27862130>
How do I get past this error?