@@ -65,9 +65,14 @@ class RealtimePublisher
6565 // / The msg_ variable contains the data that will get published on the ROS topic.
6666 MessageT msg_;
6767
68- /* * \brief Constructor for the realtime publisher
68+ /* *
69+ * \brief Constructor for the realtime publisher
6970 *
70- * \param publisher the publisher to wrap
71+ * Starts a dedicated thread for message publishing.
72+ * The publishing thread runs the publishingLoop() function to handle message
73+ * delivery in a non-realtime context.
74+ *
75+ * \param publisher the ROS publisher to wrap
7176 */
7277 explicit RealtimePublisher (PublisherSharedPtr publisher)
7378 : publisher_(publisher), is_running_(false ), keep_running_(true ), turn_(State::LOOP_NOT_STARTED)
@@ -95,7 +100,13 @@ class RealtimePublisher
95100 }
96101 }
97102
98- // / Stop the realtime publisher from sending out more ROS messages
103+ /* *
104+ * \brief Stop the realtime publisher
105+ *
106+ * Signals the publishing thread to exit by setting keep_running_ to false
107+ * and notifying the condition variable. This allows the publishing loop
108+ * to break out of its wait state and exit cleanly.
109+ */
99110 void stop ()
100111 {
101112 keep_running_ = false ;
@@ -104,12 +115,14 @@ class RealtimePublisher
104115#endif
105116 }
106117
107- /* * \brief Try to get the data lock from realtime
108- *
109- * To publish data from the realtime loop, you need to run trylock to
110- * attempt to get unique access to the msg_ variable. Trylock returns
111- * true if the lock was acquired, and false if it failed to get the lock.
112- */
118+ /* *
119+ * \brief Try to acquire the data lock for non-realtime message publishing
120+ *
121+ * It first checks if the current state allows non-realtime message publishing (turn_ == NON_REALTIME)
122+ * and then attempts to lock
123+ *
124+ * \return true if the lock was successfully acquired, false otherwise
125+ */
113126 bool trylock ()
114127 {
115128 if (msg_mutex_.try_lock ()) {
@@ -124,11 +137,14 @@ class RealtimePublisher
124137 }
125138 }
126139
127- /* * \brief Try to get the data lock from realtime and publish the given message
140+ /* *
141+ * \brief Try to get the data lock from realtime and publish the given message
128142 *
129143 * Tries to gain unique access to msg_ variable. If this succeeds
130144 * update the msg_ variable and call unlockAndPublish
131- * @return false in case no lock for the realtime variable could be acquired
145+ *
146+ * \param [in] msg The message to publish
147+ * \return false in case no lock for the realtime variable is acquired. This implies the message will not be published.
132148 */
133149 bool tryPublish (const MessageT & msg)
134150 {
@@ -141,7 +157,8 @@ class RealtimePublisher
141157 return true ;
142158 }
143159
144- /* * \brief Unlock the msg_ variable
160+ /* *
161+ * \brief Unlock the msg_ variable for the non-realtime thread to start publishing
145162 *
146163 * After a successful trylock and after the data is written to the mgs_
147164 * variable, the lock has to be released for the message to get
@@ -153,11 +170,11 @@ class RealtimePublisher
153170 unlock ();
154171 }
155172
156- /* * \brief Get the data lock form non-realtime
173+ /* *
174+ * \brief Acquire the data lock
157175 *
158- * To publish data from the realtime loop, you need to run trylock to
159- * attempt to get unique access to the msg_ variable. Trylock returns
160- * true if the lock was acquired, and false if it failed to get the lock.
176+ * This blocking call acquires exclusive access to the msg_ variable.
177+ * Use trylock() for non-blocking attempts to acquire the lock.
161178 */
162179 void lock ()
163180 {
@@ -171,7 +188,8 @@ class RealtimePublisher
171188#endif
172189 }
173190
174- /* * \brief Unlocks the data without publishing anything
191+ /* *
192+ * \brief Unlocks the data without publishing anything
175193 *
176194 */
177195 void unlock ()
@@ -189,6 +207,17 @@ class RealtimePublisher
189207
190208 bool is_running () const { return is_running_; }
191209
210+ /* *
211+ * \brief Publishing loop (runs in separate thread)
212+ *
213+ * This is the main loop for the non-realtime publishing thread. It:
214+ * 1. Waits for new messages (State::REALTIME)
215+ * 2. Copies the message data
216+ * 3. Publishes the message through the ROS publisher
217+ * 4. Returns to State::NON_REALTIME to allow realtime updates
218+ *
219+ * The loop continues until keep_running_ is set to false.
220+ */
192221 void publishingLoop ()
193222 {
194223 is_running_ = true ;
0 commit comments