LedPlugin Class Reference

A plugin that blinks light and visual elements in a model. More...

#include <LedPlugin.hh>

Inherits FlashLightPlugin.

Public Types

typedef boost::shared_ptr< ModelPluginTPtr
 plugin pointer type definition More...
 

Public Member Functions

 LedPlugin ()
 Constructor. More...
 
virtual ~LedPlugin ()
 Destructor. More...
 
std::string GetFilename () const
 Get the name of the handler. More...
 
std::string GetHandle () const
 Get the short name of the handler. More...
 
PluginType GetType () const
 Returns the type of the plugin. More...
 
virtual void Init ()
 Override this method for custom plugin initialization behavior. More...
 
void Load (physics::ModelPtr _parent, sdf::ElementPtr _sdf) override
 Load function. More...
 
virtual void Reset ()
 Override this method for custom plugin reset behavior. More...
 

Static Public Member Functions

static TPtr Create (const std::string &_filename, const std::string &_name)
 a class method that creates a plugin from a file name. More...
 

Protected Member Functions

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. 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 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. 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. 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 std::shared_ptr< FlashLightSettingCreateSetting (const sdf::ElementPtr &_sdf, const physics::ModelPtr &_model, const common::Time &_currentTime)
 Create an object of setting. More...
 
virtual void InitSettingBySpecificData (std::shared_ptr< FlashLightSetting > &_setting)
 Initialize the additional part of an object of setting. More...
 
void LoadParam (const sdf::ElementPtr &_sdf, const std::string &_name, V &_target, V _defaultValue=V()) const
 Load parameter value from _sdf and store it to the given reference, using the supplied default value if the element in _sdf is not found. More...
 
void LoadParam (sdf::ElementPtr &_sdf, const std::string &_name, std::string &_target, const char *_defaultValue) const
 Load parameter value from _sdf and store it to the given reference, using the supplied default value if the element in _sdf is not found. More...
 
virtual void OnUpdate ()
 Called by the world update start event. 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 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...
 

Protected Attributes

std::string filename
 Path to the shared library file. More...
 
std::string handleName
 Short name. More...
 
PluginType type
 Type of plugin. 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>
/// 

Member Typedef Documentation

◆ TPtr

typedef boost::shared_ptr<ModelPlugin > TPtr
inherited

plugin pointer type definition

Constructor & Destructor Documentation

◆ LedPlugin()

LedPlugin ( )

Constructor.

◆ ~LedPlugin()

virtual ~LedPlugin ( )
virtual

Destructor.

Member Function Documentation

◆ ChangeColor() [1/2]

virtual bool ChangeColor ( const std::string &  _lightName,
const std::string &  _linkName,
const ignition::math::Color &  _color,
const int  _index 
)
finalprotectedvirtualinherited

Change the color of a specific block of the flashlight.

If the index is a negative number, it updates all the blocks.

Parameters
[in]_lightNameThe name of flash light
[in]_linkNameThe name of the link holding the light
[in]_colorThe new color to set
[in]_indexThe index to the block to update
Returns
True if the specified light is found.

◆ ChangeColor() [2/2]

virtual bool ChangeColor ( const std::string &  _lightName,
const std::string &  _linkName,
const ignition::math::Color &  _color 
)
finalprotectedvirtualinherited

Change the color of all the blocks of the flashlight.

Parameters
[in]_lightNameThe name of flash light
[in]_linkNameThe name of the link holding the light
[in]_colorThe new color to set
Returns
True if the specified light is found.

◆ ChangeDuration() [1/2]

virtual bool ChangeDuration ( const std::string &  _lightName,
const std::string &  _linkName,
const double  _duration,
const int  _index 
)
finalprotectedvirtualinherited

Change the duration of a specific block of the flashlight.

If the index is a negative number, it updates all the blocks.

Parameters
[in]_lightNameThe name of flash light
[in]_linkNameThe name of the link holding the light
[in]_durationThe new duration time to set
[in]_indexThe index to the block to update
Returns
True if the specified light is found.

◆ ChangeDuration() [2/2]

virtual bool ChangeDuration ( const std::string &  _lightName,
const std::string &  _linkName,
const double  _duration 
)
finalprotectedvirtualinherited

Change the duration of all the blocks of the flashlight.

Parameters
[in]_lightNameThe name of flash light
[in]_linkNameThe name of the link holding the light
[in]_durationThe new duration time to set
Returns
True if the specified light is found.

◆ ChangeInterval() [1/2]

virtual bool ChangeInterval ( const std::string &  _lightName,
const std::string &  _linkName,
const double  _interval,
const int  _index 
)
finalprotectedvirtualinherited

Change the interval of a specific block of the flashlight.

If the index is a negative number, it updates all the blocks.

Parameters
[in]_lightNameThe name of flash light
[in]_linkNameThe name of the link holding the light
[in]_intervalThe new interval time to set
[in]_indexThe index to the block to update
Returns
True if the specified light is found.

◆ ChangeInterval() [2/2]

virtual bool ChangeInterval ( const std::string &  _lightName,
const std::string &  _linkName,
const double  _interval 
)
finalprotectedvirtualinherited

