SMACC2
controllable_led_plugin.cpp
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 <ignition/msgs.hh>
23#include <ignition/transport/Node.hh>
24
25#include "gazebo/common/Plugin.hh"
26#include "gazebo/msgs/msgs.hh"
27
28#include "gazebo/physics/World.hh"
29#include "LedPlugin.hh"
30#include "gazebo/transport/Node.hh"
31
32#include <gazebo_ros/node.hpp>
33#include <rclcpp/rclcpp.hpp>
34#include <std_msgs/msg/int8.hpp>
35
36namespace smacc2
37{
39{
40public:
42 gazebo_ros::Node::SharedPtr ros_node_;
43 rclcpp::Subscription<std_msgs::msg::Int8>::SharedPtr subscription_;
44
46 {
47 gzmsg << "Loading ControllableLed plugin\n";
48 // Transport initialization
49 // this->gzNode = gazebo::transport::NodePtr(new gazebo::transport::Node());
50 // this->gzNode->Init();
51
52 // Subscribe to ContainPlugin output
53 //std::string topic("/test_cmd");
54
55 // const bool containSub = this->dataPtr->node.Subscribe(topic, &ControllableLed::OnCommand2, this);
56 // //containSub = this->gzNode->Subscribe(topic, &ControllableLed::OnCommand, this);
57
58 // if (!containSub)
59 // {
60 // gzerr << "Failed to subscribe to [" << topic << "]\n";
61 // }
62 // else
63 // {
64 // gzmsg << "Subscribed to [" << topic << "]\n";
65 // }
66
67 // Subscribe to ContainPlugin output
68 // std::string topic("contain_example/contain");
69 // std::function<void(const ignition::msgs::Boolean &)> cb =
70 // [=](const ignition::msgs::Boolean & _msg)
71 // {
72 // //TurnOnLightPlugin::OnContainPluginMsg(_msg);
73 // };
74 // const bool containSub = this->node.Subscribe(topic, cb);
75 // if (!containSub)
76 // {
77 // gzerr << "Failed to subscribe to [" << topic << "]\n";
78 // }
79 }
80
81 void LightCmd(const std_msgs::msg::Int8::SharedPtr msg)
82 {
83 gzmsg << "Turning on light\n";
84
85 if (msg->data == 1)
86 {
87 gzmsg << "Turning on light\n";
88 this->TurnOnAll();
89 // lightMsg.set_range(15.0);
90 }
91 else if (msg->data == 0)
92 {
93 gzmsg << "Turning off light\n";
94 this->TurnOffAll();
95 // lightMsg.set_range(0.0);
96 }
97 }
98
99 void Load(gazebo::physics::ModelPtr _parent, sdf::ElementPtr _sdf) override
100 {
101 // Subscribe to wrench messages
102 // ros_node_ = gazebo_ros::Node::Get(_sdf);
103
104 // subscription_ = ros_node_->create_subscription<std_msgs::msg::Int8>(
105 // "led_cmd", rclcpp::SystemDefaultsQoS(),
106 // std::bind(&ControllableLed::LightCmd, this, std::placeholders::_1));
107
108 // // Make a publisher for the light topic
109 // this->lightPub = this->gzNode->Advertise<msgs::Light>("~/light/modify");
110
111 LedPlugin::Load(_parent, _sdf);
112 //this->TurnOnAll();
113 }
114
115public:
116 void OnCommand(ConstIntPtr & _msg)
117 {
118
119 }
120};
121} // namespace gazebo
122
123GZ_REGISTER_MODEL_PLUGIN(smacc2::ControllableLed)
rclcpp::Subscription< std_msgs::msg::Int8 >::SharedPtr subscription_
void OnCommand(ConstIntPtr &_msg)
void LightCmd(const std_msgs::msg::Int8::SharedPtr msg)
gazebo_ros::Node::SharedPtr ros_node_
A pointer to the GazeboROS node.
void Load(gazebo::physics::ModelPtr _parent, sdf::ElementPtr _sdf) override
virtual bool TurnOffAll() final
Turn off all flash lights.
virtual bool TurnOnAll() final
Turn on all flash lights.
void Load(gazebo::physics::ModelPtr _parent, sdf::ElementPtr _sdf) override
A plugin that blinks light and visual elements in a model. In addition to the features of the base pl...
Definition: LedPlugin.hh:107