Skip to content

Commit d1092e7

Browse files
committed
lint
Signed-off-by: Tony Najjar <[email protected]>
1 parent 8ab4228 commit d1092e7

File tree

4 files changed

+85
-77
lines changed

4 files changed

+85
-77
lines changed

nav2_mppi_controller/src/critic_manager.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ void CriticManager::getParams()
3737
auto node = parent_.lock();
3838
auto getParam = parameters_handler_->getParamGetter(name_);
3939
getParam(critic_names_, "critics", std::vector<std::string>{}, ParameterType::Static);
40-
40+
4141
// Read visualization parameters from Visualization namespace
4242
auto getVisualizerParam = parameters_handler_->getParamGetter(name_ + ".Visualization");
4343
getVisualizerParam(publish_critics_stats_, "publish_critics_stats", false, ParameterType::Static);
44-
getVisualizerParam(visualize_per_critic_costs_, "publish_trajectories_with_individual_cost", false, ParameterType::Static);
44+
getVisualizerParam(visualize_per_critic_costs_, "publish_trajectories_with_individual_cost",
45+
false, ParameterType::Static);
4546
}
4647

4748
void CriticManager::loadCritics()
@@ -112,7 +113,7 @@ void CriticManager::evalTrajectoriesScores(
112113
// Calculate cost contribution from this critic
113114
if (visualize_per_critic_costs_ || publish_critics_stats_) {
114115
Eigen::ArrayXf cost_diff = data.costs - costs_before;
115-
116+
116117
if (visualize_per_critic_costs_) {
117118
data.individual_critics_cost->emplace_back(critic_names_[i], cost_diff);
118119
}

nav2_mppi_controller/src/trajectory_visualizer.cpp

Lines changed: 69 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ void TrajectoryVisualizer::on_configure(
4040
getParam(time_step_, "time_step", 3);
4141
getParam(publish_optimal_trajectory_, "publish_optimal_trajectory", false);
4242
getParam(publish_trajectories_with_total_cost_, "publish_trajectories_with_total_cost", false);
43-
getParam(publish_trajectories_with_individual_cost_, "publish_trajectories_with_individual_cost", false);
43+
getParam(publish_trajectories_with_individual_cost_, "publish_trajectories_with_individual_cost",
44+
false);
4445

4546
reset();
4647
}
@@ -115,9 +116,9 @@ void TrajectoryVisualizer::add(
115116
const builtin_interfaces::msg::Time & cmd_stamp)
116117
{
117118
// Check if we should visualize per-critic costs
118-
bool visualize_per_critic = !individual_critics_cost.empty() &&
119-
publish_trajectories_with_individual_cost_ &&
120-
trajectories_publisher_->get_subscription_count() > 0;
119+
bool visualize_per_critic = !individual_critics_cost.empty() &&
120+
publish_trajectories_with_individual_cost_ &&
121+
trajectories_publisher_->get_subscription_count() > 0;
121122

122123
size_t n_rows = trajectories.x.rows();
123124
size_t n_cols = trajectories.x.cols();
@@ -128,91 +129,91 @@ void TrajectoryVisualizer::add(
128129
const Eigen::ArrayXf & costs,
129130
const std::string & ns,
130131
bool use_collision_coloring) {
131-
132+
132133
// Find min/max cost for normalization
133-
float min_cost = std::numeric_limits<float>::max();
134-
float max_cost = std::numeric_limits<float>::lowest();
135-
136-
for (Eigen::Index i = 0; i < costs.size(); ++i) {
134+
float min_cost = std::numeric_limits<float>::max();
135+
float max_cost = std::numeric_limits<float>::lowest();
136+
137+
for (Eigen::Index i = 0; i < costs.size(); ++i) {
137138
// Skip collision trajectories for min/max calculation if using collision coloring
138-
if (use_collision_coloring && costs(i) >= 1000000.0f) {
139-
continue;
139+
if (use_collision_coloring && costs(i) >= 1000000.0f) {
140+
continue;
141+
}
142+
min_cost = std::min(min_cost, costs(i));
143+
max_cost = std::max(max_cost, costs(i));
140144
}
141-
min_cost = std::min(min_cost, costs(i));
142-
max_cost = std::max(max_cost, costs(i));
143-
}
144-
145-
float cost_range = max_cost - min_cost;
146-
145+
146+
float cost_range = max_cost - min_cost;
147+
147148
// Avoid division by zero
148-
if (cost_range < 1e-6f) {
149-
cost_range = 1.0f;
150-
}
149+
if (cost_range < 1e-6f) {
150+
cost_range = 1.0f;
151+
}
151152

152-
for (size_t i = 0; i < n_rows; i += trajectory_step_) {
153-
float red_component, green_component, blue_component;
153+
for (size_t i = 0; i < n_rows; i += trajectory_step_) {
154+
float red_component, green_component, blue_component;
154155

155156
// Check if this trajectory is in collision (cost >= 1000000)
156-
bool in_collision = use_collision_coloring && costs(i) >= 1000000.0f;
157-
157+
bool in_collision = use_collision_coloring && costs(i) >= 1000000.0f;
158+
158159
// Check if cost is zero (no contribution from this critic)
159-
bool zero_cost = std::abs(costs(i)) < 1e-6f;
160-
161-
if (in_collision) {
160+
bool zero_cost = std::abs(costs(i)) < 1e-6f;
161+
162+
if (in_collision) {
162163
// Fixed red color for collision trajectories
163-
red_component = 1.0f;
164-
green_component = 0.0f;
165-
blue_component = 0.0f;
166-
} else if (zero_cost) {
164+
red_component = 1.0f;
165+
green_component = 0.0f;
166+
blue_component = 0.0f;
167+
} else if (zero_cost) {
167168
// Gray color for zero cost (no contribution)
168-
red_component = 0.5f;
169-
green_component = 0.5f;
170-
blue_component = 0.5f;
171-
} else {
169+
red_component = 0.5f;
170+
green_component = 0.5f;
171+
blue_component = 0.5f;
172+
} else {
172173
// Normal gradient for non-collision trajectories
173-
float normalized_cost = (costs(i) - min_cost) / cost_range;
174-
normalized_cost = std::clamp(normalized_cost, 0.0f, 1.0f);
174+
float normalized_cost = (costs(i) - min_cost) / cost_range;
175+
normalized_cost = std::clamp(normalized_cost, 0.0f, 1.0f);
175176

176177
// Color scheme: Green (low cost) -> Yellow -> Red (high cost)
177-
blue_component = 0.0f;
178-
if (normalized_cost < 0.5f) {
178+
blue_component = 0.0f;
179+
if (normalized_cost < 0.5f) {
179180
// Green to Yellow (0.0 - 0.5)
180-
red_component = normalized_cost * 2.0f;
181-
green_component = 1.0f;
182-
} else {
181+
red_component = normalized_cost * 2.0f;
182+
green_component = 1.0f;
183+
} else {
183184
// Yellow to Red (0.5 - 1.0)
184-
red_component = 1.0f;
185-
green_component = 2.0f * (1.0f - normalized_cost);
185+
red_component = 1.0f;
186+
green_component = 2.0f * (1.0f - normalized_cost);
187+
}
186188
}
187-
}
188189

189190
// Create line strip marker for this trajectory
190-
visualization_msgs::msg::Marker marker;
191-
marker.header.frame_id = frame_id_;
192-
marker.header.stamp = cmd_stamp;
193-
marker.ns = ns;
194-
marker.id = marker_id_++;
195-
marker.type = visualization_msgs::msg::Marker::LINE_STRIP;
196-
marker.action = visualization_msgs::msg::Marker::ADD;
197-
marker.pose.orientation.w = 1.0;
198-
marker.scale.x = 0.01; // Line width
199-
marker.color.r = red_component;
200-
marker.color.g = green_component;
201-
marker.color.b = blue_component;
202-
marker.color.a = 1.0;
191+
visualization_msgs::msg::Marker marker;
192+
marker.header.frame_id = frame_id_;
193+
marker.header.stamp = cmd_stamp;
194+
marker.ns = ns;
195+
marker.id = marker_id_++;
196+
marker.type = visualization_msgs::msg::Marker::LINE_STRIP;
197+
marker.action = visualization_msgs::msg::Marker::ADD;
198+
marker.pose.orientation.w = 1.0;
199+
marker.scale.x = 0.01; // Line width
200+
marker.color.r = red_component;
201+
marker.color.g = green_component;
202+
marker.color.b = blue_component;
203+
marker.color.a = 1.0;
203204

204205
// Add all points in this trajectory to the line strip
205-
for (size_t j = 0; j < n_cols; j += time_step_) {
206-
geometry_msgs::msg::Point point;
207-
point.x = trajectories.x(i, j);
208-
point.y = trajectories.y(i, j);
209-
point.z = 0.0f;
210-
marker.points.push_back(point);
206+
for (size_t j = 0; j < n_cols; j += time_step_) {
207+
geometry_msgs::msg::Point point;
208+
point.x = trajectories.x(i, j);
209+
point.y = trajectories.y(i, j);
210+
point.z = 0.0f;
211+
marker.points.push_back(point);
212+
}
213+
214+
points_->markers.push_back(marker);
211215
}
212-
213-
points_->markers.push_back(marker);
214-
}
215-
};
216+
};
216217

217218
// If visualizing per-critic costs
218219
if (visualize_per_critic) {

nav2_mppi_controller/test/critic_manager_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ TEST(CriticManagerTests, BasicCriticOperations)
114114
Eigen::ArrayXf costs;
115115
float model_dt = 0.1;
116116
CriticData data =
117-
{state, generated_trajectories, path, goal, costs, std::nullopt, model_dt, false, nullptr, nullptr,
117+
{state, generated_trajectories, path, goal, costs, std::nullopt, model_dt, false, nullptr,
118+
nullptr,
118119
std::nullopt, std::nullopt};
119120

120121
data.fail_flag = true;

nav2_mppi_controller/test/utils_test.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ TEST(UtilsTests, FurthestAndClosestReachedPoint)
181181
float model_dt = 0.1;
182182

183183
CriticData data =
184-
{state, generated_trajectories, path, goal, costs, std::nullopt, model_dt, false, nullptr, nullptr,
184+
{state, generated_trajectories, path, goal, costs, std::nullopt, model_dt, false, nullptr,
185+
nullptr,
185186
std::nullopt, std::nullopt}; /// Caution, keep references
186187

187188
// Attempt to set furthest point if notionally set, should not change
@@ -191,7 +192,8 @@ TEST(UtilsTests, FurthestAndClosestReachedPoint)
191192

192193
// Attempt to set if not set already with no other information, should fail
193194
CriticData data2 =
194-
{state, generated_trajectories, path, goal, costs, std::nullopt, model_dt, false, nullptr, nullptr,
195+
{state, generated_trajectories, path, goal, costs, std::nullopt, model_dt, false, nullptr,
196+
nullptr,
195197
std::nullopt, std::nullopt}; /// Caution, keep references
196198
setPathFurthestPointIfNotSet(data2);
197199
EXPECT_EQ(data2.furthest_reached_path_point, 0);
@@ -210,7 +212,8 @@ TEST(UtilsTests, FurthestAndClosestReachedPoint)
210212
path = toTensor(plan);
211213

212214
CriticData data3 =
213-
{state, generated_trajectories, path, goal, costs, std::nullopt, model_dt, false, nullptr, nullptr,
215+
{state, generated_trajectories, path, goal, costs, std::nullopt, model_dt, false, nullptr,
216+
nullptr,
214217
std::nullopt, std::nullopt}; /// Caution, keep references
215218
EXPECT_EQ(findPathFurthestReachedPoint(data3), 5);
216219
}
@@ -226,7 +229,8 @@ TEST(UtilsTests, findPathCosts)
226229
float model_dt = 0.1;
227230

228231
CriticData data =
229-
{state, generated_trajectories, path, goal, costs, std::nullopt, model_dt, false, nullptr, nullptr,
232+
{state, generated_trajectories, path, goal, costs, std::nullopt, model_dt, false, nullptr,
233+
nullptr,
230234
std::nullopt, std::nullopt}; /// Caution, keep references
231235

232236
// Test not set if already set, should not change
@@ -239,7 +243,8 @@ TEST(UtilsTests, findPathCosts)
239243
EXPECT_EQ(data.path_pts_valid->size(), 10u);
240244

241245
CriticData data3 =
242-
{state, generated_trajectories, path, goal, costs, std::nullopt, model_dt, false, nullptr, nullptr,
246+
{state, generated_trajectories, path, goal, costs, std::nullopt, model_dt, false, nullptr,
247+
nullptr,
243248
std::nullopt, std::nullopt}; /// Caution, keep references
244249

245250
auto costmap_ros = std::make_shared<nav2_costmap_2d::Costmap2DROS>(

0 commit comments

Comments
 (0)