Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct Trajectories
Eigen::ArrayXXf x;
Eigen::ArrayXXf y;
Eigen::ArrayXXf yaws;
Eigen::ArrayXf costs;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could make this a reference that points to costs_ (just would need a constructor and pass it in). I didn't trace this completely to know if this is neat in terms of where Trajectories is constructed, but it would be preferable so that we didn't have that huge copy

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also accept another solution that doesn't involve copying the costs vector around. Its quite large.


/**
* @brief Reset state data
Expand Down
1 change: 1 addition & 0 deletions nav2_mppi_controller/src/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ void Optimizer::optimize()
generateNoisedTrajectories();
critic_manager_.evalTrajectoriesScores(critics_data_);
updateControlSequence();
generated_trajectories_.costs = costs_;
}
}

Expand Down
19 changes: 18 additions & 1 deletion nav2_mppi_controller/src/trajectory_visualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@ void TrajectoryVisualizer::add(
const float shape_1 = static_cast<float>(n_cols);
points_->markers.reserve(floor(n_rows / trajectory_step_) * floor(n_cols * time_step_));

std::vector<std::pair<size_t, float>> sorted_costs;
sorted_costs.reserve(std::ceil(n_rows / trajectory_step_));

for (size_t i = 0; i < n_rows; i += trajectory_step_) {
sorted_costs.emplace_back(i, trajectories.costs(i));
}
std::sort(sorted_costs.begin(), sorted_costs.end(),
[](const auto & a, const auto & b) {return a.second < b.second;});

const float step = 1.0f / static_cast<float>(sorted_costs.size());
float color_component = 1.0f;
std::map<size_t, float> cost_color_map;
for (const auto & pair : sorted_costs) {
cost_color_map[pair.first] = color_component;
color_component -= step;
}

for (size_t i = 0; i < n_rows; i += trajectory_step_) {
for (size_t j = 0; j < n_cols; j += time_step_) {
const float j_flt = static_cast<float>(j);
Expand All @@ -119,7 +136,7 @@ void TrajectoryVisualizer::add(

auto pose = utils::createPose(trajectories.x(i, j), trajectories.y(i, j), 0.03);
auto scale = utils::createScale(0.03, 0.03, 0.03);
auto color = utils::createColor(0, green_component, blue_component, 1);
auto color = utils::createColor(cost_color_map[i], green_component, blue_component, 1);
auto marker = utils::createMarker(
marker_id_++, pose, scale, color, frame_id_, marker_namespace);

Expand Down
Loading