SMACC2
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
smacc2::LedSetting Class Reference

Internal data class to hold individual LED light settings. More...

#include <LedPlugin.hh>

Inheritance diagram for smacc2::LedSetting:
Inheritance graph
Collaboration diagram for smacc2::LedSetting:
Collaboration graph

Public Member Functions

 LedSetting (const sdf::ElementPtr &_sdf, const gazebo::physics::ModelPtr &_model, const gazebo::common::Time &_currentTime, gazebo_ros::Node::SharedPtr rosnode)
 Constructor. More...
 
virtual ~LedSetting ()
 Destructor. More...
 
virtual void InitPubVisual (const gazebo::transport::PublisherPtr &_pubVisual) final
 Set the publisher and send an initial visual command. More...
 
- Public Member Functions inherited from smacc2::FlashLightSetting
 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. More...
 
virtual ~FlashLightSetting ()
 Destructor. More...
 
virtual void InitPubLight (const gazebo::transport::PublisherPtr &_pubLight) final
 Set the publisher and send an initial light command. More...
 
virtual void UpdateLightInEnv (const gazebo::common::Time &_currentTime) final
 Update the light based on the given time. More...
 
virtual const std::string Name () const final
 Getter of name. More...
 
virtual const gazebo::physics::LinkPtr Link () const final
 Getter of link. More...
 
virtual void SwitchOn () final
 Switch on (enable the flashlight). More...
 
virtual void SwitchOff () final
 Switch off (disable the flashlight). More...
 
virtual void SetDuration (const double _duration, const int _index) final
 Set the duration time for the specified block. More...
 
virtual void SetDuration (const double _duration) final
 Set the duration time for all the blocks. More...
 
virtual void SetInterval (const double _interval, const int _index) final
 Set the interval time for the specified block. More...
 
virtual void SetInterval (const double _interval) final
 Set the interval time for all the blocks. More...
 
virtual void SetColor (const ignition::math::Color &_color, const int _index) final
 Set the color for the specified block. More...
 
virtual void SetColor (const ignition::math::Color &_color) final
 Set the color for all the blocks. More...
 
virtual unsigned int BlockCount () final
 Get the number of blocks. More...
 
virtual bool RemoveBlock (const int _index) final
 Remove a specified block. More...
 
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, the block will be appended at the end of the list. More...
 

Protected Member Functions

virtual void Flash ()
 Flash the light This function is internally used to update the light in the environment. More...
 
virtual void Dim ()
 Dim the light This function is internally used to update the light in the environment. More...
 
- Protected Member Functions inherited from smacc2::FlashLightSetting
virtual void Flash ()
 Flash the light This function is internally used to update the light in the environment. More...
 
virtual void Dim ()
 Dim the light This function is internally used to update the light in the environment. More...
 
virtual ignition::math::Color CurrentColor () final
 Get the current color of the light. This is to be used by an inheriting class of FlashLightSetting class. More...
 

Private Attributes

std::unique_ptr< LedSettingPrivatedataPtr
 Pointer to private data. More...
 

Detailed Description

Internal data class to hold individual LED light settings.

Definition at line 38 of file LedPlugin.hh.

Constructor & Destructor Documentation

◆ LedSetting()

smacc2::LedSetting::LedSetting ( const sdf::ElementPtr &  _sdf,
const gazebo::physics::ModelPtr &  _model,
const gazebo::common::Time &  _currentTime,
gazebo_ros::Node::SharedPtr  rosnode 
)

Constructor.

Definition at line 75 of file LedPlugin.cc.

80 : FlashLightSetting(_sdf, _model, _currentTime, rosnode),
81 dataPtr(new LedSettingPrivate)
82{
83 // check if the visual element exists.
84 this->dataPtr->visualExists = false;
85 msgs::Link msg;
86 this->Link()->FillMsg(msg);
87 for (auto visualMsg : msg.visual())
88 {
89 if (visualMsg.name()
90 == this->Link()->GetScopedName() + "::" + this->Name())
91 {
92 if (visualMsg.has_transparency())
93 {
94 this->dataPtr->transparency = visualMsg.transparency();
95 }
96
97 if (visualMsg.has_material()
98 && visualMsg.material().has_emissive())
99 {
100 this->dataPtr->defaultEmissiveColor
101 = msgs::Convert(visualMsg.material().emissive());
102 }
103
104 this->dataPtr->visualExists = true;
105 break;
106 }
107 }
108}
virtual const gazebo::physics::LinkPtr Link() const final
Getter of link.
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.
std::unique_ptr< LedSettingPrivate > dataPtr
Pointer to private data.
Definition: LedPlugin.hh:62

References dataPtr, and smacc2::FlashLightSetting::Link().

