light_buoy_plugin.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef VMRC_GAZEBO_LIGHT_BUOY_PLUGIN_HH_
19 #define VMRC_GAZEBO_LIGHT_BUOY_PLUGIN_HH_
20 
21 #include <ros/ros.h>
22 #include <std_msgs/ColorRGBA.h>
23 #include <std_srvs/Trigger.h>
24 
25 #include <array>
26 #include <cstdint>
27 #include <mutex>
28 #include <string>
29 #include <utility>
30 #include <vector>
31 #include <gazebo/gazebo.hh>
32 #include <sdf/sdf.hh>
33 
64 class LightBuoyPlugin : public gazebo::VisualPlugin
65 {
66  // Documentation inherited.
67  public: void Load(gazebo::rendering::VisualPtr _parent,
68  sdf::ElementPtr _sdf);
69 
76  private: static std_msgs::ColorRGBA CreateColor(const double _r,
77  const double _g,
78  const double _b,
79  const double _a);
80 
84  private: static uint8_t IndexFromColor(const std::string &_color);
85 
88  private: bool ParseSDF(sdf::ElementPtr _sdf);
89 
95  private: bool ChangePattern(std_srvs::Trigger::Request &_req,
96  std_srvs::Trigger::Response &_res);
97 
102  private: void ChangePattern(std::string &_message);
103 
106  private: void Update();
107 
110  private: using Colors_t = std::pair<std_msgs::ColorRGBA, std::string>;
111 
114  private: using Pattern_t = std::array<uint8_t, 4>;
115 
118  private: static const std::array<Colors_t, 5> kColors;
119 
121  private: std::vector<std::string> visualNames;
122 
124  private: std::vector<gazebo::rendering::VisualPtr> visuals;
125 
127  private: bool shuffleEnabled = true;
128 
131 
133  private: ros::NodeHandle nh;
134 
136  private: Pattern_t pattern;
137 
140  private: uint8_t state = 0u;
141 
143  private: std::string ns;
144 
146  private: std::string topic;
147 
149  private: gazebo::rendering::ScenePtr scene;
150 
152  private: gazebo::event::ConnectionPtr updateConnection;
153 
155  private: gazebo::common::Timer timer;
156 
158  private: std::mutex mutex;
159 };
160 
161 #endif
static std_msgs::ColorRGBA CreateColor(const double _r, const double _g, const double _b, const double _a)
Creates a std_msgs::ColorRGBA message from 4 doubles.
std::vector< gazebo::rendering::VisualPtr > visuals
Pointer to the visual elements to modify.
void Load(gazebo::rendering::VisualPtr _parent, sdf::ElementPtr _sdf)
bool shuffleEnabled
Whether shuffle is enabled via a ROS topic or not.
Visual plugin for changing the color of some visual elements using ROS messages. This plugin accepts ...
std::vector< std::string > visualNames
Collection of visual names.
bool ParseSDF(sdf::ElementPtr _sdf)
Parse all SDF parameters.
gazebo::common::Timer timer
Timer used to switch colors every second.
ros::NodeHandle nh
ROS Node handle.
static uint8_t IndexFromColor(const std::string &_color)
Return the index of the color from its string.
std::string ns
ROS namespace.
std::pair< std_msgs::ColorRGBA, std::string > Colors_t
void Update()
Display the next color in the sequence, or start over if at the end.
static const std::array< Colors_t, 5 > kColors
List of the color options (red, green, blue, yellow and no color) with their string name for logging...
Pattern_t pattern
The color pattern.
gazebo::rendering::ScenePtr scene
Pointer to the scene node.
std::string topic
ROS topic.
std::mutex mutex
Locks state and pattern member variables.
std::array< uint8_t, 4 > Pattern_t
bool ChangePattern(std_srvs::Trigger::Request &_req, std_srvs::Trigger::Response &_res)
Callback for change pattern service, calls other changePattern internaly.
uint8_t state
Track current index in pattern.
gazebo::event::ConnectionPtr updateConnection
Connects to rendering update event.
ros::ServiceServer changePatternServer
Service to generate and display a new color sequence.


vmrc_gazebo
Author(s): Brian Bingham , Carlos Aguero
autogenerated on Sun Feb 17 2019 03:14:16