underactuated.meshcat_utils

underactuated.meshcat_utils.AddMeshcatTriad(meshcat, path, length=0.25, radius=0.01, opacity=1.0, X_PT=RigidTransform(R=RotationMatrix([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]), p=[0.0, 0.0, 0.0]))

Adds an X-Y-Z triad to the meshcat scene.

Parameters:
  • meshcat (Meshcat) – A Meshcat instance.

  • path (str) – The Meshcat path on which to attach the triad. Using relative paths will attach the triad to the path’s coordinate system.

  • length (float) – The length of the axes in meters.

  • radius (float) – The radius of the axes in meters.

  • opacity (float) – The opacity of the axes in [0, 1].

  • X_PT (RigidTransform) – The pose of the triad relative to the path.

class underactuated.meshcat_utils.MeshcatSliders(meshcat, slider_names)

A system that outputs the values from meshcat sliders.

An output port is created for each element in the list slider_names. Each element of slider_names must itself be an iterable collection (list, tuple, set, …) of strings, with the names of sliders that have already been added to Meshcat via Meshcat.AddSlider().

The same slider may be used in multiple ports.

Parameters:
  • meshcat (Meshcat) –

  • slider_names (List[str]) –

underactuated.meshcat_utils.PublishPositionTrajectory(trajectory, root_context, plant, visualizer, time_step=0.030303030303030304)

Publishes an animation to Meshcat of a MultibodyPlant using a trajectory of the plant positions.

Parameters:
  • trajectory (Trajectory) – A Trajectory instance.

  • root_context (Context) – The root context of the diagram containing plant.

  • plant (MultibodyPlant) – A MultibodyPlant instance.

  • visualizer (MeshcatVisualizer) – A MeshcatVisualizer instance.

  • time_step (float) – The time step between published frames.

class underactuated.meshcat_utils.StopButton(meshcat, check_interval=0.1)

Adds a button named Stop Simulation to the meshcat GUI, and registers the Escape key to press it. Pressing this button will terminate the simulation.

Parameters:
  • meshcat (Meshcat) – The meshcat instance in which to register the button.

  • check_interval (float) – The period at which to check for button presses.

class underactuated.meshcat_utils.WsgButton(meshcat)

Adds a button named Open/Close Gripper to the meshcat GUI, and registers the Space key to press it. Pressing this button will toggle the value of the output port from a wsg position command corresponding to an open position or a closed position.

Parameters:

meshcat (Meshcat) – The meshcat instance in which to register the button.

underactuated.meshcat_utils.plot_mathematical_program(meshcat, path, prog, X, Y, result=None, point_size=0.05)

Visualize a MathematicalProgram in Meshcat.

Parameters:
  • meshcat (Meshcat) – A Meshcat instance.

  • path (str) – The Meshcat path to the visualization.

  • prog (MathematicalProgram) – A MathematicalProgram instance.

  • X (ndarray) – A 2D array of x values.

  • Y (ndarray) – A 2D array of y values.

  • result (MathematicalProgramResult | None) – A MathematicalProgramResult instance; if provided then the solution is visualized as a point.

  • point_size (float) – The size of the solution point.