FlashLightPlugin.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef GAZEBO_PLUGINS_FLASHLIGHTPLUGIN_HH_
19 #define GAZEBO_PLUGINS_FLASHLIGHTPLUGIN_HH_
20 
21 #include <memory>
22 #include <string>
23 
24 #include <ignition/math/Color.hh>
25 
26 #include "gazebo/common/Plugin.hh"
27 #include "gazebo/physics/physics.hh"
28 
29 namespace gazebo
30 {
31  // forward declaration
32  class FlashLightSettingPrivate;
33 
38  class GZ_PLUGIN_VISIBLE FlashLightSetting
39  {
45  public: FlashLightSetting(
46  const sdf::ElementPtr &_sdf,
47  const physics::ModelPtr &_model,
48  const common::Time &_currentTime);
49 
51  public: virtual ~FlashLightSetting();
52 
55  public: virtual void InitPubLight(
56  const transport::PublisherPtr &_pubLight) final;
57 
61  public:
62  virtual void UpdateLightInEnv(const common::Time &_currentTime) final;
63 
66  public: virtual const std::string Name() const final;
67 
70  public: virtual const physics::LinkPtr Link() const final;
71 
73  public: virtual void SwitchOn() final;
74 
76  public: virtual void SwitchOff() final;
77 
81  public: virtual void SetDuration(
82  const double _duration, const int _index) final;
83 
86  public: virtual void SetDuration(const double _duration) final;
87 
91  public: virtual void SetInterval(
92  const double _interval, const int _index) final;
93 
96  public: virtual void SetInterval(const double _interval) final;
97 
101  public: virtual void SetColor(
102  const ignition::math::Color &_color, const int _index) final;
103 
106  public: virtual void SetColor(const ignition::math::Color &_color) final;
107 
110  public: virtual unsigned int BlockCount() final;
111 
115  public: virtual bool RemoveBlock(const int _index) final;
116 
124  public: virtual void InsertBlock(
125  const double _duration, const double _interval,
126  const ignition::math::Color &_color, const int _index) final;
127 
131  protected: virtual void Flash();
132 
136  protected: virtual void Dim();
137 
142  protected: virtual ignition::math::Color CurrentColor() final;
143 
145  private: std::unique_ptr<FlashLightSettingPrivate> dataPtr;
146  };
147 
148 
149  // forward declaration
150  class FlashLightPluginPrivate;
151 
229  class GZ_PLUGIN_VISIBLE FlashLightPlugin : public ModelPlugin
230  {
232  public: FlashLightPlugin();
233 
235  public: virtual ~FlashLightPlugin();
236 
237  // Documentation inherited.
238  public: void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf) override;
239 
241  protected: virtual void OnUpdate();
242 
248  protected: virtual bool TurnOn(const std::string &_lightName) final;
249 
254  protected: virtual bool TurnOn(
255  const std::string &_lightName, const std::string &_linkName) final;
256 
259  protected: virtual bool TurnOnAll() final;
260 
266  protected: virtual bool TurnOff(const std::string &_lightName) final;
267 
272  protected: virtual bool TurnOff(
273  const std::string &_lightName, const std::string &_linkName) final;
274 
277  protected: virtual bool TurnOffAll() final;
278 
286  protected: virtual bool ChangeDuration(
287  const std::string &_lightName, const std::string &_linkName,
288  const double _duration, const int _index) final;
289 
295  protected: virtual bool ChangeDuration(
296  const std::string &_lightName, const std::string &_linkName,
297  const double _duration) final;
298 
306  protected: virtual bool ChangeInterval(
307  const std::string &_lightName, const std::string &_linkName,
308  const double _interval, const int _index) final;
309 
315  protected: virtual bool ChangeInterval(
316  const std::string &_lightName, const std::string &_linkName,
317  const double _interval) final;
318 
326  protected: virtual bool ChangeColor(
327  const std::string &_lightName, const std::string &_linkName,
328  const ignition::math::Color &_color, const int _index) final;
329 
335  protected: virtual bool ChangeColor(
336  const std::string &_lightName, const std::string &_linkName,
337  const ignition::math::Color &_color) final;
338 
350  protected: virtual std::shared_ptr<FlashLightSetting> CreateSetting(
351  const sdf::ElementPtr &_sdf,
352  const physics::ModelPtr &_model,
353  const common::Time &_currentTime);
354 
364  protected:
365  virtual void InitSettingBySpecificData(
366  std::shared_ptr<FlashLightSetting> &_setting);
367 
369  private: std::unique_ptr<FlashLightPluginPrivate> dataPtr;
370  };
371 }
372 #endif
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:109
Forward declarations for the common classes.
Definition: Animation.hh:26
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
Internal data class to hold individual flash light settings.
Definition: FlashLightPlugin.hh:38
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:93
A plugin that blinks a light component in the model.
Definition: FlashLightPlugin.hh:229
A plugin with access to physics::Model.
Definition: Plugin.hh:305
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44