forked from ros-navigation/navigation2
-
Notifications
You must be signed in to change notification settings - Fork 0
Reduce MPPI computation time, add OpenMP support #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
adivardi
wants to merge
32
commits into
enway-devel
Choose a base branch
from
av/mppi_freq
base: enway-devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
f5b9121
improve comment a bit
adivardi 34c8540
Use pruned path length for path occupancy check
adivardi 6ac0699
[clean] use a fixed distance for occupancy check
adivardi 78bec14
parameterize & vis occupancy check distance
adivardi 9d3f149
Use max(distance, furthest_reached) for occupancy check
adivardi 5302234
First version of direction change critic
adivardi fe6468b
Refactor direction change critic
adivardi 680eed1
Update DirectionChangeCritic after rebase
adivardi 3daf035
DirectionChangeCritic: test use robot speed or last_cmd_published
adivardi f564a5c
DirectionChangeCritic: use robot speed from feedback
adivardi 8f875aa
DirectionChangeCritic: rm todo to penalize wz
adivardi 6659ba8
fix comment
adivardi 809d679
break long lines
adivardi afd3190
fix line indentations
adivardi 240676c
Add comments to PathAlign
adivardi b6a9d58
add namespace critics to critics topics
adivardi 59c0ffe
Add timing prints
adivardi a515e52
fix typo
adivardi 1285552
[tmp] add metrics to costCritic
adivardi 124dd76
CostCritic: get collision only once
adivardi c08ec44
[tmp] cleaner count footprint checks
adivardi 2137d3f
early exit if center is in collision
adivardi c78e04f
CostCritic: check collisions backwards
adivardi 109d2ca
Clamp exponential arguments
adivardi 6d7992c
Add noalias to matrix multiplication
adivardi 3e230ba
[print] fix missing fp checks value
adivardi 7cdcc1f
[tmp] rm metrics from CostCritic
adivardi 8eb3b51
CostCritic: Add OpenMP with 4 threads
adivardi 6b33b0d
Add flag to disable/enable openMP & a param to set no. of threads
adivardi 9d9d810
Revert "Add timing prints"
adivardi 333a28f
break long line
adivardi 0485587
update license year
adivardi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
nav2_mppi_controller/include/nav2_mppi_controller/critics/direction_change_critic.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // Copyright (c) 2026 Enway GmbH, Adi Vardi | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #ifndef NAV2_MPPI_CONTROLLER__CRITICS__DIRECTION_CHANGE_CRITIC_HPP_ | ||
| #define NAV2_MPPI_CONTROLLER__CRITICS__DIRECTION_CHANGE_CRITIC_HPP_ | ||
|
|
||
| #include "nav2_mppi_controller/critic_function.hpp" | ||
| #include "nav2_mppi_controller/tools/utils.hpp" | ||
|
|
||
| namespace mppi::critics | ||
| { | ||
|
|
||
| /** | ||
| * @class mppi::critics::DirectionChangeCritic | ||
| * @brief Critic objective function for penalizing changes in driving direction. | ||
| */ | ||
| class DirectionChangeCritic : public CriticFunction | ||
| { | ||
| public: | ||
| /** | ||
| * @brief Initialize critic | ||
| */ | ||
| void initialize() override; | ||
|
|
||
| /** | ||
| * @brief Evaluate cost related to changing driving direction | ||
| * | ||
| * @param costs [out] add cost values to this tensor | ||
| */ | ||
| void score(CriticData & data) override; | ||
|
|
||
| protected: | ||
| unsigned int power_{0}; | ||
| float weight_{0}; | ||
| float threshold_to_consider_{0}; | ||
| }; | ||
|
|
||
| } // namespace mppi::critics | ||
|
|
||
| #endif // NAV2_MPPI_CONTROLLER__CRITICS__DIRECTION_CHANGE_CRITIC_HPP_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
nav2_mppi_controller/src/critics/direction_change_critic.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // Copyright (c) 2026 Enway GmbH, Adi Vardi | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include "nav2_mppi_controller/critics/direction_change_critic.hpp" | ||
|
|
||
| #include <Eigen/Dense> | ||
|
|
||
| namespace mppi::critics | ||
| { | ||
|
|
||
| void DirectionChangeCritic::initialize() | ||
| { | ||
| auto getParentParam = parameters_handler_->getParamGetter(parent_name_); | ||
| auto getParam = parameters_handler_->getParamGetter(name_); | ||
| getParam(power_, "cost_power", 1); | ||
| getParam(weight_, "cost_weight", 5.0f); | ||
| getParam( | ||
| threshold_to_consider_, | ||
| "threshold_to_consider", 0.5f); | ||
|
|
||
| RCLCPP_INFO( | ||
| logger_, "DirectionChangeCritic instantiated with %d power and %f weight.", power_, weight_); | ||
| } | ||
|
|
||
| void DirectionChangeCritic::score(CriticData & data) | ||
| { | ||
| if (!enabled_) { | ||
| return; | ||
| } | ||
|
|
||
| if (data.state.local_path_length < threshold_to_consider_) { | ||
| return; | ||
| } | ||
|
|
||
| // Penalize the magnitude of velocity difference when crossing zero (direction change) | ||
| // Calculate |vx - current_speed| only where signs differ, otherwise 0 | ||
| // Use robot_speed from feedback, as it better represents the actual direction of motion | ||
| constexpr size_t penalize_up_to_idx = 2; | ||
| const float current_speed = data.state.robot_speed.linear.x; | ||
| // Process in-place using Eigen views to avoid allocations | ||
| auto vx_view = data.state.vx.leftCols(penalize_up_to_idx); | ||
|
|
||
| if (power_ > 1u) { | ||
| data.costs += ((vx_view * current_speed < 0.0f).select( | ||
| (vx_view - current_speed).abs(), 0.0f).rowwise().sum() * weight_).pow(power_); | ||
| } else { | ||
| data.costs += (vx_view * current_speed < 0.0f).select( | ||
| (vx_view - current_speed).abs(), 0.0f).rowwise().sum() * weight_; | ||
| } | ||
| } | ||
|
|
||
| } // namespace mppi::critics | ||
|
|
||
| #include <pluginlib/class_list_macros.hpp> | ||
|
|
||
| PLUGINLIB_EXPORT_CLASS( | ||
| mppi::critics::DirectionChangeCritic, | ||
| mppi::critics::CriticFunction) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.