18 #include <gazebo/rendering/Scene.hh> 24 {
"red", CreateColor(1.0, 0.0, 0.0, 1.0)},
25 {
"green", CreateColor(0.0, 1.0, 0.0, 1.0)},
26 {
"blue", CreateColor(0.0, 0.0, 1.0, 1.0)},
30 {
"circle",
"cross",
"triangle"};
34 gzNode(new
gazebo::transport::Node())
40 const double _g,
const double _b,
const double _a)
42 static std_msgs::ColorRGBA
color;
53 for (
auto const &colorPair : this->
kColors)
62 GZ_ASSERT(_parent !=
nullptr,
"Received NULL model pointer");
64 this->
scene = _parent->GetScene();
65 GZ_ASSERT(this->
scene !=
nullptr,
"NULL scene");
98 std::lock_guard<std::mutex> lock(this->
mutex);
99 this->
shape = _msg->shape();
100 this->
color = _msg->color();
111 if (_sdf->HasElement(
"shape"))
113 std::string aShape = _sdf->GetElement(
"shape")->Get<std::string>();
114 std::transform(aShape.begin(), aShape.end(), aShape.begin(), ::tolower);
116 if (std::find(this->
kShapes.begin(), this->
kShapes.end(), aShape) !=
119 this->
shape = aShape;
124 "incorrect [%s] <shape>, using random shape", aShape.c_str());
129 if (_sdf->HasElement(
"color"))
131 std::string aColor = _sdf->GetElement(
"color")->Get<std::string>();
132 std::transform(aColor.begin(), aColor.end(), aColor.begin(), ::tolower);
136 this->
color = aColor;
141 "incorrect [%s] <color>, using random color", aColor.c_str());
146 if (!_sdf->HasElement(
"visuals"))
152 auto visualsElem = _sdf->GetElement(
"visuals");
153 if (!visualsElem->HasElement(
"visual"))
159 auto visualElem = visualsElem->GetElement(
"visual");
162 std::string visualName = visualElem->Get<std::string>();
164 visualElem = visualElem->GetNextElement();
168 if (_sdf->HasElement(
"shuffle"))
173 if (!_sdf->HasElement(
"ros_shuffle_topic"))
175 ROS_ERROR(
"<ros_shuffle_topic> missing");
178 (
"ros_shuffle_topic")->Get<std::string>();
182 if (!_sdf->HasElement(
"robot_namespace"))
186 this->
ns = _sdf->GetElement(
"robot_namespace")->Get<std::string>();
187 if (!_sdf->HasElement(
"gz_symbol_topic"))
194 (
"gz_symbol_topic")->Get<std::string>();
207 auto visualPtr = this->
scene->GetVisual(visualName);
209 this->
visuals.push_back(visualPtr);
211 ROS_ERROR(
"Unable to find [%s] visual", visualName.c_str());
221 std::lock_guard<std::mutex> lock(this->
mutex);
224 for (
auto visual : this->
visuals)
226 std_msgs::ColorRGBA
color;
229 #if GAZEBO_MAJOR_VERSION >= 8 230 auto name = visual->Name();
232 auto name = visual->GetName();
234 auto delim = name.rfind(
"/");
235 auto shortName = name.substr(delim + 1);
236 if (shortName.find(this->shape) != std::string::npos)
240 #if GAZEBO_MAJOR_VERSION >= 8 241 ignition::math::Color gazeboColor(color.r, color.g, color.b, color.a);
243 gazebo::common::Color gazeboColor(color.r, color.g, color.b, color.a);
246 visual->SetAmbient(gazeboColor);
247 visual->SetDiffuse(gazeboColor);
255 std::lock_guard<std::mutex> lock(this->
mutex);
263 this->
shape.c_str());
static std::vector< std::string > kShapes
List of the shape options (circle, cross, triangle) with their string name for logging.
#define ROS_INFO_NAMED(name,...)
ros::NodeHandle nh
ROS Node handle.
gazebo::rendering::ScenePtr scene
Pointer to the scene node.
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void InitializeAllPatterns()
Initialize all color/symbol sequences.
gazebo::event::ConnectionPtr updateConnection
Connects to rendering update event.
ROSCPP_DECL bool isInitialized()
std::mutex mutex
Locks state and pattern member variables.
ros::Subscriber changeSymbolSub
Service to generate and display a new symbol.
bool ParseSDF(sdf::ElementPtr _sdf)
Parse all SDF parameters.
std::string rosShuffleTopic
ROS topic.
gazebo::transport::NodePtr gzNode
gazebo Node
gazebo::common::Time nextUpdateTime
Next time where the plugin should be updated.
std::string color
The current color.
size_t allPatternsIdx
The index pointing to one of the potential color/symbol sequence.
void ChangeSymbolTo(gazebo::ConstDockPlacardPtr &_msg)
Gazebo callback for changing light to a specific color pattern.
Controls the shape and color of a symbol.
std::vector< std::array< std::string, 2u > > allPatterns
All color/symbol sequences.
std::vector< std::string > visualNames
Collection of visual names.
void Update()
Display the symbol in the placard.
GZ_REGISTER_VISUAL_PLUGIN(GazeboRosVideo)
bool shuffleEnabled
Whether shuffle is enabled via a ROS topic or not.
static std::map< std::string, std_msgs::ColorRGBA > kColors
List of the color options (red, green, blue, and no color) with their string name for logging...
void Load(gazebo::rendering::VisualPtr _parent, sdf::ElementPtr _sdf)
std::string ns
ROS namespace.
std::string symbolSubTopic
gazebo symbol sub topic
std::vector< gazebo::rendering::VisualPtr > visuals
Pointer to the visual elements to modify.
std::string shape
The current shape.
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.
gazebo::transport::SubscriberPtr symbolSub
symbol subscriber
void ChangeSymbol(const std_msgs::Empty::ConstPtr &_msg)
ROS callback for changing a symbol and its color.