@@ -37,6 +37,7 @@ void MPPIController::configure(
3737 // Get high-level controller parameters
3838 auto getParam = parameters_handler_->getParamGetter (name_);
3939 getParam (visualize_, " visualize" , false );
40+ getParam (print_execution_times_," print_execution_times" , false );
4041
4142 // Configure composed objects
4243 optimizer_.initialize (parent_, name_, costmap_ros_, parameters_handler_.get ());
@@ -79,9 +80,11 @@ geometry_msgs::msg::TwistStamped MPPIController::computeVelocityCommands(
7980 const geometry_msgs::msg::Twist & robot_speed,
8081 nav2_core::GoalChecker * goal_checker)
8182{
82- #ifdef BENCHMARK_TESTING
83- auto start = std::chrono::system_clock::now ();
84- #endif
83+ std::chrono::time_point<std::chrono::system_clock> start;
84+ if (print_execution_times_)
85+ {
86+ start = std::chrono::system_clock::now ();
87+ }
8588
8689 std::lock_guard<std::mutex> param_lock (*parameters_handler_->getLock ());
8790 geometry_msgs::msg::Pose goal = path_handler_.getTransformedGoal (robot_pose.header .stamp ).pose ;
@@ -94,11 +97,13 @@ geometry_msgs::msg::TwistStamped MPPIController::computeVelocityCommands(
9497 geometry_msgs::msg::TwistStamped cmd =
9598 optimizer_.evalControl (robot_pose, robot_speed, transformed_plan, goal, goal_checker);
9699
97- #ifdef BENCHMARK_TESTING
98- auto end = std::chrono::system_clock::now ();
99- auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count ();
100- RCLCPP_INFO (logger_, " Control loop execution time: %ld [ms]" , duration);
101- #endif
100+ if (print_execution_times_)
101+ {
102+ auto end = std::chrono::system_clock::now ();
103+ auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count ();
104+ RCLCPP_INFO (logger_, " Control loop execution time: %ld [ms]" , duration);
105+ }
106+
102107
103108 if (visualize_) {
104109 visualize (std::move (transformed_plan), cmd.header .stamp );
0 commit comments