Drake
Drake C++ Documentation
contact_results_to_lcm.h File Reference
#include <functional>
#include <memory>
#include <optional>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <vector>
#include "drake/common/default_scalars.h"
#include "drake/common/drake_copyable.h"
#include "drake/geometry/geometry_ids.h"
#include "drake/geometry/scene_graph.h"
#include "drake/lcmt_contact_results_for_viz.hpp"
#include "drake/multibody/plant/contact_results.h"
#include "drake/multibody/plant/multibody_plant.h"
#include "drake/systems/framework/diagram_builder.h"
#include "drake/systems/framework/leaf_system.h"
#include "drake/systems/lcm/lcm_publisher_system.h"
Include dependency graph for contact_results_to_lcm.h:

Classes

class  ContactResultsToLcmSystem< T >
 A System that encodes ContactResults into a lcmt_contact_results_for_viz message. More...
 

Namespaces

 drake
 
 drake::multibody
 

Functions

 DRAKE_DECLARE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_SCALARS (class drake::multibody::ContactResultsToLcmSystem)
 
Visualizing contact results

These functions extend a Diagram with the required components to publish contact results (as reported by MultibodyPlant) to a visualizer (Meldis). We recommend using these functions instead of assembling the requisite components by hand.

These must be called during Diagram building. Each function makes modifications to the diagram being constructed by builder including the following changes:

  • adds systems multibody::ContactResultsToLcmSystem and LcmPublisherSystem to the Diagram and connects the draw message output to the publisher input,
  • connects a ContactResults<double>-valued output port to the ContactResultsToLcmSystem system, and
  • sets the publishing rate based on publish_period.

The two overloads differ in the following way:

  • One overload takes an OutputPort and one doesn't. This determines what is connected to the ContactResultsToLcmSystem input port. The overload that specifies an OutputPort will attempt to connect that port. The one that doesn't will connect the given plant's contact results output port.

The parameters have the following semantics:

Parameters
builderThe diagram builder being used to construct the Diagram. Systems will be added to this builder.
plantThe System in builder containing the plant whose contact results are to be visualized.
scene_graphThe SceneGraph that will determine how the geometry names will appear in the lcm message.
publish_periodAn optional period to pass along to the LcmPublisherSystem constructor; when null, a reasonable default period will be used.
lcmAn optional lcm interface through which lcm messages will be dispatched. Will be allocated internally if none is supplied. If one is given, it must remain alive at least as long as the diagram built from builder.
contact_results_portThe optional port that will be connected to the ContactResultsToLcmSystem (as documented above).
Returns
(for all overloads) the LcmPublisherSystem (in case callers, e.g., need to change the default publishing rate).
Precondition
plant is contained within the supplied builder.
scene_graph is contained with the supplied builder.
contact_results_port (if given) belongs to a system that is an immediate child of builder.
systems::lcm::LcmPublisherSystem * ConnectContactResultsToDrakeVisualizer (systems::DiagramBuilder< double > *builder, const MultibodyPlant< double > &plant, const geometry::SceneGraph< double > &scene_graph, lcm::DrakeLcmInterface *lcm=nullptr, std::optional< double > publish_period=std::nullopt)
 MultibodyPlant-connecting overload. More...
 
systems::lcm::LcmPublisherSystem * ConnectContactResultsToDrakeVisualizer (systems::DiagramBuilder< double > *builder, const MultibodyPlant< double > &plant, const geometry::SceneGraph< double > &scene_graph, const systems::OutputPort< double > &contact_results_port, lcm::DrakeLcmInterface *lcm=nullptr, std::optional< double > publish_period=std::nullopt)
 OutputPort-connecting overload. More...
 

Function Documentation

◆ DRAKE_DECLARE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_SCALARS()

DRAKE_DECLARE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_SCALARS ( class drake::multibody::ContactResultsToLcmSystem  )