SMACC2
FlashLightPlugin.cc
Go to the documentation of this file.
1// Copyright 2021 RobosoftAI Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/*****************************************************************************************************************
16 *
17 * Authors: Pablo Inigo Blasco, Brett Aldrich
18 *
19 ******************************************************************************************************************/
20
21
22#include <memory>
23#include <string>
24#include <vector>
25
26#include <ignition/math/Color.hh>
27
28#include <gazebo/common/Plugin.hh>
29#include <gazebo/msgs/msgs.hh>
30#include <gazebo/physics/physics.hh>
31#include <gazebo/transport/transport.hh>
32#include "FlashLightPlugin.hh"
33#include <boost/algorithm/string.hpp>
34
35namespace smacc2
36{
37 using namespace gazebo;
38
39 struct Block
40 {
42 public: double duration;
43
46 public: double interval;
47
49 public: ignition::math::Color color;
50 };
51
53 {
56 switchOn(true), flashing(true), range(0),
58 {
59 }
60
68 public: gazebo::physics::LinkPtr FindLinkForLight(
69 const gazebo::physics::ModelPtr &_model,
70 const std::string &_lightName, const std::string &_linkName)
71 {
72 auto childLink = _model->GetChildLink(_linkName);
73 if (childLink && childLink->GetSDF()->HasElement("light"))
74 {
75 auto sdfLight = childLink->GetSDF()->GetElement("light");
76 while (sdfLight)
77 {
78 if (sdfLight->Get<std::string>("name") == _lightName)
79 {
80 return childLink;
81 }
82 sdfLight = sdfLight->GetNextElement("light");
83 }
84 }
85 for (auto model: _model->NestedModels())
86 {
87 auto foundLink = this->FindLinkForLight(model, _lightName, _linkName);
88 if (foundLink)
89 {
90 return foundLink;
91 }
92 }
93
94 return nullptr;
95 }
96
98 public: std::string name;
99
101 public: gazebo::physics::LinkPtr link;
102
104 public: gazebo::common::Time startTime;
105
107 public: bool switchOn;
108
110 public: bool flashing;
111
113 public: double range;
114
116 public: gazebo::transport::PublisherPtr pubLight;
117
119 public: msgs::Light msg;
120
122 public: bool lightExists;
123
125 public: std::vector< std::shared_ptr<Block> > blocks;
126
128 public: int currentBlockIndex;
129 };
130
132 {
140 public: std::shared_ptr<FlashLightSetting>
142 const std::string &_lightName, const std::string &_linkName) const
143 {
144 for (auto &setting: this->listFlashLight)
145 {
146 if (setting->Name() == _lightName)
147 {
148 if (_linkName.length() == 0
149 || setting->Link()->GetName() == _linkName)
150 {
151 return setting;
152 }
153 }
154 }
155
156 return nullptr;
157 }
158
160 public: gazebo::physics::ModelPtr model;
161
163 public: gazebo::physics::WorldPtr world;
164
166 public: gazebo::transport::NodePtr node;
167
169 public: gazebo::transport::PublisherPtr pubLight;
170
172 public: std::vector< std::shared_ptr<FlashLightSetting> > listFlashLight;
173
175 public: event::ConnectionPtr updateConnection;
176 };
177}
178
179using namespace gazebo;
180
181namespace smacc2
182{
185 const sdf::ElementPtr &_sdf,
186 const gazebo::physics::ModelPtr &_model,
187 const gazebo::common::Time &_currentTime,
188 gazebo_ros::Node::SharedPtr rosnode)
189 : dataPtr(new FlashLightSettingPrivate)
190{
191 // Get the light name.
192 std::string lightId;
193 if (_sdf->HasElement("id"))
194 {
195 lightId = _sdf->Get<std::string>("id");
196 }
197 else
198 {
199 gzerr << "Parameter <id> is missing." << std::endl;
200 }
201 int posDelim = lightId.rfind("/");
202 this->dataPtr->name = lightId.substr(posDelim+1, lightId.length());
203
204 // link which holds this light
205 this->dataPtr->link = this->dataPtr->FindLinkForLight(
206 _model, this->dataPtr->name,
207 lightId.substr(0, posDelim));
208
209 if (_sdf->HasElement("block"))
210 {
211 sdf::ElementPtr sdfBlock = _sdf->GetElement("block");
212 while (sdfBlock)
213 {
214 auto block = std::make_shared<Block>();
215 // duration
216 if (sdfBlock->HasElement("duration"))
217 {
218 block->duration = sdfBlock->Get<double>("duration");
219 }
220 else
221 {
222 //gzerr << "Parameter <duration> is missing in a block." << std::endl;
223 block->duration = std::numeric_limits<double>::max();
224
225 }
226 // interval
227 if (sdfBlock->HasElement("interval"))
228 {
229 block->interval = sdfBlock->Get<double>("interval");
230 }
231 else
232 {
233 //gzerr << "Parameter <interval> is missing in a block." << std::endl;
234 block->interval = std::numeric_limits<double>::max();
235
236 }
237 // color
238 if (sdfBlock->HasElement("color"))
239 {
240 block->color = sdfBlock->Get<ignition::math::Color>("color");
241 }
242 else
243 {
244 block->color.Reset();
245 }
246
247 this->dataPtr->blocks.push_back(block);
248 sdfBlock = sdfBlock->GetNextElement("block");
249 }
250 }
251 else
252 {
253 auto block = std::make_shared<Block>();
254 // duration
255 if (_sdf->HasElement("duration"))
256 {
257 block->duration = _sdf->Get<double>("duration");
258 }
259 else
260 {
261 // gzerr << "Parameter <duration> is missing." << std::endl;
262 block->duration = std::numeric_limits<double>::max();
263
264 }
265 // interval
266 if (_sdf->HasElement("interval"))
267 {
268 block->interval = _sdf->Get<double>("interval");
269 }
270 else
271 {
272 // gzerr << "Parameter <interval> is missing." << std::endl;
273 block->interval = std::numeric_limits<double>::max();
274
275 }
276 // color
277 if (_sdf->HasElement("color"))
278 {
279 block->color = _sdf->Get<ignition::math::Color>("color");
280 }
281 else
282 {
283 block->color.Reset();
284 }
285
286 this->dataPtr->blocks.push_back(block);
287 }
288
289 // start time
290 this->dataPtr->startTime = _currentTime;
291
292 // If link is not nullptr, the light exists.
293 if (this->dataPtr->link)
294 {
295
296
297 // void LightCmd(const std_msgs::msg::Int8::SharedPtr msg)
298 // {
299 // gzmsg << "Turning on light\n";
300
301 // if (msg->data == 1)
302 // {
303 // gzmsg << "Turning on light\n";
304 // this->TurnOnAll();
305 // // lightMsg.set_range(15.0);
306 // }
307 // else if (msg->data == 0)
308 // {
309 // gzmsg << "Turning off light\n";
310 // this->TurnOffAll();
311 // // lightMsg.set_range(0.0);
312 // }
313 // }
314 // range
315 if (this->dataPtr->link->GetSDF()->HasElement("light"))
316 {
317 auto sdfLight = this->dataPtr->link->GetSDF()->GetElement("light");
318 while (sdfLight)
319 {
320 if (sdfLight->Get<std::string>("name") == this->dataPtr->name)
321 {
322 this->dataPtr->range
323 = sdfLight->GetElement("attenuation")->Get<double>("range");
324 break;
325 }
326 sdfLight = sdfLight->GetNextElement("light");
327 }
328 this->dataPtr->lightExists = true;
329 }
330 }
331}
332
335{
336}
337
340 const gazebo::transport::PublisherPtr &_pubLight)
341{
342 // The PublisherPtr
343 this->dataPtr->pubLight = _pubLight;
344
345 if (this->dataPtr->lightExists)
346 {
347 // Make a message
348 this->dataPtr->msg.set_name(
349 this->dataPtr->link->GetScopedName() + "::" + this->dataPtr->name);
350 this->dataPtr->msg.set_range(this->dataPtr->range);
351 }
352}
353
355void FlashLightSetting::UpdateLightInEnv(const gazebo::common::Time &_currentTime)
356{
357 if (this->dataPtr->switchOn)
358 {
359 this->Flash();
360
361 }
362 else
363 {
364 this->Dim();
365 }
366
367 // int index = this->dataPtr->currentBlockIndex;
368
369 // // Reset the start time so the current time is within the current phase.
370 // if (_currentTime < this->dataPtr->startTime ||
371 // this->dataPtr->startTime
372 // + this->dataPtr->blocks[index]->duration
373 // + this->dataPtr->blocks[index]->interval <= _currentTime)
374 // {
375 // // initialize the start time.
376 // this->dataPtr->startTime = _currentTime;
377 // // proceed to the next block.
378 // index++;
379 // if (index >= static_cast<int>(this->dataPtr->blocks.size()))
380 // {
381 // index = 0;
382 // }
383 // this->dataPtr->currentBlockIndex = index;
384 // }
385
386 // if (this->dataPtr->switchOn)
387 // {
388 // // time to dim
389 // if (_currentTime - this->dataPtr->startTime
390 // > this->dataPtr->blocks[index]->duration)
391 // {
392 // if (this->dataPtr->flashing)
393 // {
394 // this->Dim();
395 // }
396 // }
397 // // time to flash
398 // else
399 // {
400 // // if there is more than one block, it calls Flash() at the beginning of
401 // // every block.
402 // if (this->dataPtr->blocks.size() > 1
403 // && this->dataPtr->startTime == _currentTime)
404 // {
405 // this->Flash();
406 // }
407 // // otherwise, it calls the function only if the light is not lit yet.
408 // else if (!this->dataPtr->flashing)
409 // {
410 // this->Flash();
411 // }
412 // }
413 // }
414 // else if (this->dataPtr->flashing)
415 // {
416 // this->Dim();
417 // }
418}
419
421const std::string FlashLightSetting::Name() const
422{
423 return this->dataPtr->name;
424}
425
427const gazebo::physics::LinkPtr FlashLightSetting::Link() const
428{
429 return this->dataPtr->link;
430}
431
434{
435 this->dataPtr->switchOn = true;
436}
437
440{
441 gzmsg << "switch off" << std::endl;
442
443 this->dataPtr->switchOn = false;
444}
445
447void FlashLightSetting::SetDuration(const double _duration, const int _index)
448{
449 if (0 <= _index && _index < static_cast<int>(this->dataPtr->blocks.size()))
450 {
451 this->dataPtr->blocks[_index]->duration = _duration;
452 }
453 else
454 {
455 gzerr << "The given index for block is out of range." << std::endl;
456 }
457}
458
460void FlashLightSetting::SetDuration(const double _duration)
461{
462 for (auto block: this->dataPtr->blocks)
463 {
464 block->duration = _duration;
465 }
466}
467
469void FlashLightSetting::SetInterval(const double _interval, const int _index)
470{
471 if (0 <= _index && _index < static_cast<int>(this->dataPtr->blocks.size()))
472 {
473 this->dataPtr->blocks[_index]->interval = _interval;
474 }
475 else
476 {
477 gzerr << "The given index for block is out of range." << std::endl;
478 }
479}
480
482void FlashLightSetting::SetInterval(const double _interval)
483{
484 for (auto block: this->dataPtr->blocks)
485 {
486 block->interval = _interval;
487 }
488}
489
492 const ignition::math::Color &_color, const int _index)
493{
494 if (0 <= _index && _index < static_cast<int>(this->dataPtr->blocks.size()))
495 {
496 this->dataPtr->blocks[_index]->color = _color;
497 }
498 else
499 {
500 gzerr << "The given index for block is out of range." << std::endl;
501 }
502}
503
505void FlashLightSetting::SetColor(const ignition::math::Color &_color)
506{
507 for (auto block: this->dataPtr->blocks)
508 {
509 block->color = _color;
510 }
511}
512
515{
516 return this->dataPtr->blocks.size();
517}
518
520bool FlashLightSetting::RemoveBlock(const int _index)
521{
522 if (_index < 0 || static_cast<int>(this->dataPtr->blocks.size()) <= _index)
523 {
524 return false;
525 }
526
527 this->dataPtr->blocks.erase(this->dataPtr->blocks.begin() + _index);
528
529 return true;
530}
531
534 const double _duration, const double _interval,
535 const ignition::math::Color &_color, const int _index)
536{
537 auto block = std::make_shared<Block>();
538
539 block->duration = _duration;
540 block->interval = _interval;
541 block->color = _color;
542
543 if (_index < 0 || static_cast<int>(this->dataPtr->blocks.size()) <= _index)
544 {
545 this->dataPtr->blocks.push_back(block);
546 }
547 else
548 {
549 this->dataPtr->blocks.insert(this->dataPtr->blocks.begin() + _index, block);
550 }
551}
552
555{
556 // Set the range to the default value.
557 this->dataPtr->msg.set_range(this->dataPtr->range);
558 // set the color of light.
559 if (this->dataPtr->blocks[this->dataPtr->currentBlockIndex]->color
560 != ignition::math::Color::Black)
561 {
562 msgs::Set(this->dataPtr->msg.mutable_diffuse(),
563 this->dataPtr->blocks[this->dataPtr->currentBlockIndex]->color);
564 msgs::Set(this->dataPtr->msg.mutable_specular(),
565 this->dataPtr->blocks[this->dataPtr->currentBlockIndex]->color);
566 }
567 // Send the message.
568 if (this->dataPtr->lightExists)
569 {
570 //this->dataPtr->pubLight->Publish(this->dataPtr->msg);
571 }
572 // Update the state.
573 this->dataPtr->flashing = true;
574}
575
578{
579 // Set the range to zero.
580 this->dataPtr->msg.set_range(0.0);
581 // Send the message.
582 if (this->dataPtr->lightExists)
583 {
584 //this->dataPtr->pubLight->Publish(this->dataPtr->msg);
585 }
586 // Update the state.
587 this->dataPtr->flashing = false;
588}
589
591ignition::math::Color FlashLightSetting::CurrentColor()
592{
593 return this->dataPtr->blocks[this->dataPtr->currentBlockIndex]->color;
594}
595
597FlashLightPlugin::FlashLightPlugin() : gazebo::ModelPlugin(),
598 dataPtr(new FlashLightPluginPrivate)
599{
600 // Create a node
601 this->dataPtr->node = gazebo::transport::NodePtr(new gazebo::transport::Node());
602 this->dataPtr->node->Init();
603
604 // advertise the topic to update lights
605 // this->dataPtr->pubLight
606 // = this->dataPtr->node->Advertise<gazebo::msgs::Light>("~/light/modify");
607
608 // this->dataPtr->pubLight->WaitForConnection();
609}
610
613{
614}
615
617void FlashLightPlugin::Load(gazebo::physics::ModelPtr _parent, sdf::ElementPtr _sdf)
618{
619 // Store the pointers to the model and world
620 this->dataPtr->model = _parent;
621 this->dataPtr->world = _parent->GetWorld();
622
623 auto node = gazebo_ros::Node::Get(_sdf);
624 // Get the current time
625 gazebo::common::Time currentTime = this->dataPtr->world->SimTime();
626
627 // Get the parameters from sdf
628 if (_sdf->HasElement("light"))
629 {
630 sdf::ElementPtr sdfFlashLight = _sdf->GetElement("light");
631 while (sdfFlashLight)
632 {
633 // id required
634 if (sdfFlashLight->HasElement("id"))
635 {
636 // Create an object of setting.
637 std::shared_ptr<FlashLightSetting> setting
638 = this->CreateSetting(
639 sdfFlashLight, this->dataPtr->model, currentTime, node);
640
641 // Initialize the object with the data specific to descendan classes.
642 this->InitSettingBySpecificData(setting);
643
644 // Store the setting to the list
645 this->dataPtr->listFlashLight.push_back(setting);
646 }
647 else
648 {
649 // display an error message
650 gzerr << "id does not exist in <light>" << std::endl;
651 }
652
653 sdfFlashLight = sdfFlashLight->GetNextElement("light");
654 }
655
656 // Turn on/off all the lights if <enable> element is given
657 if (_sdf->HasElement("enable"))
658 {
659 if (_sdf->Get<bool>("enable"))
660 {
661 this->TurnOnAll();
662 }
663 else
664 {
665 this->TurnOffAll();
666 }
667 }
668 // Turn on/off a specific light if <enable> is specifically given.
669 if (_sdf->HasElement("light"))
670 {
671 sdf::ElementPtr sdfFlashLight = _sdf->GetElement("light");
672 while (sdfFlashLight)
673 {
674 if (sdfFlashLight->HasElement("enable"))
675 {
676 std::string lightId = sdfFlashLight->Get<std::string>("id");
677 int posDelim = lightId.rfind("/");
678 std::string lightName = lightId.substr(posDelim+1, lightId.length());
679 std::string linkName = lightId.substr(0, posDelim);
680 if (sdfFlashLight->Get<bool>("enable"))
681 {
682 this->TurnOn(lightName, linkName);
683 }
684 else
685 {
686 this->TurnOff(lightName, linkName);
687 }
688 }
689
690 sdfFlashLight = sdfFlashLight->GetNextElement("light");
691 }
692 }
693
694 // listen to the update event by the World
695 if (!this->dataPtr->listFlashLight.empty())
696 {
697 this->dataPtr->updateConnection = event::Events::ConnectWorldUpdateBegin(
698 std::bind(&FlashLightPlugin::OnUpdate, this));
699 }
700
701 rclcpp::SensorDataQoS qos;
702
703 auto topicname = "/"+ this->dataPtr->model->GetName()+ "/cmdled";
704
705 boost::replace_all(topicname, "::","/");
706
707 gzmsg << "topicname: " << topicname <<"\n";
708
710 node->create_subscription<std_msgs::msg::Int8>(topicname, qos,
711 [this, node]
712 (const std_msgs::msg::Int8::SharedPtr msg)
713 {
714 RCLCPP_INFO(node->get_logger(), "msg received");
715 if(msg->data == 0)
716 this->TurnOffAll();
717 else
718 this->TurnOnAll();
719
720 });
721 }
722}
723
726{
727 gazebo::common::Time currentTime = this->dataPtr->world->SimTime();
728
729 for (auto &setting: this->dataPtr->listFlashLight)
730 {
732 setting->UpdateLightInEnv(currentTime);
733 }
734}
735
737bool FlashLightPlugin::TurnOn(const std::string &_lightName)
738{
739 return this->TurnOn(_lightName, "");
740}
741
744 const std::string &_lightName, const std::string &_linkName)
745{
746 std::shared_ptr<FlashLightSetting> setting
747 = this->dataPtr->SettingByLightNameAndLinkName(_lightName, _linkName);
748
749 if (setting)
750 {
751 setting->SwitchOn();
752 return true;
753 }
754
755 gzerr << "light: [" + _linkName + "/" + _lightName + "] does not exist."
756 << std::endl;
757 return false;
758}
759
762{
763 if (this->dataPtr->listFlashLight.empty())
764 {
765 gzerr << "no flash lights exist to turn on." << std::endl;
766 return false;
767 }
768
769 for (auto &setting: this->dataPtr->listFlashLight)
770 {
771 setting->SwitchOn();
772 }
773
774 return true;
775}
776
778bool FlashLightPlugin::TurnOff(const std::string &_lightName)
779{
780 return this->TurnOff(_lightName, "");
781}
782
784bool FlashLightPlugin::TurnOff(const std::string &_lightName,
785 const std::string &_linkName)
786{
787 std::shared_ptr<FlashLightSetting> setting
788 = this->dataPtr->SettingByLightNameAndLinkName(_lightName, _linkName);
789
790 if (setting)
791 {
792 setting->SwitchOff();
793 return true;
794 }
795
796 gzerr << "light: [" + _linkName + "/" + _lightName + "] does not exist."
797 << std::endl;
798 return false;
799}
800
803{
804 gzmsg << "msg TurnOffAll" << std::endl;
805 if (this->dataPtr->listFlashLight.empty())
806 {
807 gzerr << "no flash lights exist to turn off." << std::endl;
808 return false;
809 }
810
811 gzmsg << "switch off" << std::endl;
812
813 for (auto &setting: this->dataPtr->listFlashLight)
814 {
815 setting->SwitchOff();
816 }
817
818 return true;
819}
820
823 const std::string &_lightName, const std::string &_linkName,
824 const double _duration, const int _index
825)
826{
827 std::shared_ptr<FlashLightSetting> setting
828 = this->dataPtr->SettingByLightNameAndLinkName(_lightName, _linkName);
829
830 if (setting)
831 {
832 if (_index >= 0)
833 {
834 setting->SetDuration(_duration, _index);
835 }
836 else
837 {
838 setting->SetDuration(_duration);
839 }
840 return true;
841 }
842
843 gzerr << "light <" + _lightName + "> does not exist." << std::endl;
844 return false;
845}
846
849 const std::string &_lightName, const std::string &_linkName,
850 const double _duration
851)
852{
853 return this->ChangeDuration(_lightName, _linkName, _duration, -1);
854}
855
858 const std::string &_lightName, const std::string &_linkName,
859 const double _interval, const int _index
860)
861{
862 std::shared_ptr<FlashLightSetting> setting
863 = this->dataPtr->SettingByLightNameAndLinkName(_lightName, _linkName);
864
865 if (setting)
866 {
867 if (_index >= 0)
868 {
869 setting->SetInterval(_interval, _index);
870 }
871 else
872 {
873 setting->SetInterval(_interval);
874 }
875 return true;
876 }
877
878 gzerr << "light <" + _lightName + "> does not exist." << std::endl;
879 return false;
880}
881
884 const std::string &_lightName, const std::string &_linkName,
885 const double _interval
886)
887{
888 return this->ChangeInterval(_lightName, _linkName, _interval, -1);
889}
890
893 const std::string &_lightName, const std::string &_linkName,
894 const ignition::math::Color &_color, const int _index
895)
896{
897 std::shared_ptr<FlashLightSetting> setting
898 = this->dataPtr->SettingByLightNameAndLinkName(_lightName, _linkName);
899
900 if (setting)
901 {
902 if (_index >= 0)
903 {
904 setting->SetColor(_color, _index);
905 }
906 else
907 {
908 setting->SetColor(_color);
909 }
910 return true;
911 }
912
913 gzerr << "light <" + _lightName + "> does not exist." << std::endl;
914 return false;
915}
916
919 const std::string &_lightName, const std::string &_linkName,
920 const ignition::math::Color &_color
921)
922{
923 return this->ChangeColor(_lightName, _linkName, _color, -1);
924}
925
927std::shared_ptr<FlashLightSetting>
929 const sdf::ElementPtr &_sdf,
930 const gazebo::physics::ModelPtr &_model,
931 const gazebo::common::Time &_currentTime,
932 gazebo_ros::Node::SharedPtr node)
933{
934 return std::make_shared<FlashLightSetting>(_sdf, _model, _currentTime, node);
935}
936
939 std::shared_ptr<FlashLightSetting> &_setting)
940{
941 _setting->InitPubLight(this->dataPtr->pubLight);
942}
943}
gazebo::physics::ModelPtr model
pointer to the model.
std::shared_ptr< FlashLightSetting > SettingByLightNameAndLinkName(const std::string &_lightName, const std::string &_linkName) const
Find a setting by names. This is internally used to access an individual setting. If the link name is...
gazebo::physics::WorldPtr world
pointer to the world.
gazebo::transport::NodePtr node
The pointer to node for communication.
gazebo::transport::PublisherPtr pubLight
The pointer to publisher to send a command to the light.
event::ConnectionPtr updateConnection
pointer to the update even connection.
std::vector< std::shared_ptr< FlashLightSetting > > listFlashLight
The list of flashlight settings to control.
virtual bool TurnOffAll() final
Turn off all flash lights.
virtual ~FlashLightPlugin()
Destructor.
rclcpp::Subscription< std_msgs::msg::Int8 >::SharedPtr cmdledsubscription
virtual bool TurnOnAll() final
Turn on all flash lights.
void Load(gazebo::physics::ModelPtr _parent, sdf::ElementPtr _sdf) override
virtual void OnUpdate()
Called by the world update start event.
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,...
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...
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...
std::unique_ptr< FlashLightPluginPrivate > dataPtr
Pointer to private data.
virtual void InitSettingBySpecificData(std::shared_ptr< FlashLightSetting > &_setting)
Initialize the additional part of an object of setting.
virtual std::shared_ptr< FlashLightSetting > CreateSetting(const sdf::ElementPtr &_sdf, const gazebo::physics::ModelPtr &_model, const gazebo::common::Time &_currentTime, gazebo_ros::Node::SharedPtr node)
Create an object of setting.
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,...
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,...
gazebo::common::Time startTime
The time at which the current phase started.
bool lightExists
True if <light> element exists.
gazebo::transport::PublisherPtr pubLight
The pointer to publisher to send a command to a light.
std::string name
The name of flash light.
gazebo::physics::LinkPtr link
Link which holds this flash light.
bool switchOn
The current switch state (the light itself is active or not).
gazebo::physics::LinkPtr FindLinkForLight(const gazebo::physics::ModelPtr &_model, const std::string &_lightName, const std::string &_linkName)
Find the link holding the light to control. If multiple models are nested, this function is recursive...
double range
The length of the ray (in meters).
msgs::Light msg
A message holding a flashlight command.
int currentBlockIndex
the index of the current block.
bool flashing
The current flasshing state (flash or dim).
std::vector< std::shared_ptr< Block > > blocks
The list of blocks of light.
virtual void SetDuration(const double _duration, const int _index) final
Set the duration time for the specified block.
virtual void InitPubLight(const gazebo::transport::PublisherPtr &_pubLight) final
Set the publisher and send an initial light command.
virtual unsigned int BlockCount() final
Get the number of blocks.
virtual void UpdateLightInEnv(const gazebo::common::Time &_currentTime) final
Update the light based on the given time.
std::unique_ptr< FlashLightSettingPrivate > dataPtr
Pointer to private data.
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,...
virtual const std::string Name() const final
Getter of name.
virtual void SwitchOn() final
Switch on (enable the flashlight).
virtual void Dim()
Dim the light This function is internally used to update the light in the environment.
virtual const gazebo::physics::LinkPtr Link() const final
Getter of link.
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 SetInterval(const double _interval, const int _index) final
Set the interval time for the specified block.
virtual void Flash()
Flash the light This function is internally used to update the light in the environment.
virtual void SwitchOff() final
Switch off (disable the flashlight).
virtual ~FlashLightSetting()
Destructor.
virtual void SetColor(const ignition::math::Color &_color, const int _index) final
Set the color for the specified block.
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.
virtual bool RemoveBlock(const int _index) final
Remove a specified block.
double duration
The duration time to flash (in seconds).
double interval
The interval time between flashing (in seconds). When it is zero, the light is constant.
ignition::math::Color color
The color of light.