SMACC2
FlashLightPlugin.hh
Go to the documentation of this file.
1// Copyright 2021 RobosoftAI Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/*****************************************************************************************************************
16 *
17 * Authors: Pablo Inigo Blasco, Brett Aldrich
18 *
19 ******************************************************************************************************************/
20
21
22#ifndef GAZEBO_SMACC_PLUGINS_FLASHLIGHTPLUGIN_HH_
23#define GAZEBO_SMACC_PLUGINS_FLASHLIGHTPLUGIN_HH_
24
25#include <memory>
26#include <string>
27
28#include <ignition/math/Color.hh>
29
30#include <gazebo/common/Plugin.hh>
31#include <gazebo/physics/physics.hh>
32#include <gazebo_ros/node.hpp>
33#include <std_msgs/msg/int8.hpp>
34#include <rclcpp/rclcpp.hpp>
35
36
37namespace smacc2
38{
39 using namespace gazebo;
40
41 // forward declaration
42 class FlashLightSettingPrivate;
43
49 {
55 public: FlashLightSetting(
56 const sdf::ElementPtr &_sdf,
57 const gazebo::physics::ModelPtr &_model,
58 const gazebo::common::Time &_currentTime,
59 gazebo_ros::Node::SharedPtr node);
60
62 public: virtual ~FlashLightSetting();
63
66 public: virtual void InitPubLight(
67 const gazebo::transport::PublisherPtr &_pubLight) final;
68
72 public:
73 virtual void UpdateLightInEnv(const gazebo::common::Time &_currentTime) final;
74
77 public: virtual const std::string Name() const final;
78
81 public: virtual const gazebo::physics::LinkPtr Link() const final;
82
84 public: virtual void SwitchOn() final;
85
87 public: virtual void SwitchOff() final;
88
92 public: virtual void SetDuration(
93 const double _duration, const int _index) final;
94
97 public: virtual void SetDuration(const double _duration) final;
98
102 public: virtual void SetInterval(
103 const double _interval, const int _index) final;
104
107 public: virtual void SetInterval(const double _interval) final;
108
112 public: virtual void SetColor(
113 const ignition::math::Color &_color, const int _index) final;
114
117 public: virtual void SetColor(const ignition::math::Color &_color) final;
118
121 public: virtual unsigned int BlockCount() final;
122
126 public: virtual bool RemoveBlock(const int _index) final;
127
135 public: virtual void InsertBlock(
136 const double _duration, const double _interval,
137 const ignition::math::Color &_color, const int _index) final;
138
142 protected: virtual void Flash();
143
147 protected: virtual void Dim();
148
153 protected: virtual ignition::math::Color CurrentColor() final;
154
156 private: std::unique_ptr<FlashLightSettingPrivate> dataPtr;
157
158 };
159
160
161 // forward declaration
163
164 class FlashLightPlugin : public gazebo::ModelPlugin
165 {
167 public: FlashLightPlugin();
168
170 public: virtual ~FlashLightPlugin();
171
172 // Documentation inherited.
173 public: void Load(gazebo::physics::ModelPtr _parent, sdf::ElementPtr _sdf) override;
174
176 protected: virtual void OnUpdate();
177
183 protected: virtual bool TurnOn(const std::string &_lightName) final;
184
189 protected: virtual bool TurnOn(
190 const std::string &_lightName, const std::string &_linkName) final;
191
194 protected: virtual bool TurnOnAll() final;
195
201 protected: virtual bool TurnOff(const std::string &_lightName) final;
202
207 protected: virtual bool TurnOff(
208 const std::string &_lightName, const std::string &_linkName) final;
209
212 protected: virtual bool TurnOffAll() final;
213
221 protected: virtual bool ChangeDuration(
222 const std::string &_lightName, const std::string &_linkName,
223 const double _duration, const int _index) final;
224
230 protected: virtual bool ChangeDuration(
231 const std::string &_lightName, const std::string &_linkName,
232 const double _duration) final;
233
241 protected: virtual bool ChangeInterval(
242 const std::string &_lightName, const std::string &_linkName,
243 const double _interval, const int _index) final;
244
250 protected: virtual bool ChangeInterval(
251 const std::string &_lightName, const std::string &_linkName,
252 const double _interval) final;
253
261 protected: virtual bool ChangeColor(
262 const std::string &_lightName, const std::string &_linkName,
263 const ignition::math::Color &_color, const int _index) final;
264
270 protected: virtual bool ChangeColor(
271 const std::string &_lightName, const std::string &_linkName,
272 const ignition::math::Color &_color) final;
273
285 protected: virtual std::shared_ptr<FlashLightSetting> CreateSetting(
286 const sdf::ElementPtr &_sdf,
287 const gazebo::physics::ModelPtr &_model,
288 const gazebo::common::Time &_currentTime,
289 gazebo_ros::Node::SharedPtr node);
290
300 protected:
301 virtual void InitSettingBySpecificData(
302 std::shared_ptr<FlashLightSetting> &_setting);
303
305 private: std::unique_ptr<FlashLightPluginPrivate> dataPtr;
306
307 rclcpp::Subscription<std_msgs::msg::Int8>::SharedPtr cmdledsubscription;
308
309 };
310}
311#endif
virtual bool TurnOffAll() final
Turn off all flash lights.
virtual ~FlashLightPlugin()
Destructor.
rclcpp::Subscription< std_msgs::msg::Int8 >::SharedPtr cmdledsubscription
virtual bool TurnOnAll() final
Turn on all flash lights.
void Load(gazebo::physics::ModelPtr _parent, sdf::ElementPtr _sdf) override
virtual void OnUpdate()
Called by the world update start event.
virtual bool ChangeColor(const std::string &_lightName, const std::string &_linkName, const ignition::math::Color &_color, const int _index) final
Change the color of a specific block of the flashlight. If the index is a negative number,...
virtual bool TurnOn(const std::string &_lightName) final
Turn on a flash light specified by the light name If more than one link have lights with the identica...
virtual bool TurnOff(const std::string &_lightName) final
Turn off a flash light specified by the name If more than one link have lights with the identical nam...
std::unique_ptr< FlashLightPluginPrivate > dataPtr
Pointer to private data.
virtual void InitSettingBySpecificData(std::shared_ptr< FlashLightSetting > &_setting)
Initialize the additional part of an object of setting.
virtual std::shared_ptr< FlashLightSetting > CreateSetting(const sdf::ElementPtr &_sdf, const gazebo::physics::ModelPtr &_model, const gazebo::common::Time &_currentTime, gazebo_ros::Node::SharedPtr node)
Create an object of setting.
virtual bool ChangeInterval(const std::string &_lightName, const std::string &_linkName, const double _interval, const int _index) final
Change the interval of a specific block of the flashlight. If the index is a negative number,...
virtual bool ChangeDuration(const std::string &_lightName, const std::string &_linkName, const double _duration, const int _index) final
Change the duration of a specific block of the flashlight. If the index is a negative number,...
Internal data class to hold individual flash light settings. A setting for each flash light is separa...
virtual void SetDuration(const double _duration, const int _index) final
Set the duration time for the specified block.
virtual void InitPubLight(const gazebo::transport::PublisherPtr &_pubLight) final
Set the publisher and send an initial light command.
virtual unsigned int BlockCount() final
Get the number of blocks.
virtual void UpdateLightInEnv(const gazebo::common::Time &_currentTime) final
Update the light based on the given time.
std::unique_ptr< FlashLightSettingPrivate > dataPtr
Pointer to private data.
virtual void InsertBlock(const double _duration, const double _interval, const ignition::math::Color &_color, const int _index) final
Insert a block. Create a block with specified parameters. If the index is out of range,...
virtual const std::string Name() const final
Getter of name.
virtual void SwitchOn() final
Switch on (enable the flashlight).
virtual void Dim()
Dim the light This function is internally used to update the light in the environment.
virtual const gazebo::physics::LinkPtr Link() const final
Getter of link.
virtual ignition::math::Color CurrentColor() final
Get the current color of the light. This is to be used by an inheriting class of FlashLightSetting cl...
virtual void SetInterval(const double _interval, const int _index) final
Set the interval time for the specified block.
virtual void Flash()
Flash the light This function is internally used to update the light in the environment.
virtual void SwitchOff() final
Switch off (disable the flashlight).
virtual ~FlashLightSetting()
Destructor.
virtual void SetColor(const ignition::math::Color &_color, const int _index) final
Set the color for the specified block.
FlashLightSetting(const sdf::ElementPtr &_sdf, const gazebo::physics::ModelPtr &_model, const gazebo::common::Time &_currentTime, gazebo_ros::Node::SharedPtr node)
Constructor. Initialize the setting by the data given to the base plugin.
virtual bool RemoveBlock(const int _index) final
Remove a specified block.