Skip to content

Commit 15ed1c9

Browse files
MPPI Check Namespace.
Signed-off-by: Nils-Christian Iseke <nilsmailiseke@gmail.com>
1 parent b6bbcdf commit 15ed1c9

14 files changed

+141
-90
lines changed

nav2_mppi_controller/benchmark/optimizer_benchmark.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ void prepareAndRunBenchmark(
7979

8080
printInfo(optimizer_settings, path_settings, critics);
8181
auto node = getDummyNode(optimizer_settings, critics);
82-
auto parameters_handler = std::make_unique<mppi::ParametersHandler>(node);
82+
std::string name = "test";
83+
auto parameters_handler = std::make_unique<mppi::ParametersHandler>(node, name);
8384
auto optimizer = getDummyOptimizer(node, costmap_ros, parameters_handler.get());
8485

8586
// evalControl args

nav2_mppi_controller/include/nav2_mppi_controller/tools/parameters_handler.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ParametersHandler
4545
rcl_interfaces::msg::SetParametersResult & result);
4646
using post_callback_t = void ();
4747
using pre_callback_t = void ();
48-
48+
std::string name_;
4949
/**
5050
* @brief Constructor for mppi::ParametersHandler
5151
*/
@@ -56,7 +56,7 @@ class ParametersHandler
5656
* @param parent Weak ptr to node
5757
*/
5858
explicit ParametersHandler(
59-
const rclcpp_lifecycle::LifecycleNode::WeakPtr & parent);
59+
const rclcpp_lifecycle::LifecycleNode::WeakPtr & parent, std::string & name);
6060

