0
builder = DiagramBuilder()
plant, scene_graph = AddMultibodyPlantSceneGraph(builder, 0.0)

parser = Parser(plant)

renderer_name = "renderer"
renderer = MakeRenderEngineVtk(RenderEngineVtkParams())
scene_graph.AddRenderer(
    renderer_name, renderer)
...
for i, position in enumerate(positions):
    obj_joints[i].set_translation(plant_context, position)
diagram.Publish(diagram_context)
scene_graph.Publish(sg_context)

The above code does not update anything in the visualizer.

I must run:

simulator.AdvanceTo(100.0)

For anything to update visually.

How do I get the objects to move to their new poses without physics simulation?

user3180
  • 1,369
  • 1
  • 21
  • 38

1 Answers1

2

... does not update anything in the visualizer.

Is that drake_visualizer? It's worth noting that RenderEngines don't "visualize" geoemetry in that sense. They are part of the simulation of cameras and sensors in the actual simulation. What you actually want to do is attach an instance of DrakeVisualizer to your diagram as:

DrakeVisualizer.AddToBuilder(builder, scene_graph)

(before you call builder.Build()).

That is the system responsible for populating drake_visualizer and is the system that would update drake_visualizer upon calling Publish() (and you'd only have to call Publish on the diagram, not scene_graph as well.

On the off chance, if you actually meant that you were attempting to produce rendered images inside the simulation from an RgbdSensor, the instructions would change.

Sean Curtis
  • 1,425
  • 7
  • 8
  • Thanks. So even without Drake_Visualizer mentioned anywhere, just using the VTKEngine above we get a GUI window that shows the simulation. Are you saying if I add DrakeVisualizer it will replace that GUI window built with VTK Engine? – user3180 Nov 06 '21 at 05:50
  • Did you call `ColorRenderCamera(..., show_window=True)` perhaps? That would mean the window you're seeing is the preview image for a simulated camera. – jwnimmer-tri Nov 06 '21 at 15:29
  • Ah, I hadn't thought of the `show_window` parameter. Yes, you can use that parameter to show the last rendering. It's not interactive at all, but it does should you what the render engine has drawn over and over. The key is that you need to invoke the rendering every time you want the window to update. You either need to invoke the `QueryObject` query directly, or have it happen in the simulation by having something like `RgbdSensor`, regularly publish. – Sean Curtis Nov 07 '21 at 15:55
  • I want to clarify something. I already had: DrakeVisualizer.AddToBuilder(builder, scene_graph) in the code – user3180 Nov 12 '21 at 18:26
  • Also the objects were created using: https://github.com/RussTedrake/manipulation/blob/bead198553d328bb2faeba5c22b493104dbf7657/manipulation/scenarios.py#L138 – user3180 Nov 12 '21 at 18:46
  • But basically, it does not work. The spheres created through add shape do not move – user3180 Nov 12 '21 at 18:49
  • See [this issue](https://stackoverflow.com/questions/69950297/plant-setpositions-does-not-update-visualization/69951636?noredirect=1#comment123656046_69951636). There was another "I set the pose, but things didn't move". In that case, the position wasn't being set as expected. Your original post doesn't provide sufficient information for me to tell if it applies to you, but you might check it out. – Sean Curtis Nov 13 '21 at 14:42