Visualization¶
Pinker displays robots with Viser, which serves the scene to a Web browser and handles user inputs. You can start a visualizer from a robot wrapper, then display configurations as the inverse kinematics unrolls:
from pinker.visualizer import start_viser_visualizer
viz = start_viser_visualizer(robot)
viz.display(configuration.q)
Visuals come from the geometry model that
build_geom_from_urdf() reads from the URDF, or
build_geom_from_mjcf() from the MJCF: see
Kinematics for the geometry types the parsers support.
Robot visualization with Viser.
- class pinker.visualizer.ViserVisualizer(model, visual_model=None, collision_model=None)¶
Robot visualizer using Viser.
The viewer and the scene nodes are created when the visualizer starts:
init_viewer()connects to a Viser server, thenload_viewer_model()adds the robot’s visuals and frames to its scene.- collision_model¶
Geometry model with the robot’s collision shapes.
- collision_root_frame¶
Scene node the collision shapes of the model hang from.
- collision_root_node_name¶
Name of that scene node.
- data¶
Data where the visualizer runs its forward kinematics.
- frames¶
Scene nodes of the robot’s visuals and frames, by node name.
- frames_root_frame¶
Scene node the frames of the model hang from.
- frames_root_node_name¶
Name of that scene node.
- model¶
Robot model to visualize.
- viewer¶
Viser server the scene is displayed in, None until
init_viewer()is called.
- viewer_root_node_name¶
Name of the scene node the robot hangs from.
- visual_model¶
Geometry model with the robot’s visuals.
- visual_root_frame¶
Scene node the visuals of the model hang from.
- visual_root_node_name¶
Name of that scene node.
- display(q=None)¶
Display the robot at a given configuration.
- display_collisions(visibility)¶
Toggle display of the collision model.
- display_frames(visibility)¶
Toggle display of the model frames.
- display_visuals(visibility)¶
Toggle display of the visual model.
- init_viewer(viewer=None, open=False, loadModel=False, host='localhost', port=8080)¶
Start a new Viser server (or reuse the one passed as viewer).
- Parameters:
viewer – Existing Viser server to reuse. If None, a new server is started.
open (
bool) – If true, open the viewer in a web browser and wait for a client to connect, for at most ten seconds.loadModel (
bool) – If true, load the visual model in the viewer.host (
str) – Host name the new server listens to.port (
int) – Port the new server listens to.
- Return type:
- load_viewer_geometry_object(geometry_object, prefix, color=None)¶
Add one geometry object to the Viser scene.
Subclasses can override this function to customize how geometries are displayed, for instance by changing the arguments passed to the scene.
- Parameters:
geometry_object (
GeometryObject) – Geometry object to add.prefix (
str) – Name of the parent node in the scene.color (
Optional[Sequence[float]]) – RGBA color of the shape. If None, the color of the geometry object is used.
- Raises:
ValueError – If the shape of the geometry object is not supported.
- Return type:
- load_viewer_model(rootNodeName='robot', frame_axis_length=0.2, frame_axis_radius=0.01, collision_color=None)¶
Load the visual and collision models in the viewer.
Visuals are displayed after loading, collision shapes and frames are hidden. Call
display_collisions()anddisplay_frames()to show them.- Parameters:
rootNodeName (
str) – Name of the root node of the robot in the scene.frame_axis_length (
float) – Length of frame axes in [m].frame_axis_radius (
float) – Radius of frame axes in [m].collision_color (
Optional[Sequence[float]]) – RGBA color applied to all collision shapes. If None, each shape keeps its own color.
- Return type:
- update_placements(geometry_type=GeometryType.VISUAL)¶
Update geometry placements in the viewer.
- Parameters:
geometry_type (
GeometryType) – Kind of geometries to update, visuals by default.- Return type:
- pinker.visualizer.start_viser_visualizer(robot, open=True)¶
Open a Viser visualizer in a Web browser.
- Parameters:
robot (
RobotWrapper) – Robot wrapper with its model and data.open (
bool) – If set (default), open Viser in a new Web browser tab.
- Return type:
- Returns:
Viser visualizer.