6161
/**
6262
* @brief Destructor for mppi::ParametersHandler

nav2_mppi_controller/src/controller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void MPPIController::configure(
3131
costmap_ros_ = costmap_ros;
3232
tf_buffer_ = tf;
3333
name_ = name;
34-
parameters_handler_ = std::make_unique<ParametersHandler>(parent);
34+
parameters_handler_ = std::make_unique<ParametersHandler>(parent, name_);
3535

3636
auto node = parent_.lock();
3737
// Get high-level controller parameters

nav2_mppi_controller/src/optimizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void Optimizer::getParams()
6262

6363
auto & s = settings_;
6464
auto getParam = parameters_handler_->getParamGetter(name_);
65-
auto getParentParam = parameters_handler_->getParamGetter("");
65+
auto getParentParam = parameters_handler_->getParamGetter("test");
6666
getParam(s.model_dt, "model_dt", 0.05f);
6767
getParam(s.time_steps, "time_steps", 56);
6868
getParam(s.batch_size, "batch_size", 1000);

nav2_mppi_controller/src/parameters_handler.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ namespace mppi
1818
{
1919

2020
ParametersHandler::ParametersHandler(
21-
const rclcpp_lifecycle::LifecycleNode::WeakPtr & parent)
21+
const rclcpp_lifecycle::LifecycleNode::WeakPtr & parent, std::string & name)
2222
{
2323
node_ = parent;
2424
auto node = node_.lock();
2525
node_name_ = node->get_name();
2626
logger_ = node->get_logger();
27+
name_ = name;
2728
}
2829

2930
ParametersHandler::~ParametersHandler()
@@ -64,7 +65,9 @@ ParametersHandler::dynamicParamsCallback(
6465

6566
for (auto & param : parameters) {
6667
const std::string & param_name = param.get_name();
67-
68+
if (param_name.find(name_ + ".") != 0) {
69+
continue;
70+
}
6871
if (auto callback = get_param_callbacks_.find(param_name);
6972
callback != get_param_callbacks_.end())
7073
{

nav2_mppi_controller/test/critic_manager_test.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ TEST(CriticManagerTests, BasicCriticOperations)
9595
auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("my_node");
9696
auto costmap_ros = std::make_shared<nav2_costmap_2d::Costmap2DROS>(
9797
"dummy_costmap", "", true);
98-
ParametersHandler param_handler(node);
98+
std::string name = "test";
99+
ParametersHandler param_handler(node, name);
99100
rclcpp_lifecycle::State lstate;
100101
costmap_ros->on_configure(lstate);
101102

@@ -134,7 +135,8 @@ TEST(CriticManagerTests, CriticLoadingTest)
134135
rclcpp::ParameterValue(std::vector<std::string>{"ConstraintCritic", "PreferForwardCritic"}));
135136
auto costmap_ros = std::make_shared<nav2_costmap_2d::Costmap2DROS>(
136137
"dummy_costmap", "", true);
137-
ParametersHandler param_handler(node);
138+
std::string name = "test";
139+
ParametersHandler param_handler(node, name);
138140
rclcpp_lifecycle::State state;
139141
costmap_ros->on_configure(state);
140142

nav2_mppi_controller/test/critics_tests.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ TEST(CriticTests, ConstraintsCritic)
6262
auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("my_node");
6363
auto costmap_ros = std::make_shared<nav2_costmap_2d::Costmap2DROS>(
6464
"dummy_costmap", "", true);
65-
ParametersHandler param_handler(node);
65+
std::string name = "test";
66+
ParametersHandler param_handler(node, name);
6667
rclcpp_lifecycle::State lstate;
6768
costmap_ros->on_configure(lstate);
6869

@@ -130,7 +131,8 @@ TEST(CriticTests, ObstacleCriticMisalignedParams) {
130131
auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("my_node");
131132
auto costmap_ros = std::make_shared<nav2_costmap_2d::Costmap2DROS>(
132133
"dummy_costmap", "", true);
133-
ParametersHandler param_handler(node);
134+
std::string name = "test";
135+
ParametersHandler param_handler(node, name);
134136
auto getParam = param_handler.getParamGetter("critic");
135137
bool consider_footprint;
136138
getParam(consider_footprint, "consider_footprint", true);
@@ -150,7 +152,8 @@ TEST(CriticTests, ObstacleCriticAlignedParams) {
150152
auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("my_node");
151153
auto costmap_ros = std::make_shared<nav2_costmap_2d::Costmap2DROS>(
152154
"dummy_costmap", "", true);
153-
ParametersHandler param_handler(node);
155+
std::string name = "test";
156+
ParametersHandler param_handler(node, name);
154157
auto getParam = param_handler.getParamGetter("critic");
155158
bool consider_footprint;
156159
getParam(consider_footprint, "consider_footprint", false);
@@ -169,7 +172,8 @@ TEST(CriticTests, CostCriticMisAlignedParams) {
169172
auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("my_node");
170173
auto costmap_ros = std::make_shared<nav2_costmap_2d::Costmap2DROS>(
171174
"dummy_costmap", "", true);
172-
ParametersHandler param_handler(node);
175+
std::string name = "test";
176+
ParametersHandler param_handler(node, name);
173177
rclcpp_lifecycle::State lstate;
174178
auto getParam = param_handler.getParamGetter("critic");
175179
bool consider_footprint;
@@ -189,7 +193,8 @@ TEST(CriticTests, CostCriticAlignedParams) {
189193
auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("my_node");
190194
auto costmap_ros = std::make_shared<nav2_costmap_2d::Costmap2DROS>(
191195
"dummy_costmap", "", true);
192-
ParametersHandler param_handler(node);
196+
std::string name = "test";
197+
ParametersHandler param_handler(node, name);
193198
rclcpp_lifecycle::State lstate;
194199
auto getParam = param_handler.getParamGetter("critic");
195200
bool consider_footprint;
@@ -207,7 +212,8 @@ TEST(CriticTests, GoalAngleCritic)
207212
auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("my_node");
208213
auto costmap_ros = std::make_shared<nav2_costmap_2d::Costmap2DROS>(
209214
"dummy_costmap", "", true);
210-
ParametersHandler param_handler(node);
215+
std::string name = "test";
216+
ParametersHandler param_handler(node, name);
211217
rclcpp_lifecycle::State lstate;
212218
costmap_ros->on_configure(lstate);
213219

@@ -266,7 +272,8 @@ TEST(CriticTests, GoalCritic)
266272
auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("my_node");
267273
auto costmap_ros = std::make_shared<nav2_costmap_2d::Costmap2DROS>(
268274
"dummy_costmap", "", true);
269-
ParametersHandler param_handler(node);
275+
std::string name = "test";
276+
ParametersHandler param_handler(node, name);
270277
rclcpp_lifecycle::State lstate;
271278
costmap_ros->on_configure(lstate);
272279

@@ -318,7 +325,8 @@ TEST(CriticTests, PathAngleCritic)
318325
auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("my_node");
319326
auto costmap_ros = std::make_shared<nav2_costmap_2d::Costmap2DROS>(
320327
"dummy_costmap", "", true);
321-
ParametersHandler param_handler(node);
328+
std::string name = "test";
329+
ParametersHandler param_handler(node, name);
322330
rclcpp_lifecycle::State lstate;
323331
costmap_ros->on_configure(lstate);
324332

@@ -436,7 +444,8 @@ TEST(CriticTests, PreferForwardCritic)
436444
auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("my_node");
437445
auto costmap_ros = std::make_shared<nav2_costmap_2d::Costmap2DROS>(
438446
"dummy_costmap", "", true);
439-
ParametersHandler param_handler(node);
447+
std::string name = "test";
448+
ParametersHandler param_handler(node, name);
440449
rclcpp_lifecycle::State lstate;
441450
costmap_ros->on_configure(lstate);
442451

@@ -492,7 +501,8 @@ TEST(CriticTests, TwirlingCritic)
492501
auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("my_node");
493502
auto costmap_ros = std::make_shared<nav2_costmap_2d::Costmap2DROS>(
494503
"dummy_costmap", "", true);
495-
ParametersHandler param_handler(node);
504+
std::string name = "test";
505+
ParametersHandler param_handler(node, name);
496506
rclcpp_lifecycle::State lstate;
497507
costmap_ros->on_configure(lstate);
498508

@@ -556,7 +566,8 @@ TEST(CriticTests, PathFollowCritic)
556566
auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("my_node");
557567
auto costmap_ros = std::make_shared<nav2_costmap_2d::Costmap2DROS>(
558568
"dummy_costmap", "", true);
559-
ParametersHandler param_handler(node);
569+
std::string name = "test";
570+
ParametersHandler param_handler(node, name);
560571
rclcpp_lifecycle::State lstate;
561572
costmap_ros->on_configure(lstate);
562573

@@ -607,7 +618,8 @@ TEST(CriticTests, PathAlignCritic)
607618
auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("my_node");
608619
auto costmap_ros = std::make_shared<nav2_costmap_2d::Costmap2DROS>(
609620
"dummy_costmap", "", true);
610-
ParametersHandler param_handler(node);
621+
std::string name = "test";
622+
ParametersHandler param_handler(node, name);
611623
rclcpp_lifecycle::State lstate;
612624
costmap_ros->on_configure(lstate);
613625

@@ -717,7 +729,8 @@ TEST(CriticTests, VelocityDeadbandCritic)
717729
auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("my_node");
718730
auto costmap_ros = std::make_shared<nav2_costmap_2d::Costmap2DROS>(
719731
"dummy_costmap", "", true);
720-
ParametersHandler param_handler(node);
732+
std::string name = "test";
733+
ParametersHandler param_handler(node, name);
721734
auto getParam = param_handler.getParamGetter("critic");
722735
std::vector<double> deadband_velocities_;
723736
getParam(deadband_velocities_, "deadband_velocities", std::vector<double>{0.08, 0.08, 0.08});

nav2_mppi_controller/test/motion_model_tests.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ TEST(MotionModelTests, AckermannTest)
127127
control_sequence.reset(timesteps); // populates with zeros
128128
state.reset(batches, timesteps); // populates with zeros
129129
auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("my_node");
130-
ParametersHandler param_handler(node);
130+
std::string name = "test";
131+
ParametersHandler param_handler(node, name);
131132
std::unique_ptr<AckermannMotionModel> model =
132133
std::make_unique<AckermannMotionModel>(&param_handler, node->get_name());
133134

@@ -185,7 +186,8 @@ TEST(MotionModelTests, AckermannReversingTest)
185186
control_sequence2.reset(timesteps); // populates with zeros
186187
state.reset(batches, timesteps); // populates with zeros
187188
auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("my_node");
188-
ParametersHandler param_handler(node);
189+
std::string name = "test";
190+
ParametersHandler param_handler(node, name);
189191
std::unique_ptr<AckermannMotionModel> model =
190192
std::make_unique<AckermannMotionModel>(&param_handler, node->get_name());
191193

nav2_mppi_controller/test/noise_generator_test.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ TEST(NoiseGeneratorTest, NoiseGeneratorLifecycle)
3838

3939
auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("node");
4040
node->declare_parameter("test_name.regenerate_noises", rclcpp::ParameterValue(false));
41-
ParametersHandler handler(node);
41+
std::string name = "test";
42+
ParametersHandler handler(node, name);
4243

4344
generator.initialize(settings, false, "test_name", &handler);
4445
generator.reset(settings, false);
@@ -50,7 +51,8 @@ TEST(NoiseGeneratorTest, NoiseGeneratorMain)
5051
// Tests shuts down internal thread cleanly
5152
auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("node");
5253
node->declare_parameter("test_name.regenerate_noises", rclcpp::ParameterValue(true));
53-
ParametersHandler handler(node);
54+
std::string name = "test";
55+
ParametersHandler handler(node, name);
5456
NoiseGenerator generator;
5557
mppi::models::OptimizerSettings settings;
5658
settings.batch_size = 100;
@@ -138,7 +140,8 @@ TEST(NoiseGeneratorTest, NoiseGeneratorMainNoRegenerate)
138140
// This time with no regeneration of noises
139141
auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("node");
140142
node->declare_parameter("test_name.regenerate_noises", rclcpp::ParameterValue(false));
141-
ParametersHandler handler(node);
143+
std::string name = "test";
144+
ParametersHandler handler(node, name);
142145
NoiseGenerator generator;
143146
mppi::models::OptimizerSettings settings;
144147
settings.batch_size = 100;

nav2_mppi_controller/test/optimizer_smoke_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ TEST_P(OptimizerSuite, OptimizerTest) {
6666

6767
printInfo(optimizer_settings, path_settings, critics);
6868
auto node = getDummyNode(optimizer_settings, critics);
69-
auto parameters_handler = std::make_unique<mppi::ParametersHandler>(node);
69+
std::string name = "test";
70+
auto parameters_handler = std::make_unique<mppi::ParametersHandler>(node, name);
7071
auto optimizer = getDummyOptimizer(node, costmap_ros, parameters_handler.get());
7172

7273
// evalControl args

0 commit comments

Comments
 (0)