11#include " WebGUI.hpp"
22#include " Map.hpp"
33#include " common_interfaces_cpp/webgui/WebGUIBridge.hpp"
4+ #include " common_interfaces_cpp/webgui/RTFMonitor.hpp"
45#include " common_interfaces_cpp/hal/odometry.hpp"
56#include " geometry_msgs/msg/point.hpp"
67#include " nav_msgs/msg/path.hpp"
@@ -19,6 +20,8 @@ class WebGUINode : public BaseWebGUI
1920 : BaseWebGUI(" webgui_node" , " 127.0.0.1" , " 2303" , 30.0 )
2021 , image_updated_(false )
2122 , last_image_payload_(" {\" image\" :\"\" ,\" shape\" :[]}" )
23+ , gui_iterations_(0 )
24+ , rtf_monitor_(" /stats" , std::chrono::milliseconds(500 ))
2225 , map_util_([this ](){ return odom_node_->getPose3d (); })
2326 {
2427 odom_node_ = std::make_shared<OdometryNode>(" /odom" , " webgui_odom" );
@@ -48,6 +51,11 @@ class WebGUINode : public BaseWebGUI
4851 }
4952 show_path (path);
5053 });
54+
55+ last_stat_time_ = std::chrono::steady_clock::now ();
56+ stats_timer_ = this ->create_wall_timer (
57+ std::chrono::milliseconds (500 ),
58+ std::bind (&WebGUINode::send_stats, this ));
5159 }
5260
5361 std::vector<rclcpp::Node::SharedPtr> get_internal_nodes () {
@@ -87,6 +95,8 @@ class WebGUINode : public BaseWebGUI
8795
8896protected:
8997 json update_gui () override {
98+ gui_iterations_++;
99+
90100 json inner;
91101 inner[" image" ] = encode_image ();
92102
@@ -133,6 +143,26 @@ class WebGUINode : public BaseWebGUI
133143 }
134144
135145private:
146+ void send_stats () {
147+ auto now = std::chrono::steady_clock::now ();
148+ std::chrono::duration<double > elapsed = now - last_stat_time_;
149+
150+ double current_freq = 0.0 ;
151+ if (elapsed.count () > 0.0 ) {
152+ current_freq = gui_iterations_.exchange (0 ) / elapsed.count ();
153+ }
154+ last_stat_time_ = now;
155+
156+ json stats;
157+ stats[" brain" ] = std::round (current_freq * 10.0 ) / 10.0 ;
158+ stats[" gui" ] = 30.0 ;
159+ stats[" rtf" ] = rtf_monitor_.get ();
160+ stats[" fps" ] = -1.0 ;
161+ stats[" lat" ] = -1.0 ;
162+
163+ send_to_frontend (stats);
164+ }
165+
136166 std::string encode_image () {
137167 cv::Mat local;
138168 {
@@ -182,6 +212,11 @@ class WebGUINode : public BaseWebGUI
182212 std::mutex target_mtx_;
183213
184214 Map map_util_;
215+
216+ RTFMonitor rtf_monitor_;
217+ rclcpp::TimerBase::SharedPtr stats_timer_;
218+ std::atomic<int > gui_iterations_;
219+ std::chrono::time_point<std::chrono::steady_clock> last_stat_time_;
185220};
186221
187222std::shared_ptr<WebGUINode> WebGUI::gui_node_ = nullptr ;
0 commit comments