2121#include < mrpt/nav/reactive/CLogFileRecord.h>
2222#include < mrpt/nav/reactive/CMultiObjectiveMotionOptimizerBase.h>
2323#include < mrpt/nav/reactive/CWaypointsNavigator.h>
24+ #include < mrpt/nav/reactive/NavigationLogger.h>
2425#include < mrpt/nav/reactive/TCandidateMovementPTG.h>
26+ #include < mrpt/nav/reactive/VelocityFilter.h>
2527#include < mrpt/nav/tpspace/CParameterizedTrajectoryGenerator.h>
2628#include < mrpt/system/CTimeLogger.h>
2729#include < mrpt/system/datetime.h>
@@ -152,18 +154,22 @@ class CAbstractPTGBasedReactive : public CWaypointsNavigator
152154 * \note Log records are not prepared unless either "enableLogFile" is
153155 * enabled in the constructor or "enableLogFile()" has been called.
154156 */
155- void getLastLogRecord (CLogFileRecord& o);
157+ void getLastLogRecord (CLogFileRecord& o) { m_navLogger. getLastLogRecord (o); }
156158
157159 /* * Enables keeping an internal registry of navigation logs that can be
158160 * queried with getLastLogRecord() */
159- void enableKeepLogRecords (bool enable = true ) { m_enableKeepLogRecords = enable; }
161+ void enableKeepLogRecords (bool enable = true ) { m_navLogger. enableKeepLogRecords ( enable) ; }
160162
161163 /* * Enables/disables saving log files. */
162164 void enableLogFile (bool enable);
163165
164166 /* * Changes the prefix for new log files. */
165- void setLogFileDirectory (const std::string& sDir ) { m_navlogfiles_dir = sDir ; }
166- std::string getLogFileDirectory () const { return m_navlogfiles_dir; }
167+ void setLogFileDirectory (const std::string& sDir ) { m_navLogger.setLogFileDirectory (sDir ); }
168+ [[nodiscard]] std::string getLogFileDirectory () const
169+ {
170+ return m_navLogger.getLogFileDirectory ();
171+ }
172+
167173 struct TAbstractPTGNavigatorParams : public mrpt ::config::CLoadableOptions
168174 {
169175 /* * C++ class name of the holonomic navigation method to run in the
@@ -273,18 +279,12 @@ class CAbstractPTGBasedReactive : public CWaypointsNavigator
273279 /* * The holonomic navigation algorithm (one object per PTG, so internal
274280 * states are maintained) */
275281 std::vector<CAbstractHolonomicReactiveMethod::Ptr> m_holonomicMethod;
276- std::unique_ptr<mrpt::io::CStream> m_logFile;
277- /* * The current log file stream, or nullptr if not being used */
278- mrpt::io::CStream* m_prev_logfile{nullptr };
279- /* * See enableKeepLogRecords */
280- bool m_enableKeepLogRecords{false };
281- /* * The last log */
282- CLogFileRecord lastLogRecord;
283- /* * Last velocity commands */
284- mrpt::kinematics::CVehicleVelCmd::Ptr m_last_vel_cmd;
285-
286- /* * Critical zones */
287- std::recursive_mutex m_critZoneLastLog;
282+
283+ /* * Navigation log file manager */
284+ NavigationLogger m_navLogger;
285+
286+ /* * Velocity command filtering and last-sent-command tracking */
287+ VelocityFilter m_velFilter;
288288
289289 /* * Enables / disables the console debug output. */
290290 bool m_enableConsoleOutput;
@@ -368,9 +368,11 @@ class CAbstractPTGBasedReactive : public CWaypointsNavigator
368368 const mrpt::system::TTimeStamp tim_start_iteration,
369369 const mrpt::nav::CHolonomicLogFileRecord::Ptr& hlfr);
370370
371- /* * Return the [0,1] velocity scale of raw PTG cmd_vel */
371+ /* * Return the [0,1] velocity scale of raw PTG cmd_vel.
372+ * Delegates to VelocityFilter. */
372373 virtual double generate_vel_cmd (
373374 const TCandidateMovementPTG& in_movement, mrpt::kinematics::CVehicleVelCmd::Ptr& new_vel_cmd);
375+
374376 void generateLogRecord (
375377 CLogFileRecord& newLogRec,
376378 const std::vector<mrpt::math::TPose2D>& relTargets,
@@ -432,7 +434,7 @@ class CAbstractPTGBasedReactive : public CWaypointsNavigator
432434 TSentVelCmd () = default ;
433435
434436 void reset () { *this = TSentVelCmd (); }
435- bool isValid () const { return this ->poseVel .timestamp != INVALID_TIMESTAMP; }
437+ [[nodiscard]] bool isValid () const { return this ->poseVel .timestamp != INVALID_TIMESTAMP; }
436438 /* * 0-based index of used PTG */
437439 int ptg_index = -1 ;
438440 /* * Path index for selected PTG */
@@ -457,9 +459,6 @@ class CAbstractPTGBasedReactive : public CWaypointsNavigator
457459 /* * Delete m_holonomicMethod */
458460 void deleteHolonomicObjects ();
459461
460- /* * Default: "./reactivenav.logs" */
461- std::string m_navlogfiles_dir;
462-
463462 double m_expr_var_k, m_expr_var_k_target, m_expr_var_num_paths;
464463 /* * A copy of last-iteration navparams, used to detect changes */
465464 std::unique_ptr<TNavigationParams> m_copy_prev_navParams;
0 commit comments