Jason
Jason

Reputation: 37

New Drake Visualizer Example

After updating my drake to the latest version, my previous simulation code cannot work because of the API change. I am wondering if there is an existing tutorial or example for this new visualization API.

I find a similar example online (https://github.com/RobotLocomotion/drake/issues/8576) but some of these header files cannot be found as well.

My previous implementation is for visualizing the simulation of a piecewise polynomial trajectory, which is as follows:

 // Make a trajectory from these waypoints (first-order hold)
drake::trajectories::PiecewisePolynomial<double> trajectory_solution =
        drake::trajectories::PiecewisePolynomial<double>::FirstOrderHold(t_solution, q_solution);
const auto traj_source = viz_builder.AddSystem<drake::systems::TrajectorySource<double>>(
        trajectory_solution);

// Connect the trajectory source directly to the geometry poses
auto q_to_pose = viz_builder.AddSystem<drake::systems::rendering::MultibodyPositionToGeometryPose<double>>(viz_plant);
viz_builder.Connect(traj_source->get_output_port(), q_to_pose->get_input_port());
viz_builder.Connect(q_to_pose->get_output_port(), viz_scene_graph.get_source_pose_port(viz_plant_source_id));

// Create the visualizer
drake::geometry::ConnectDrakeVisualizer(&viz_builder, viz_scene_graph);
std::unique_ptr<drake::systems::Diagram<double>> viz_diagram = viz_builder.Build();

// Set up simulator and run
drake::systems::Simulator<double> simulator(*viz_diagram);
simulator.set_publish_every_time_step(true);
simulator.set_target_realtime_rate(1.0);
simulator.Initialize();
simulator.AdvanceTo(100); 

After taking the suggestions from the answers, I updated the implementation:

drake::geometry::ConnectDrakeVisualizer(&viz_builder, viz_scene_graph);

to

drake::geometry::DrakeVisualizer<double> viz;
viz.AddToBuilder(&viz_builder, viz_scene_graph);

Upvotes: 1

Views: 324

Answers (1)

Russ Tedrake
Russ Tedrake

Reputation: 5533

drake::geometry::ConnectDrakeVisualizer moved to drake::geometry::DrakeVisualizer::AddToBuilder https://drake.mit.edu/doxygen_cxx/classdrake_1_1geometry_1_1_drake_visualizer.html#a532df1140a607611304fbd439519a4c5

Upvotes: 3

Related Questions