##

FlashLightPlugin.hh
Go to the documentation of this file.
/*
* Copyright (C) 2018 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GAZEBO_PLUGINS_FLASHLIGHTPLUGIN_HH_
#define GAZEBO_PLUGINS_FLASHLIGHTPLUGIN_HH_
#include <memory>
#include <string>
#include <ignition/math/Color.hh>
#include "gazebo/common/Plugin.hh"
#include "gazebo/physics/physics.hh"
namespace gazebo
{
// forward declaration
class FlashLightSettingPrivate;
class GZ_PLUGIN_VISIBLE FlashLightSetting
{
public: FlashLightSetting(
const sdf::ElementPtr &_sdf,
const physics::ModelPtr &_model,
const common::Time &_currentTime);
public: virtual ~FlashLightSetting();
public: virtual void InitPubLight(
const transport::PublisherPtr &_pubLight) final;
public:
virtual void UpdateLightInEnv(const common::Time &_currentTime) final;
public: virtual const std::string Name() const final;
public: virtual const physics::LinkPtr Link() const final;
public: virtual void SwitchOn() final;
public: virtual void SwitchOff() final;
public: virtual void SetDuration(
const double _duration, const int _index) final;
public: virtual void SetDuration(const double _duration) final;
public: virtual void SetInterval(
const double _interval, const int _index) final;
public: virtual void SetInterval(const double _interval) final;
public: virtual void SetColor(
const ignition::math::Color &_color, const int _index) final;
public: virtual void SetColor(const ignition::math::Color &_color) final;
public: virtual unsigned int BlockCount() final;
public: virtual bool RemoveBlock(const int _index) final;
public: virtual void InsertBlock(
const double _duration, const double _interval,
const ignition::math::Color &_color, const int _index) final;
protected: virtual void Flash();
protected: virtual void Dim();
protected: virtual ignition::math::Color CurrentColor() final;
private: std::unique_ptr<FlashLightSettingPrivate> dataPtr;
};
// forward declaration
class FlashLightPluginPrivate;
class GZ_PLUGIN_VISIBLE FlashLightPlugin : public ModelPlugin
{
public: FlashLightPlugin();
public: virtual ~FlashLightPlugin();
// Documentation inherited.
public: void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf) override;
protected: virtual void OnUpdate();
protected: virtual bool TurnOn(const std::string &_lightName) final;
protected: virtual bool TurnOn(
const std::string &_lightName, const std::string &_linkName) final;
protected: virtual bool TurnOnAll() final;
protected: virtual bool TurnOff(const std::string &_lightName) final;
protected: virtual bool TurnOff(
const std::string &_lightName, const std::string &_linkName) final;
protected: virtual bool TurnOffAll() final;
protected: virtual bool ChangeDuration(
const std::string &_lightName, const std::string &_linkName,
const double _duration, const int _index) final;
protected: virtual bool ChangeDuration(
const std::string &_lightName, const std::string &_linkName,
const double _duration) final;
protected: virtual bool ChangeInterval(
const std::string &_lightName, const std::string &_linkName,
const double _interval, const int _index) final;
protected: virtual bool ChangeInterval(
const std::string &_lightName, const std::string &_linkName,
const double _interval) final;
protected: virtual bool ChangeColor(
const std::string &_lightName, const std::string &_linkName,
const ignition::math::Color &_color, const int _index) final;
protected: virtual bool ChangeColor(
const std::string &_lightName, const std::string &_linkName,
const ignition::math::Color &_color) final;
protected: virtual std::shared_ptr<FlashLightSetting> CreateSetting(
const sdf::ElementPtr &_sdf,
const physics::ModelPtr &_model,
const common::Time &_currentTime);
protected:
virtual void InitSettingBySpecificData(
std::shared_ptr<FlashLightSetting> &_setting);
private: std::unique_ptr<FlashLightPluginPrivate> dataPtr;
};
}
#endif
gazebo::FlashLightPlugin::OnUpdate
virtual void OnUpdate()
Called by the world update start event.
gazebo::FlashLightPlugin::CreateSetting
virtual std::shared_ptr< FlashLightSetting > CreateSetting(const sdf::ElementPtr &_sdf, const physics::ModelPtr &_model, const common::Time &_currentTime)
Create an object of setting.
gazebo::FlashLightSetting::CurrentColor
virtual ignition::math::Color CurrentColor() final
Get the current color of the light.
gazebo::FlashLightPlugin::TurnOn
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 identica...
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
gazebo::FlashLightSetting::FlashLightSetting
FlashLightSetting(const sdf::ElementPtr &_sdf, const physics::ModelPtr &_model, const common::Time &_currentTime)
Constructor.
gazebo::common::Time
A Time class, can be used to hold wall- or sim-time. stored as sec and nano-sec.
Definition: Time.hh:47
gazebo::physics::ModelPtr
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:93
gazebo::FlashLightPlugin::ChangeColor
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.
gazebo::FlashLightSetting::InitPubLight
virtual void InitPubLight(const transport::PublisherPtr &_pubLight) final
Set the publisher and send an initial light command.
gazebo::transport::PublisherPtr
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
gazebo::FlashLightSetting::SwitchOff
virtual void SwitchOff() final
Switch off (disable the flashlight).
gazebo::FlashLightPlugin::FlashLightPlugin
FlashLightPlugin()
Constructor.
gazebo::FlashLightSetting::SwitchOn
virtual void SwitchOn() final
Switch on (enable the flashlight).
gazebo::FlashLightPlugin
A plugin that blinks a light component in the model.
Definition: FlashLightPlugin.hh:229
gazebo::FlashLightSetting::Dim
virtual void Dim()
Dim the light This function is internally used to update the light in the environment.
gazebo::FlashLightPlugin::~FlashLightPlugin
virtual ~FlashLightPlugin()
Destructor.
gazebo::FlashLightSetting::UpdateLightInEnv
virtual void UpdateLightInEnv(const common::Time &_currentTime) final
Update the light based on the given time.
gazebo::FlashLightSetting
Internal data class to hold individual flash light settings.
Definition: FlashLightPlugin.hh:38
gazebo::FlashLightSetting::~FlashLightSetting
virtual ~FlashLightSetting()
Destructor.
gazebo::FlashLightPlugin::ChangeInterval
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.
gazebo::FlashLightPlugin::Load
void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf) override
Load function.
gazebo::FlashLightPlugin::ChangeDuration
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.
gazebo::FlashLightPlugin::TurnOnAll
virtual bool TurnOnAll() final
Turn on all flash lights.
gazebo::FlashLightPlugin::TurnOffAll
virtual bool TurnOffAll() final
Turn off all flash lights.
gazebo::FlashLightSetting::Name
virtual const std::string Name() const final
Getter of name.
gazebo::FlashLightPlugin::InitSettingBySpecificData
virtual void InitSettingBySpecificData(std::shared_ptr< FlashLightSetting > &_setting)
Initialize the additional part of an object of setting.
gazebo::FlashLightSetting::InsertBlock
virtual void InsertBlock(const double _duration, const double _interval, const ignition::math::Color &_color, const int _index) final
Insert a block.
gazebo::physics::LinkPtr
boost::shared_ptr< Link > LinkPtr
Definition: PhysicsTypes.hh:109
gazebo::FlashLightPlugin::TurnOff
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 nam...
gazebo::FlashLightSetting::SetDuration
virtual void SetDuration(const double _duration, const int _index) final
Set the duration time for the specified block.
gazebo::FlashLightSetting::BlockCount
virtual unsigned int BlockCount() final
Get the number of blocks.
gazebo::FlashLightSetting::SetColor
virtual void SetColor(const ignition::math::Color &_color, const int _index) final
Set the color for the specified block.
gazebo::ModelPlugin
A plugin with access to physics::Model.
Definition: Plugin.hh:303
Plugin.hh
gazebo::FlashLightSetting::Link
virtual const physics::LinkPtr Link() const final
Getter of link.
gazebo::FlashLightSetting::RemoveBlock
virtual bool RemoveBlock(const int _index) final
Remove a specified block.
gazebo::FlashLightSetting::SetInterval
virtual void SetInterval(const double _interval, const int _index) final
Set the interval time for the specified block.
gazebo::FlashLightSetting::Flash
virtual void Flash()
Flash the light This function is internally used to update the light in the environment.