FlashLightPlugin Class Reference

A plugin that blinks a light component in the model. More...

#include <FlashLightPlugin.hh>

Inherits ModelPlugin.

Inherited by LedPlugin.

Public Types

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

Public Member Functions

 FlashLightPlugin ()
 Constructor. More...
 
virtual ~FlashLightPlugin ()
 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 a light component in the model.

This plugin accesses <light> elements in the model specified by <light> as a parameter. More than one <light> can exist.

NOTE: This base class provides basic functions to control the lights. Users can create their own flash light plugin by inheriting this base model plugin.

A light is specified by <id>, including link and light names separated by a slash "/".

<enable> is optional. The default value is true. When it is set to true, a light starts flashing from the beginning. If <enable> is directly under the <plugin>, it affects all the lights. If it is under <light>, it individually affects the corresponding light. When it is set to false, the light is off, and it is necessary to call TurnOn() or TurnOnAll() in an inherited class to enable the light. A locally placed <enable> has a higher priority than the global one so specific lights can be turned on while the others are all off, and vice versa.

<duration> and <interval> specify the time to flash and dim in seconds, respectively. That is, the phase is determined as the sum of them: duration + interval.

<color> is optional. It specifies the color of light. If it is not given, the original color of the <light> element in the model will be used.

<block> is optional. It specifies a single phase. By adding multiple <block> elements, the light can generate a specific sequence of light patterns with different colors. It must have <duration> and <interval>. It can have <color> to specify the color of light. If <color> is not given, it will be set to the same color as that of the previous block. The first two elements are in the same format described above. <color> has three values representing RGB values.

Example (single color):

/// <enable>true</enable>
/// <light>
///  <id>link1/light_source</id>
///  <duration>0.1</duration>
///  <interval>0.4</interval>
///  <enable>true</enable>
/// </light>
/// <light>
///  <id>link1/light_source2</id>
///  <duration>0.8</duration>
///  <interval>0.2</interval>
///  <enable>false</enable>
/// </light>
/// ...
/// 
Example (multiple colors by <block> elements):
/// <enable>true</enable>
///
/// <light>
///   <id>link1/light_source</id>
///   <block>
///     <duration>0.6</duration>
///     <interval>0</interval>
///     <color>1 0 0</color>
///   </block>
///   <block>
///     <duration>0.2</duration>
///     <interval>0.5</interval>
///     <color>0 1 0</color>
///   </block>
///   <enable>true</enable>
/// </light>
///
/// ...
/// 

Member Typedef Documentation

◆ TPtr

typedef boost::shared_ptr<ModelPlugin > TPtr
inherited

plugin pointer type definition

Constructor & Destructor Documentation

◆ FlashLightPlugin()

Constructor.

◆ ~FlashLightPlugin()

virtual ~FlashLightPlugin ( )
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 
)
finalprotectedvirtual

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 
)
finalprotectedvirtual

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 
)
finalprotectedvirtual

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 
)
finalprotectedvirtual

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 
)
finalprotectedvirtual

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 
)
finalprotectedvirtual

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 in LedPlugin.

◆ 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()

virtual void Init ( )
inlinevirtualinherited

◆ 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 in LedPlugin.

◆ Load()

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

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 ( )
protectedvirtual

Called by the world update start event.

◆ Reset()

virtual void Reset ( )
inlinevirtualinherited

Override this method for custom plugin reset behavior.

Reimplemented in KeysToCmdVelPlugin, RandomVelocityPlugin, ElevatorPlugin, FollowerPlugin, LinearBatteryPlugin, ActorPlugin, InitialVelocityPlugin, and SphereAtlasDemoPlugin.

◆ TurnOff() [1/2]

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

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 
)
finalprotectedvirtual

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 ( )
finalprotectedvirtual

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)
finalprotectedvirtual

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 
)
finalprotectedvirtual

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 ( )
finalprotectedvirtual

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: