Drake
car_vis_applicator.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <map>
4 #include <memory>
5 
8 #include "drake/lcmt_viewer_load_robot.hpp"
12 
13 namespace drake {
14 namespace automotive {
15 
16 /// CarVisApplicator takes as input a PoseVector containing vehicle poses. For
17 /// each vehicle, it outputs the poses of all visual geometries associated with
18 /// the vehicle's visualization.
19 ///
20 /// Prior to instantiating this system's systems::Context and
21 /// systems::SystemOutput, a CarVis object must be provided for each vehicle in
22 /// the simulation using AddCarVis().
23 ///
24 /// This system is stateless and is direct feed-through.
25 ///
26 /// Input port getters:
27 /// - get_car_poses_input_port() - Contains a PoseBundle of every vehicle's
28 /// pose in the world frame (i.e., `X_WM_W` where `W` stands for "world" and
29 /// `M` stands for "Model"). The vehicle IDs and names contained within this
30 /// PoseBundle must match the IDs and names contained within the CarVis
31 /// objects that were supplied via calls to AddCarVis().
32 ///
33 /// Output port getters:
34 /// - get_visual_geometry_poses_output_port() - Contains a PoseBundle of visual
35 /// geometry poses in the world frame.
36 ///
37 /// Instantiated templates for the following kinds of T's are provided:
38 /// - double
39 ///
40 /// They are already available to link against in the containing library.
41 template <typename T>
43  public:
45 
47  ~CarVisApplicator() override {}
48 
49  /// Returns a descriptor of the input port that contains the vehicle poses in
50  /// the form of a PoseBundle.
52 
53  /// Returns the output port that contains the visual geometry
54  /// poses of all vehicle visualizations.
56 
57  /// Adds a CarVis object for a vehicle. The ID returned by CarVis::id() must
58  /// be unique among the CarVis objects added to this method. A
59  /// std::runtime_error is thrown if the provided CarVis object's ID is a
60  /// duplicate of a previously provided CarVis object's ID.
61  ///
62  /// @pre The context for this system has not been created.
63  void AddCarVis(std::unique_ptr<CarVis<T>> vis);
64 
65  /// Returns an lcmt_viewer_load_robot message containing the geometries of the
66  /// bodies being visualized.
67  lcmt_viewer_load_robot get_load_robot_message() const;
68 
69  /// Returns the number vehicles being visualized.
70  int num_cars() const { return static_cast<int>(visualizers_.size()); }
71 
72  /// Returns the total number of poses of bodies being visualized.
73  int num_vis_poses() const;
74 
75  private:
76  systems::rendering::PoseBundle<T> MakePoseBundleOutput() const;
77 
78  void CalcPoseBundleOutput(const systems::Context<T>& context,
79  systems::rendering::PoseBundle<T>* output) const;
80 
81  // The key is the car ID.
82  std::map<int, std::unique_ptr<const CarVis<T>>> visualizers_;
83 
84  // The key is the car ID and the value is the starting index within the output
85  // PoseBundle.
86  mutable std::map<int, int> starting_indices_;
87 
88  int input_port_index_{};
89  int output_port_index_{};
90  bool context_allocated_{false};
91 };
92 
93 } // namespace automotive
94 } // namespace drake
int num_vis_poses() const
Returns the total number of poses of bodies being visualized.
Definition: car_vis_applicator.cc:146
CarVisApplicator takes as input a PoseVector containing vehicle poses.
Definition: car_vis_applicator.h:42
Definition: automotive_demo.cc:88
CarVisApplicator()
Definition: car_vis_applicator.cc:27
const systems::OutputPort< T > & get_visual_geometry_poses_output_port() const
Returns the output port that contains the visual geometry poses of all vehicle visualizations.
Definition: car_vis_applicator.cc:45
Context is an abstract base class template that represents all the inputs to a System: time...
Definition: query_handle.h:10
lcmt_viewer_load_robot get_load_robot_message() const
Returns an lcmt_viewer_load_robot message containing the geometries of the bodies being visualized...
Definition: car_vis_applicator.cc:60
PoseBundle is a container for a set of poses, represented by an Isometry3, and corresponding velociti...
Definition: pose_bundle.h:40
const systems::InputPortDescriptor< T > & get_car_poses_input_port() const
Returns a descriptor of the input port that contains the vehicle poses in the form of a PoseBundle...
Definition: car_vis_applicator.cc:39
int num_cars() const
Returns the number vehicles being visualized.
Definition: car_vis_applicator.h:70
void AddCarVis(std::unique_ptr< CarVis< T >> vis)
Adds a CarVis object for a vehicle.
Definition: car_vis_applicator.cc:50
InputPortDescriptor is a notation for specifying the kind of input a System accepts, on a given port.
Definition: input_port_descriptor.h:21
An OutputPort belongs to a System and represents the properties of one of that System&#39;s output ports...
Definition: output_port.h:67
A superclass template that extends System with some convenience utilities that are not applicable to ...
Definition: leaf_system.h:82
CarVis is a base class that provides visualization geometries and their poses.
Definition: car_vis.h:21
~CarVisApplicator() override
Definition: car_vis_applicator.h:47
#define DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(Classname)
DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN deletes the special member functions for copy-construction, copy-assignment, move-construction, and move-assignment.
Definition: drake_copyable.h:33
Provides careful macros to selectively enable or disable the special member functions for copy-constr...