Here is the call graph for this function:

◆ ~LedSetting()

smacc2::LedSetting::~LedSetting ( )
virtual

Destructor.

Definition at line 111 of file LedPlugin.cc.

112{
113}

Member Function Documentation

◆ Dim()

void smacc2::LedSetting::Dim ( )
protectedvirtual

Dim the light This function is internally used to update the light in the environment.

Reimplemented from smacc2::FlashLightSetting.

Definition at line 174 of file LedPlugin.cc.

175{
176 // Call the function of the parent class.
178
179 // Make the appearance darker.
180 this->dataPtr->msg.set_transparency(this->dataPtr->transparency);
181 msgs::Set(this->dataPtr->msg.mutable_material()->mutable_emissive(),
182 ignition::math::Color(0, 0, 0));
183 // Send the message.
184 if (this->dataPtr->visualExists)
185 {
186 // NOTE: this if statement is to make sure that a visual object to update
187 // has been created in the environment before publishing a message.
188 // Otherwise, a duplicate object will be created and the original one will
189 // never be updated.
190 // This problem is solved by the patch (Pull Request # 2983), which has
191 // been merged into gazebo7 as of July 16, 2018. This if statement should be
192 // removed once the patch is forwarded up to gazebo9.
193 if (this->Link()->GetWorld()->SimTime() > 2.0)
194 this->dataPtr->pubVisual->Publish(this->dataPtr->msg);
195 }
196}
virtual void Dim()
Dim the light This function is internally used to update the light in the environment.

References dataPtr, smacc2::FlashLightSetting::Dim(), and smacc2::FlashLightSetting::Link().

Here is the call graph for this function:

◆ Flash()

void smacc2::LedSetting::Flash ( )
protectedvirtual

Flash the light This function is internally used to update the light in the environment.

Reimplemented from smacc2::FlashLightSetting.

Definition at line 134 of file LedPlugin.cc.

135{
136 // Call the function of the parent class.
138
139 // Make the appearance brighter.
140 this->dataPtr->msg.set_transparency(0.0);
141 ignition::math::Color color = this->CurrentColor();
142 if (color != ignition::math::Color::Black)
143 {
144 // If the base class is using a specific color rather than the default,
145 // apply it to the visual object.
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);
150 }
151 else
152 {
153 // Otherwise, just apply the default color.
154 msgs::Set(this->dataPtr->msg.mutable_material()->mutable_emissive(),
155 this->dataPtr->defaultEmissiveColor);
156 }
157
158 // Send the message.
159 if (this->dataPtr->visualExists)
160 {
161 // NOTE: this if statement is to make sure that a visual object to update
162 // has been created in the environment before publishing a message.
163 // Otherwise, a duplicate object will be created and the original one will
164 // never be updated.
165 // This problem is solved by the patch (Pull Request # 2983), which has
166 // been merged into gazebo7 as of July 16, 2018. This if statement should be
167 // removed once the patch is forwarded up to gazebo9.
168 if (this->Link()->GetWorld()->SimTime() > 2.0)
169 this->dataPtr->pubVisual->Publish(this->dataPtr->msg);
170 }
171}
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.

References smacc2::FlashLightSetting::CurrentColor(), dataPtr, smacc2::FlashLightSetting::Flash(), and smacc2::FlashLightSetting::Link().

Here is the call graph for this function:

◆ InitPubVisual()

void smacc2::LedSetting::InitPubVisual ( const gazebo::transport::PublisherPtr &  _pubVisual)
finalvirtual

Set the publisher and send an initial visual command.

Parameters
[in]_pubVisualThe publisher to send a message

Definition at line 116 of file LedPlugin.cc.

117{
118 // The PublisherPtr
119 this->dataPtr->pubVisual = _pubVisual;
120
121 if (this->dataPtr->visualExists)
122 {
123 // Make a message
124 this->dataPtr->msg.set_name(
125 this->Link()->GetScopedName() + "::" + this->Name());
126 this->dataPtr->msg.set_parent_name(this->Link()->GetScopedName());
127 uint32_t id;
128 this->Link()->VisualId(this->Name(), id);
129 this->dataPtr->msg.set_id(id);
130 }
131}
virtual const std::string Name() const final
Getter of name.

References dataPtr, smacc2::FlashLightSetting::Link(), and smacc2::FlashLightSetting::Name().

Here is the call graph for this function:

Member Data Documentation

◆ dataPtr

std::unique_ptr<LedSettingPrivate> smacc2::LedSetting::dataPtr
private

Pointer to private data.

Definition at line 62 of file LedPlugin.hh.

Referenced by Dim(), Flash(), InitPubVisual(), and LedSetting().


The documentation for this class was generated from the following files: