forked from ros-navigation/navigation2
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Critic for Velocity Deadband Hardware Constraints (ros-navi…
…gation#4256) * Adding new velocity deadband critic. - add some tests - cast double to float - add new features from "main" branch - fix formating - add cost test - fix linting issue - add README Signed-off-by: Denis Sokolov <[email protected]> * Remove velocity deadband critic from defaults Signed-off-by: Denis Sokolov <[email protected]> * remove old weight Signed-off-by: Denis Sokolov <[email protected]> * fix velocity deadband critic tests Signed-off-by: Denis Sokolov <[email protected]> --------- Signed-off-by: Denis Sokolov <[email protected]> Signed-off-by: enricosutera <[email protected]>
- Loading branch information
1 parent
34a2102
commit b62fa1b
Showing
6 changed files
with
227 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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
54 changes: 54 additions & 0 deletions
54
nav2_mppi_controller/include/nav2_mppi_controller/critics/velocity_deadband_critic.hpp
This file contains 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,54 @@ | ||
// Copyright (c) 2022 Samsung Research America, @artofnothingness Alexey Budyakov | ||
// | ||
// 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__VELOCITY_DEADBAND_CRITIC_HPP_ | ||
#define NAV2_MPPI_CONTROLLER__CRITICS__VELOCITY_DEADBAND_CRITIC_HPP_ | ||
|
||
#include <vector> | ||
|
||
#include "nav2_mppi_controller/critic_function.hpp" | ||
#include "nav2_mppi_controller/models/state.hpp" | ||
#include "nav2_mppi_controller/tools/utils.hpp" | ||
|
||
namespace mppi::critics | ||
{ | ||
|
||
/** | ||
* @class mppi::critics::VelocityDeadbandCritic | ||
* @brief Critic objective function for enforcing feasible constraints | ||
*/ | ||
class VelocityDeadbandCritic : public CriticFunction | ||
{ | ||
public: | ||
/** | ||
* @brief Initialize critic | ||
*/ | ||
void initialize() override; | ||
|
||
/** | ||
* @brief Evaluate cost related to goal following | ||
* | ||
* @param costs [out] add reference cost values to this tensor | ||
*/ | ||
void score(CriticData & data) override; | ||
|
||
protected: | ||
unsigned int power_{0}; | ||
float weight_{0}; | ||
std::vector<float> deadband_velocities_{0.0f, 0.0f, 0.0f}; | ||
}; | ||
|
||
} // namespace mppi::critics | ||
|
||
#endif // NAV2_MPPI_CONTROLLER__CRITICS__VELOCITY_DEADBAND_CRITIC_HPP_ |
104 changes: 104 additions & 0 deletions
104
nav2_mppi_controller/src/critics/velocity_deadband_critic.cpp
This file contains 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,104 @@ | ||
// Copyright (c) 2022 Samsung Research America, @artofnothingness Alexey Budyakov | ||
// | ||
// 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/velocity_deadband_critic.hpp" | ||
|
||
namespace mppi::critics | ||
{ | ||
|
||
void VelocityDeadbandCritic::initialize() | ||
{ | ||
auto getParam = parameters_handler_->getParamGetter(name_); | ||
|
||
getParam(power_, "cost_power", 1); | ||
getParam(weight_, "cost_weight", 35.0); | ||
|
||
// Recast double to float | ||
std::vector<double> deadband_velocities{0.0, 0.0, 0.0}; | ||
getParam(deadband_velocities, "deadband_velocities", std::vector<double>{0.0, 0.0, 0.0}); | ||
std::transform( | ||
deadband_velocities.begin(), deadband_velocities.end(), deadband_velocities_.begin(), | ||
[](double d) {return static_cast<float>(d);}); | ||
|
||
RCLCPP_INFO_STREAM( | ||
logger_, "VelocityDeadbandCritic instantiated with " | ||
<< power_ << " power, " << weight_ << " weight, deadband_velocity [" | ||
<< deadband_velocities_.at(0) << "," << deadband_velocities_.at(1) << "," | ||
<< deadband_velocities_.at(2) << "]"); | ||
} | ||
|
||
void VelocityDeadbandCritic::score(CriticData & data) | ||
{ | ||
using xt::evaluation_strategy::immediate; | ||
|
||
if (!enabled_) { | ||
return; | ||
} | ||
|
||
auto & vx = data.state.vx; | ||
auto & wz = data.state.wz; | ||
|
||
if (data.motion_model->isHolonomic()) { | ||
auto & vy = data.state.vy; | ||
if (power_ > 1u) { | ||
data.costs += xt::pow( | ||
xt::sum( | ||
std::move( | ||
xt::maximum(fabs(deadband_velocities_.at(0)) - xt::fabs(vx), 0) + | ||
xt::maximum(fabs(deadband_velocities_.at(1)) - xt::fabs(vy), 0) + | ||
xt::maximum(fabs(deadband_velocities_.at(2)) - xt::fabs(wz), 0)) * | ||
data.model_dt, | ||
{1}, immediate) * | ||
weight_, | ||
power_); | ||
} else { | ||
data.costs += xt::sum( | ||
(std::move( | ||
xt::maximum(fabs(deadband_velocities_.at(0)) - xt::fabs(vx), 0) + | ||
xt::maximum(fabs(deadband_velocities_.at(1)) - xt::fabs(vy), 0) + | ||
xt::maximum(fabs(deadband_velocities_.at(2)) - xt::fabs(wz), 0))) * | ||
data.model_dt, | ||
{1}, immediate) * | ||
weight_; | ||
} | ||
return; | ||
} | ||
|
||
if (power_ > 1u) { | ||
data.costs += xt::pow( | ||
xt::sum( | ||
std::move( | ||
xt::maximum(fabs(deadband_velocities_.at(0)) - xt::fabs(vx), 0) + | ||
xt::maximum(fabs(deadband_velocities_.at(2)) - xt::fabs(wz), 0)) * | ||
data.model_dt, | ||
{1}, immediate) * | ||
weight_, | ||
power_); | ||
} else { | ||
data.costs += xt::sum( | ||
(std::move( | ||
xt::maximum(fabs(deadband_velocities_.at(0)) - xt::fabs(vx), 0) + | ||
xt::maximum(fabs(deadband_velocities_.at(2)) - xt::fabs(wz), 0))) * | ||
data.model_dt, | ||
{1}, immediate) * | ||
weight_; | ||
} | ||
return; | ||
} | ||
|
||
} // namespace mppi::critics | ||
|
||
#include <pluginlib/class_list_macros.hpp> | ||
|
||
PLUGINLIB_EXPORT_CLASS(mppi::critics::VelocityDeadbandCritic, mppi::critics::CriticFunction) |
This file contains 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