3535#include < nav_msgs/msg/odometry.hpp>
3636#include " turtlebot3_msgs/msg/gaussian.hpp"
3737#include " turtlebot3_msgs/msg/gmm.hpp"
38+ #include < visualization_msgs/msg/marker.hpp>
39+ #include < visualization_msgs/msg/marker_array.hpp>
3840
3941#include " gaussian_mixture_model/gaussian_mixture_model.h"
4042
@@ -68,6 +70,8 @@ class Supervisor : public rclcpp::Node
6870 this ->get_parameter (" NOISE_STD" , NOISE_STD);
6971 this ->declare_parameter <double >(" ENV_SIZE" , 20.0 );
7072 this ->get_parameter (" ENV_SIZE" , ENV_SIZE);
73+ this ->declare_parameter <bool >(" GUI" , false );
74+ this ->get_parameter (" GUI" , GUI);
7175 this ->declare_parameter <bool >(" GRAPHICS_ON" , true );
7276 this ->get_parameter (" GRAPHICS_ON" , GRAPHICS_ON);
7377 // -----------------------------------------------------------------------------------------------------------------------------------
@@ -94,7 +98,7 @@ class Supervisor : public rclcpp::Node
9498 }
9599 }
96100 communication_pub_ = this ->create_publisher <geometry_msgs::msg::Point>(" robot" + std::to_string (ID) + " /communication_topic" , 1 );
97- timer_ = this ->create_wall_timer (2000ms , std::bind (&Supervisor::loop, this ));
101+ timer_ = this ->create_wall_timer (100ms , std::bind (&Supervisor::loop, this ));
98102
99103 // ------------------------------------------------- Initialize GMM and samples -----------------------------------------------------
100104 // Set up random number generator
@@ -132,6 +136,13 @@ class Supervisor : public rclcpp::Node
132136 app_gui.reset (new Graphics{ENV_SIZE, ENV_SIZE, -0.5 *ENV_SIZE, -0.5 *ENV_SIZE, 2.0 });
133137 }
134138
139+ // ------------------------------------------ GUI Publisher ------------------------
140+ if (GUI)
141+ {
142+ SHAPE = visualization_msgs::msg::Marker::SPHERE;
143+ samples_pub_ = this ->create_publisher <visualization_msgs::msg::MarkerArray>(" /gmm_" +std::to_string (ID)+" _samples" , 1 );
144+ }
145+
135146
136147
137148
@@ -151,6 +162,7 @@ class Supervisor : public rclcpp::Node
151162 void neighCallback (const nav_msgs::msg::Odometry::SharedPtr msg, int i);
152163 void communicationCallback (const geometry_msgs::msg::Point::SharedPtr msg, int i);
153164 Eigen::VectorXd addNoise (Eigen::VectorXd point);
165+ void publishSamples ();
154166
155167private:
156168 int ID;
@@ -161,6 +173,7 @@ class Supervisor : public rclcpp::Node
161173 double SENS_RANGE;
162174 double NOISE_STD;
163175 double ENV_SIZE;
176+ bool GUI;
164177 bool GRAPHICS_ON;
165178 GaussianMixtureModel gmm;
166179 std::vector<Eigen::VectorXd> samples;
@@ -174,8 +187,12 @@ class Supervisor : public rclcpp::Node
174187 std::vector<rclcpp::Subscription<nav_msgs::msg::Odometry>::SharedPtr> neighbor_subs_;
175188 rclcpp::Publisher<geometry_msgs::msg::Point>::SharedPtr communication_pub_;
176189 std::vector<rclcpp::Subscription<geometry_msgs::msg::Point>::SharedPtr> communication_subs_;
190+ rclcpp::Publisher<visualization_msgs::msg::MarkerArray>::SharedPtr samples_pub_;
177191 rclcpp::TimerBase::SharedPtr timer_;
178192
193+ visualization_msgs::msg::MarkerArray marker_msg;
194+ uint32_t SHAPE;
195+
179196 // Rendering with SFML
180197 // ------------------------------ graphics window -------------------------------------
181198 std::unique_ptr<Graphics> app_gui;
@@ -236,6 +253,31 @@ void Supervisor::communicationCallback(const geometry_msgs::msg::Point::SharedPt
236253 }
237254}
238255
256+ void Supervisor::publishSamples ()
257+ {
258+ for (int i = 0 ; i < samples.size (); i++)
259+ {
260+ visualization_msgs::msg::Marker m;
261+ m.id = i;
262+ m.header .frame_id = " odom" ;
263+ m.type = SHAPE;
264+ m.action = visualization_msgs::msg::Marker::ADD;
265+ m.pose .position .x = samples[i](0 );
266+ m.pose .position .y = samples[i](1 );
267+ m.pose .position .z = 0.0 ;
268+ m.scale .x = 0.05 ;
269+ m.scale .y = 0.05 ;
270+ m.scale .z = 0.05 ;
271+ m.color .r = 0 .0f ;
272+ m.color .g = 1 .0f ;
273+ m.color .b = 0 .0f ;
274+ m.color .a = 0.5 ; // alpha is given by its weight
275+ this ->marker_msg .markers .push_back (m);
276+ }
277+
278+ this ->samples_pub_ ->publish (this ->marker_msg );
279+ }
280+
239281Eigen::VectorXd Supervisor::addNoise (Eigen::VectorXd point)
240282{
241283 // Generate random inputs
@@ -251,6 +293,8 @@ Eigen::VectorXd Supervisor::addNoise(Eigen::VectorXd point)
251293 return noisy_point;
252294}
253295
296+
297+
254298void Supervisor::loop ()
255299{
256300 auto timerstart = std::chrono::high_resolution_clock::now ();
@@ -298,6 +342,11 @@ void Supervisor::loop()
298342
299343 this ->gmm_pub_ ->publish (gmm_msg);
300344
345+ if (GUI)
346+ {
347+ publishSamples ();
348+ }
349+
301350 if ((GRAPHICS_ON) && (this ->app_gui ->isOpen ()))
302351 {
303352 this ->app_gui ->clear ();
0 commit comments