Change the interval of all the blocks of the flashlight.

Parameters
[in]_lightNameThe name of flash light
[in]_linkNameThe name of the link holding the light
[in]_intervalThe new interval time to set
Returns
True if the specified light is found.

◆ Create()

static TPtr Create ( const std::string &  _filename,
const std::string &  _name 
)
inlinestaticinherited

a class method that creates a plugin from a file name.

It locates the shared library and loads it dynamically.

Parameters
[in]_filenamethe path to the shared library.
[in]_nameshort name of the plugin
Returns
Shared Pointer to this class type

References PluginT< T >::filename, gzerr, and SingletonT< SystemPaths >::Instance().

◆ CreateSetting()

virtual std::shared_ptr<FlashLightSetting> CreateSetting ( const sdf::ElementPtr &  _sdf,
const physics::ModelPtr _model,
const common::Time _currentTime 
)
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 FlashLightPlugin.

◆ GetFilename()

std::string GetFilename ( ) const
inlineinherited

Get the name of the handler.

References PluginT< T >::filename.

◆ GetHandle()

std::string GetHandle ( ) const
inlineinherited

Get the short name of the handler.

References PluginT< T >::handleName.

◆ GetType()

PluginType GetType ( ) const
inlineinherited

Returns the type of the plugin.

Returns
type of the plugin

References PluginT< T >::type.

◆ Init()

◆ InitSettingBySpecificData()

virtual void 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 FlashLightPlugin.

◆ Load()

void Load ( physics::ModelPtr  _model,
sdf::ElementPtr  _sdf 
)
overridevirtualinherited

Load function.

Called when a Plugin is first created, and after the World has been loaded. This function should not be blocking.

Parameters
[in]_modelPointer to the Model
[in]_sdfPointer to the SDF element of the plugin.

Implements ModelPlugin.

◆ LoadParam() [1/2]

void LoadParam ( const sdf::ElementPtr &  _sdf,
const std::string &  _name,
V &  _target,
_defaultValue = V() 
) const
inlineprotectedinherited

Load parameter value from _sdf and store it to the given reference, using the supplied default value if the element in _sdf is not found.

A message is written using gzmsg reporting whether the default value was used or not.

Parameters
[in]_sdfThe SDF element of the plugin.
[in]_nameName of a tag inside the SDF.
[out]_targetThe reference to store the param value to.
[in]_defaultValueThe default value.

References gzmsg, and PluginT< T >::handleName.

◆ LoadParam() [2/2]

void LoadParam ( sdf::ElementPtr &  _sdf,
const std::string &  _name,
std::string &  _target,
const char *  _defaultValue 
) const
inlineprotectedinherited

Load parameter value from _sdf and store it to the given reference, using the supplied default value if the element in _sdf is not found.

A message is written using gzmsg reporting whether the default value was used or not. String specialization to allow accepting const char* values for std::string parameters.

Parameters
[in]_sdfThe SDF element of the plugin.
[in]_nameName of a tag inside the SDF.
[out]_targetThe reference to store the param value to.
[in]_defaultValueThe default value.

◆ OnUpdate()

virtual void OnUpdate ( )
protectedvirtualinherited

Called by the world update start event.

◆ Reset()

virtual void Reset ( )
inlinevirtualinherited

◆ TurnOff() [1/2]

virtual bool TurnOff ( const std::string &  _lightName)
finalprotectedvirtualinherited

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.

Parameters
[in]_lightNameThe name of flash light
Returns
True if the specified light is found.

◆ TurnOff() [2/2]

virtual bool TurnOff ( const std::string &  _lightName,
const std::string &  _linkName 
)
finalprotectedvirtualinherited

Turn off a flash light specified by the name.

Parameters
[in]_lightNameThe name of flash light
[in]_linkNameThe name of the link holding the light
Returns
True if the specified light is found.

◆ TurnOffAll()

virtual bool TurnOffAll ( )
finalprotectedvirtualinherited

Turn off all flash lights.

Returns
True if there is one or more lights to turn off.

◆ TurnOn() [1/2]

virtual bool TurnOn ( const std::string &  _lightName)
finalprotectedvirtualinherited

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.

Parameters
[in]_lightNameThe name of flash light
Returns
True if the specified light is found.

◆ TurnOn() [2/2]

virtual bool TurnOn ( const std::string &  _lightName,
const std::string &  _linkName 
)
finalprotectedvirtualinherited

Turn on a flash light specified by the name and its link.

Parameters
[in]_lightNameThe name of flash light
[in]_linkNameThe name of the link holding the light
Returns
True if the specified light is found.

◆ TurnOnAll()

virtual bool TurnOnAll ( )
finalprotectedvirtualinherited

Turn on all flash lights.

Returns
True if there is one or more lights to turn on.

Member Data Documentation

◆ filename

std::string filename
protectedinherited

Path to the shared library file.

◆ handleName

std::string handleName
protectedinherited

Short name.

◆ type

PluginType type
protectedinherited

Type of plugin.


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