Skip to content

Commit ff505c5

Browse files
committed
Rviz panel clean exit, Fix logging and json dep
1 parent a0e84f4 commit ff505c5

File tree

11 files changed

+56
-25
lines changed

11 files changed

+56
-25
lines changed

roadmap_explorer/CMakeLists.txt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ set(dependencies
5555
eigen3_cmake_module
5656
Eigen3
5757
nav2_behavior_tree
58+
nlohmann_json
5859
)
5960

6061
####################### GET ROS DISTRO ##########################
@@ -259,14 +260,3 @@ if(ament_cmake_gtest_FOUND)
259260
endif()
260261

261262
ament_package()
262-
263-
# ${PROJECT_NAME}_frontier
264-
# ${PROJECT_NAME}_utils
265-
# ${PROJECT_NAME}_frontier_search_plugins
266-
# ${PROJECT_NAME}_information_gain_plugins
267-
# ${PROJECT_NAME}_planner_plugins
268-
# ${PROJECT_NAME}_core
269-
270-
# TODO
271-
# ${PROJECT_NAME}_bt_plugins
272-
# ${PROJECT_NAME}_bt

roadmap_explorer/include/roadmap_explorer/util/Logger.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,22 @@ Attributes Foreground color Background color
8181
// 2 = WARN (warnings only) [DEFAULT]
8282
// 1 = ERROR (errors and critical messages only)
8383
// 0 = FATAL (only fatal errors)
84+
// -1 = HIDE (hide all logs)
8485
//
8586
// TIME_LEVEL: Controls which timing logs are shown
8687
// 2 = Show all timing logs (EVENT, SUBMODULE, MODULE, ITERATION)
8788
// 1 = Show SUBMODULE, MODULE, and ITERATION timing logs
8889
// 0 = Show MODULE and ITERATION timing logs only [DEFAULT]
90+
// -1 = Hide all timing logs
8991
//
9092
// USE_MODULE_FLOW: Enable/disable module flow tracking logs
9193
// true = Show module flow logs [DEFAULT]
9294
// false = Hide module flow logs
9395
// ======================================================================
9496

95-
#define LOG_LEVEL 3
96-
#define TIME_LEVEL 0
97-
#define USE_MODULE_FLOW true
97+
#define LOG_LEVEL 2
98+
#define TIME_LEVEL -1
99+
#define USE_MODULE_FLOW false
98100

99101
////////////////////////////////////////////////////////////////////////////////////////
100102

roadmap_explorer/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<depend>nav2_theta_star_planner</depend>
3232
<depend>nav2_map_server</depend>
3333
<depend>boost</depend>
34-
<depend>nlohmann_json</depend>
34+
<depend>nlohmann-json-dev</depend>
3535

3636
<build_depend>ros_environment</build_depend>
3737

