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

A plugin that blinks light and visual elements in a model. In addition to the features of the base plugin, FlashLightPlugin, this plugin accesses a <visual> element to make it blink. More...

#include <LedPlugin.hh>

Inheritance diagram for smacc2::LedPlugin:
Inheritance graph
Collaboration diagram for smacc2::LedPlugin:
Collaboration graph

Public Member Functions

 LedPlugin ()
 Constructor. More...
 
virtual ~LedPlugin ()
 Destructor. More...
 
- Public Member Functions inherited from smacc2::FlashLightPlugin
 FlashLightPlugin ()
 Constructor. More...
 
virtual ~FlashLightPlugin ()
 Destructor. More...
 
void Load (gazebo::physics::ModelPtr _parent, sdf::ElementPtr _sdf) override
 

Protected Member Functions

virtual std::shared_ptr< FlashLightSettingCreateSetting (const sdf::ElementPtr &_sdf, const gazebo::physics::ModelPtr &_model, const gazebo::common::Time &_currentTime, gazebo_ros::Node::SharedPtr node)
 Create an object of setting. More...
 
virtual void InitSettingBySpecificData (std::shared_ptr< FlashLightSetting > &_setting)
 Initialize the additional part of an object of setting. More...
 
- Protected Member Functions inherited from smacc2::FlashLightPlugin
virtual void OnUpdate ()
 Called by the world update start event. More...
 
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 identical name, the first appearing light in the list will be updated. More...
 
virtual bool TurnOn (const std::string &_lightName, const std::string &_linkName) final
 Turn on a flash light specified by the name and its link. More...
 
virtual bool TurnOnAll () final
 Turn on all flash lights. More...
 
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 name, the first appearing light in the list will be updated. More...
 
virtual bool TurnOff (const std::string &_lightName, const std::string &_linkName) final
 Turn off a flash light specified by the name. More...
 
virtual bool TurnOffAll () final
 Turn off all flash lights. More...
 
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, it updates all the blocks. More...
 
virtual bool ChangeDuration (const std::string &_lightName, const std::string &_linkName, const double _duration) final
 Change the duration of all the blocks of the flashlight. More...
 
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, it updates all the blocks. More...
 
virtual bool ChangeInterval (const std::string &_lightName, const std::string &_linkName, const double _interval) final
 Change the interval of all the blocks of the flashlight. More...
 
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, it updates all the blocks. More...
 
virtual bool ChangeColor (const std::string &_lightName, const std::string &_linkName, const ignition::math::Color &_color) final
 Change the color of all the blocks of the flashlight. More...
 
virtual std::shared_ptr< FlashLightSettingCreateSetting (const sdf::ElementPtr &_sdf, const gazebo::physics::ModelPtr &_model, const gazebo::common::Time &_currentTime, gazebo_ros::Node::SharedPtr node)
 Create an object of setting. More...
 
virtual void InitSettingBySpecificData (std::shared_ptr< FlashLightSetting > &_setting)
 Initialize the additional part of an object of setting. More...
 

Private Attributes

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

Detailed Description

A plugin that blinks light and visual elements in a model. In addition to the features of the base plugin, FlashLightPlugin, this plugin accesses a <visual> element to make it blink.

The <light> and <visual> element to control must have the identical name and specified by <light_id>, including the name of the link, which they are attached on, and their name separated by a slash "/".

Other parameters are inherited from the base plugin, FlashLightPlugin.

Example:

/// <model name='light_model'>
///   ...
///   <link name='light_source'>
///     ...
///     <light name='lamp' type='point'>
///       ...
///     </light>
///     <visual name='lamp'>
///       ...
///     </visual>
///   </link>
///   ...
///   <plugin name='light_control' filename='libLedPlugin.so'>
///     <light>
///       <id>light_source/lamp</id>
///       <block>
///         <duration>1</duration>
///         <interval>1</interval>
///         <color>1 0.5 0.5</color>
///       </block>
///       <enable>true</enable>
///     </light>
///   </plugin>
/// </model>
/// 

Definition at line 106 of file LedPlugin.hh.

Constructor & Destructor Documentation

◆ LedPlugin()

smacc2::LedPlugin::LedPlugin ( )

Constructor.

Definition at line 199 of file LedPlugin.cc.

199 : FlashLightPlugin(), dataPtr(new LedPluginPrivate)
200{
201 // Create a node
202 this->dataPtr->node = gazebo::transport::NodePtr(new gazebo::transport::Node());
203 this->dataPtr->node->Init();
204
205 // Advertise the topic to update lights
206 this->dataPtr->pubVisual
207 = this->dataPtr->node->Advertise<gazebo::msgs::Visual>("~/visual");
208 // NOTE: it should not call WaitForConnection() since there could be no
209 // subscriber to "~/visual" topic if the render engine is not running (e.g.,
210 // rostest), leading to a hang-up.
211}
std::unique_ptr< LedPluginPrivate > dataPtr
Pointer to private data.
Definition: LedPlugin.hh:126

References dataPtr.

◆ ~LedPlugin()

smacc2::LedPlugin::~LedPlugin ( )
virtual

Destructor.

Definition at line 214 of file LedPlugin.cc.

215{
216}

Member Function Documentation

◆ CreateSetting()

std::shared_ptr< FlashLightSetting > smacc2::LedPlugin::CreateSetting ( const sdf::ElementPtr &  _sdf,
const gazebo::physics::ModelPtr &  _model,
const gazebo::common::Time &  _currentTime,
gazebo_ros::Node::SharedPtr  node 
)
protectedvirtual

Create an object of setting.

NOTE: This function is internally called in Load() of the base class. If a child class of FlashLightPlugin has also an inherited class of FlashLightSetting, this function must be overridden so that dataPtr deals with objects of the appropriate setting class.

Parameters
[in]_sdfSDF data for the setting.
[in]_modelThe Model pointer holding the light to control.
[in]_currentTimeThe current time point.
Returns
A pointer to the newly created setting object.

Reimplemented from smacc2::FlashLightPlugin.

Definition at line 219 of file LedPlugin.cc.

224{
225 return std::make_shared<LedSetting>(_sdf, _model, _currentTime, node);
226}

◆ InitSettingBySpecificData()

void smacc2::LedPlugin::InitSettingBySpecificData ( std::shared_ptr< FlashLightSetting > &  _setting)
protectedvirtual

Initialize the additional part of an object of setting.

NOTE: This function is internally called in Load() of the base class. If a child class of FlashLightPlugin has also an inherited class of FlashLightSetting, this function must be overridden so that the object can be initialized with necessary data. Also, the overridden function must call the original function in it.

Parameters
[in]_settingA pointer to the setting object.

Reimplemented from smacc2::FlashLightPlugin.

Definition at line 229 of file LedPlugin.cc.

231{
232 // Call the function of the parent class.
234
235 std::dynamic_pointer_cast<LedSetting>(_setting)->InitPubVisual(
236 this->dataPtr->pubVisual);
237}
virtual void InitSettingBySpecificData(std::shared_ptr< FlashLightSetting > &_setting)
Initialize the additional part of an object of setting.

References dataPtr, and smacc2::FlashLightPlugin::InitSettingBySpecificData().

Here is the call graph for this function:

Member Data Documentation

◆ dataPtr

std::unique_ptr<LedPluginPrivate> smacc2::LedPlugin::dataPtr
private

Pointer to private data.

Definition at line 126 of file LedPlugin.hh.

Referenced by InitSettingBySpecificData(), and LedPlugin().


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