25#include <ignition/math/Color.hh>
27#include <gazebo/common/Plugin.hh>
28#include <gazebo/msgs/msgs.hh>
29#include <gazebo/physics/physics.hh>
30#include <gazebo/transport/transport.hh>
54 public: msgs::Visual
msg;
63 public: gazebo::transport::NodePtr
node;
70using namespace gazebo;
76 const sdf::ElementPtr &_sdf,
77 const gazebo::physics::ModelPtr &_model,
78 const gazebo::common::Time &_currentTime,
79 gazebo_ros::Node::SharedPtr rosnode)
84 this->
dataPtr->visualExists =
false;
86 this->
Link()->FillMsg(msg);
87 for (
auto visualMsg : msg.visual())
90 == this->Link()->GetScopedName() +
"::" + this->Name())
92 if (visualMsg.has_transparency())
94 this->
dataPtr->transparency = visualMsg.transparency();
97 if (visualMsg.has_material()
98 && visualMsg.material().has_emissive())
100 this->
dataPtr->defaultEmissiveColor
101 = msgs::Convert(visualMsg.material().emissive());
104 this->
dataPtr->visualExists =
true;
119 this->
dataPtr->pubVisual = _pubVisual;
121 if (this->
dataPtr->visualExists)
125 this->
Link()->GetScopedName() +
"::" + this->
Name());
126 this->
dataPtr->msg.set_parent_name(this->
Link()->GetScopedName());
128 this->
Link()->VisualId(this->
Name(),
id);
140 this->
dataPtr->msg.set_transparency(0.0);
142 if (color != ignition::math::Color::Black)
146 msgs::Set(this->
dataPtr->msg.mutable_material()->mutable_diffuse(), color);
147 msgs::Set(this->
dataPtr->msg.mutable_material()->mutable_emissive(), color);
148 msgs::Set(this->
dataPtr->msg.mutable_material()->mutable_specular(), color);
149 msgs::Set(this->
dataPtr->msg.mutable_material()->mutable_ambient(), color);
154 msgs::Set(this->
dataPtr->msg.mutable_material()->mutable_emissive(),
155 this->dataPtr->defaultEmissiveColor);
159 if (this->
dataPtr->visualExists)
168 if (this->
Link()->GetWorld()->SimTime() > 2.0)
181 msgs::Set(this->
dataPtr->msg.mutable_material()->mutable_emissive(),
182 ignition::math::Color(0, 0, 0));
184 if (this->
dataPtr->visualExists)
193 if (this->
Link()->GetWorld()->SimTime() > 2.0)
202 this->
dataPtr->node = gazebo::transport::NodePtr(
new gazebo::transport::Node());
207 = this->
dataPtr->node->Advertise<gazebo::msgs::Visual>(
"~/visual");
220 const sdf::ElementPtr &_sdf,
221 const gazebo::physics::ModelPtr &_model,
222 const gazebo::common::Time &_currentTime,
223 gazebo_ros::Node::SharedPtr node)
225 return std::make_shared<LedSetting>(_sdf, _model, _currentTime, node);
230 std::shared_ptr<FlashLightSetting> &_setting)
235 std::dynamic_pointer_cast<LedSetting>(_setting)->InitPubVisual(
virtual void InitSettingBySpecificData(std::shared_ptr< FlashLightSetting > &_setting)
Initialize the additional part of an object of setting.
Internal data class to hold individual flash light settings. A setting for each flash light is separa...
virtual const std::string Name() const final
Getter of name.
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 Flash()
Flash the light This function is internally used to update the light in the environment.
gazebo::transport::PublisherPtr pubVisual
The pointer to publisher to send a command to the visual.
gazebo::transport::NodePtr node
The pointer to node for communication.
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 ~LedPlugin()
Destructor.
std::unique_ptr< LedPluginPrivate > dataPtr
Pointer to private data.
virtual void InitSettingBySpecificData(std::shared_ptr< FlashLightSetting > &_setting)
Initialize the additional part of an object of setting.
double transparency
The transparency when the light is off.
msgs::Visual msg
A message holding a Visual message.
bool visualExists
True if <visual> element exists.
gazebo::transport::PublisherPtr pubVisual
The pointer to publisher to send a command to update a visual.
ignition::math::Color defaultEmissiveColor
The emissive color.
LedSettingPrivate()
Constructor.
LedSetting(const sdf::ElementPtr &_sdf, const gazebo::physics::ModelPtr &_model, const gazebo::common::Time &_currentTime, gazebo_ros::Node::SharedPtr rosnode)
Constructor.
virtual void Dim()
Dim the light This function is internally used to update the light in the environment.
virtual void InitPubVisual(const gazebo::transport::PublisherPtr &_pubVisual) final
Set the publisher and send an initial visual command.
std::unique_ptr< LedSettingPrivate > dataPtr
Pointer to private data.
virtual void Flash()
Flash the light This function is internally used to update the light in the environment.
virtual ~LedSetting()
Destructor.