roadmap_explorer/src/ExplorationServer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ nav2_util::CallbackReturn ExplorationServer::on_configure(const rclcpp_lifecycle
4242
{
4343
LOG_INFO("Configured " << get_name());
4444
node_ = shared_from_this();
45-
node_->declare_parameter("localisation_only_mode", false);
45+
46+
nav2_util::declare_parameter_if_not_declared(node_, "localisation_only_mode", rclcpp::ParameterValue(false));
4647
node_->get_parameter("localisation_only_mode", localisation_only_mode_);
4748

4849
return nav2_util::CallbackReturn::SUCCESS;

roadmap_explorer/src/FullPathOptimizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ bool FullPathOptimizer::getNextGoal(
386386
// LOG_ERROR("Could not find local frontiers. Returning a zero frontiers. The program may crash if goal point is checked...");
387387
if (sortedFrontiers.global_frontiers.size() >= 1) {
388388
LOG_WARN(
389-
"Could not find local frontiers. Returning the best global frontier.");
389+
"Global repositioning!! -> Could not find local frontiers. Returning the best global frontier.");
390390
nextFrontier = sortedFrontiers.closest_global_frontier;
391391

392392
nav_msgs::msg::Path globalReposPath;

roadmap_explorer/src/Nav2Interface.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ bool Nav2Interface<ActionT>::sendCancelWaitForResponse(
9292
// Wait for cancel response with timeout (ROS2 recommended approach)
9393
const int timeout_seconds = 5;
9494
int elapsed_seconds = 0;
95-
while (cancel_future.wait_for(std::chrono::seconds(1)) != std::future_status::ready) {
95+
while (cancel_future.wait_for(std::chrono::seconds(1)) != std::future_status::ready && rclcpp::ok()) {
9696
elapsed_seconds++;
9797
LOG_WARN("Waiting for cancel response (" << elapsed_seconds << "/" << timeout_seconds << " seconds)");
9898

@@ -106,7 +106,7 @@ bool Nav2Interface<ActionT>::sendCancelWaitForResponse(
106106

107107
// Wait until the cancel request has been accepted or an error occurs.
108108
auto result = cancel_future.get();
109-
LOG_WARN("Got cancel response");
109+
LOG_INFO("Got cancel response");
110110
if (!result) {
111111
LOG_ERROR("The future response is null");
112112
return false;
@@ -123,7 +123,7 @@ void Nav2Interface<ActionT>::cancelAllGoals()
123123
action_msgs::srv::CancelGoal::Response response;
124124
if (sendCancelWaitForResponse(response)) {
125125
if (response.return_code == action_msgs::srv::CancelGoal::Response::ERROR_NONE) {
126-
LOG_ERROR("Cancellation request accepted by nav2 server. Will cancel the goal.");
126+
LOG_INFO("Cancellation request accepted by nav2 server. Will cancel the goal.");
127127
nav2_goal_state_ = NavGoalStatus::CANCELLING;
128128
} else if (response.return_code == action_msgs::srv::CancelGoal::Response::ERROR_REJECTED) {
129129
LOG_INFO("Cancellation request rejected by Nav2 action server, not cancelling goal");

roadmap_explorer/src/bt_plugins/SearchForFrontiersPlugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace roadmap_explorer
5757
LOG_INFO("Using robot pose: " << robotP.pose.position.x << ", " << robotP.pose.position.y);
5858
std::vector<FrontierPtr> frontier_list;
5959
auto current_frontier_search_distance = config().blackboard->get<double>("current_frontier_search_distance");
60-
LOG_HIGHLIGHT("Current frontier search distance: " << current_frontier_search_distance);
60+
LOG_INFO("Current frontier search distance: " << current_frontier_search_distance);
6161
auto searchResult = frontierSearchPtr_->searchFrom(robotP.pose.position, frontier_list, current_frontier_search_distance);
6262
if (searchResult != FrontierSearchResult::SUCCESSFUL_SEARCH)
6363
{

roadmap_explorer/src/bt_plugins/SendNav2GoalPlugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ namespace roadmap_explorer
107107

108108
void onHalted()
109109
{
110-
LOG_WARN("SendNav2Goal onHalted");
110+
LOG_INFO("SendNav2Goal onHalted");
111111
return;
112112
}
113113

roadmap_explorer/src/information_gain/CountBasedGain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@ double CountBasedGain::setArrivalInformationLimits()
252252
}
253253
arrival_info_limits_set_ = true;
254254
max_arrival_info_gt_ = maxValue * 1.2;
255-
LOG_WARN("Max arrival cost GT: " << max_arrival_info_gt_);
255+
LOG_INFO("Max arrival cost GT: " << max_arrival_info_gt_);
256256
min_arrival_info_gt_ = FACTOR_OF_MAX_IS_MIN_ * max_arrival_info_gt_;
257-
LOG_WARN("Min arrival cost GT: " << min_arrival_info_gt_);
257+
LOG_INFO("Min arrival cost GT: " << min_arrival_info_gt_);
258258
return maxValue;
259259
}
260260
} // namespace roadmap_explorer

roadmap_explorer_rviz_plugins/src/panel.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,46 @@ ExplorationPanel::ExplorationPanel(QWidget * parent)
127127
ros_timer_->start();
128128
}
129129

130+
ExplorationPanel::~ExplorationPanel()
131+
{
132+
// Stop the timer first to prevent any further ROS calls
133+
if (ros_timer_) {
134+
ros_timer_->stop();
135+
}
136+
137+
// Cancel any active goals before shutting down
138+
if (goal_handle_) {
139+
try {
140+
// Don't wait for response during shutdown
141+
action_client_->async_cancel_goal(goal_handle_);
142+
} catch (const std::exception & e) {
143+
// Ignore exceptions during shutdown
144+
}
145+
goal_handle_.reset();
146+
}
147+
148+
// Clean up ROS clients before the node
149+
if (action_client_) {
150+
action_client_.reset();
151+
}
152+
153+
if (save_map_client_) {
154+
save_map_client_.reset();
155+
}
156+
157+
// Finally, clean up the node
158+
if (node_) {
159+
node_.reset();
160+
}
161+
}
162+
130163
void ExplorationPanel::spinnerOnGUI()
131164
{
165+
// Safety check: if node is being destroyed, don't proceed
166+
if (!node_ || !rclcpp::ok()) {
167+
return;
168+
}
169+
132170
rclcpp::spin_some(node_);
133171
if (!action_client_->wait_for_action_server(0ms)) {
134172
updateButtons(ButtonSetting::IN_PROCESS);

0 commit comments

Comments
 (0)