19 #include <gazebo/physics/Model.hh> 20 #include <ignition/math/Rand.hh> 32 const double _g,
const double _b,
const double _a)
34 static std_msgs::ColorRGBA color;
50 {
"circle",
"cross",
"triangle"};
56 GZ_ASSERT(_parent !=
nullptr,
"Received NULL model pointer");
66 std::string modelName = _parent->GetName();
67 auto delim = modelName.find(
":");
68 if (delim != std::string::npos)
69 modelName = modelName.substr(0, delim);
72 std::string ns = modelName;
73 if (_sdf->HasElement(
"robotNamespace"))
74 ns = _sdf->GetElement(
"robotNamespace")->Get<std::string>();
78 "missing <robotNamespace>, defaulting to %s", ns.c_str());
83 if (_sdf->HasElement(
"shape"))
85 std::string aShape = _sdf->GetElement(
"shape")->Get<std::string>();
86 std::transform(aShape.begin(), aShape.end(), aShape.begin(), ::tolower);
88 if (std::find(this->
kShapes.begin(), this->
kShapes.end(), aShape) !=
96 "incorrect [%s] <shape>, using random shape", aShape.c_str());
102 if (_sdf->HasElement(
"color"))
104 std::string aColor = _sdf->GetElement(
"color")->Get<std::string>();
105 std::transform(aColor.begin(), aColor.end(), aColor.begin(), ::tolower);
109 this->
color = aColor;
114 "incorrect [%s] <color>, using random color", aColor.c_str());
121 auto iterShapes = this->
kShapes.begin();
122 for (
auto i = 0; i < this->
kShapes.size(); ++i)
124 std::string topic = *iterShapes;
125 std::advance(iterShapes, 1);
127 this->nh.advertise<std_msgs::ColorRGBA>(topic, 1u,
true));
132 this->
timer = this->nh.createTimer(
142 std_srvs::Trigger::Response &_res)
160 std::string newShape;
164 this->
kShapes[ignition::math::Rand::IntUniform(0,
167 while (newShape == this->
shape);
168 this->
shape = newShape;
174 std::string newColor;
177 auto iterColor = this->
kColors.begin();
178 std::advance(iterColor,
179 ignition::math::Rand::IntUniform(0, this->
kColors.size() - 1));
180 newColor = (*iterColor).first;
182 while (newColor == this->
color);
183 this->
color = newColor;
195 for (
auto i = 0; i < this->
kShapes.size(); ++i)
197 std_msgs::ColorRGBA
msg;
201 auto delim = topic.rfind(
"/");
202 auto aShape = topic.substr(delim + 1);
203 if (aShape == this->
shape)
GZ_REGISTER_MODEL_PLUGIN(GazeboRosElevator)
std::string color
The current color.
void Shuffle()
Create a new combination of shape/color.
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.
#define ROS_INFO_NAMED(name,...)
ros::NodeHandle nh
Node handle.
ROSCPP_DECL bool isInitialized()
virtual void Load(gazebo::physics::ModelPtr _parent, sdf::ElementPtr _sdf)
std::vector< ros::Publisher > symbolPubs
Publisher to set the color to each of the 3 potential shapes.
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...
#define ROS_DEBUG_NAMED(name,...)
void ShuffleColor()
Choose a new random color.
Controls the shape and color of a symbol.
std::string shape
The current shape.
static std::vector< std::string > kShapes
List of the shape options (circle, cross, triangle) with their string name for logging.
ros::Timer timer
Timer triggered in simulated time to update the shape/color for.
ros::ServiceServer changePatternServer
Service to generate a new random shape/color.
void Publish()
Publish the current shape/color combination.
void ShuffleShape()
Choose a new random shape.