Drake
lcm_publisher_system.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <string>
5 #include <vector>
6 
14 
15 namespace drake {
16 namespace systems {
17 namespace lcm {
18 
24 class LcmPublisherSystem : public LeafSystem<double> {
25  public:
27 
28 
39  template <typename LcmMessage>
40  static std::unique_ptr<LcmPublisherSystem> Make(
41  const std::string& channel, drake::lcm::DrakeLcmInterface* lcm) {
42  return std::make_unique<LcmPublisherSystem>(
43  channel, std::make_unique<Serializer<LcmMessage>>(), lcm);
44  }
45 
59  LcmPublisherSystem(const std::string& channel,
60  std::unique_ptr<SerializerInterface> serializer,
62 
77  LcmPublisherSystem(const std::string& channel,
78  const LcmAndVectorBaseTranslator& translator,
80 
95  LcmPublisherSystem(const std::string& channel,
96  const LcmTranslatorDictionary& translator_dictionary,
98 
99  ~LcmPublisherSystem() override;
100 
101  const std::string& get_channel_name() const;
102 
104  static std::string make_name(const std::string& channel);
105 
111  void set_publish_period(double period);
112 
117  void DoPublish(
118  const Context<double>& context,
119  const std::vector<const systems::PublishEvent<double>*>&) const override;
120 
130 
131  private:
132  // All constructors delegate to here.
133  LcmPublisherSystem(const std::string& channel,
134  const LcmAndVectorBaseTranslator* translator,
135  std::unique_ptr<SerializerInterface> serializer,
137 
138  // The channel on which to publish LCM messages.
139  const std::string channel_;
140 
141  // Converts VectorBase objects into LCM message bytes.
142  // Will be non-null iff our input port is vector-valued.
143  const LcmAndVectorBaseTranslator* const translator_{};
144 
145  // Converts Value<LcmMessage> objects into LCM message bytes.
146  // Will be non-null iff our input port is abstract-valued.
147  std::unique_ptr<SerializerInterface> serializer_;
148 
149  // A const pointer to an LCM subsystem. Note that while the pointer is const,
150  // the LCM subsystem is not const.
151  drake::lcm::DrakeLcmInterface* const lcm_{};
152 };
153 
154 } // namespace lcm
155 } // namespace systems
156 } // namespace drake
Definition: automotive_demo.cc:88
void set_publish_period(double period)
Sets the publishing period of this system.
Definition: lcm_publisher_system.cc:81
const std::string & get_channel_name() const
Definition: lcm_publisher_system.cc:77
A dictionary that maps between LCM channel names and translators that convert between LCM message obj...
Definition: lcm_translator_dictionary.h:20
std::vector< double > vector
Definition: translator_test.cc:20
Publishes an LCM message containing information from its input port.
Definition: lcm_publisher_system.h:24
static std::string make_name(const std::string &channel)
Returns the default name for a system that publishes channel.
Definition: lcm_publisher_system.cc:73
A pure virtual interface that enables LCM to be mocked.
Definition: drake_lcm_interface.h:14
static std::unique_ptr< LcmPublisherSystem > Make(const std::string &channel, drake::lcm::DrakeLcmInterface *lcm)
A factory method that returns an LcmPublisherSystem that takes Value<LcmMessage> message objects on i...
Definition: lcm_publisher_system.h:40
A superclass template that extends System with some convenience utilities that are not applicable to ...
Definition: leaf_system.h:82
void DoPublish(const Context< double > &context, const std::vector< const systems::PublishEvent< double > * > &) const override
Takes the VectorBase from the input port of the context and publishes it onto an LCM channel...
Definition: lcm_publisher_system.cc:85
const LcmAndVectorBaseTranslator & get_translator() const
Returns the translator used by this publisher.
Definition: lcm_publisher_system.cc:108
Defines an abstract parent class of all translators that convert between LCM message bytes and drake:...
Definition: lcm_and_vector_base_translator.h:18
This class represents a publish event.
Definition: event.h:194
~LcmPublisherSystem() override
Definition: lcm_publisher_system.cc:71
#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:35
Provides careful macros to selectively enable or disable the special member functions for copy-constr...
LcmPublisherSystem(const LcmPublisherSystem &)=delete