|
31 | 31 | #include "nav2_mppi_controller/critics/prefer_forward_critic.hpp" |
32 | 32 | #include "nav2_mppi_controller/critics/twirling_critic.hpp" |
33 | 33 | #include "nav2_mppi_controller/critics/velocity_deadband_critic.hpp" |
| 34 | +#include "nav2_core/exceptions.hpp" |
34 | 35 | #include "utils_test.cpp" // NOLINT |
35 | 36 |
|
36 | 37 | // Tests the various critic plugin functions |
@@ -115,6 +116,81 @@ TEST(CriticTests, ConstraintsCritic) |
115 | 116 | EXPECT_NEAR(costs(1), 0.48, 0.01); |
116 | 117 | } |
117 | 118 |
|
| 119 | +TEST(CriticTests, ObstacleCriticMisalignedParams) { |
| 120 | + auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("my_node"); |
| 121 | + auto costmap_ros = std::make_shared<nav2_costmap_2d::Costmap2DROS>( |
| 122 | + "dummy_costmap", "", "dummy_costmap"); |
| 123 | + ParametersHandler param_handler(node); |
| 124 | + auto getParam = param_handler.getParamGetter("critic"); |
| 125 | + bool consider_footprint; |
| 126 | + getParam(consider_footprint, "consider_footprint", true); |
| 127 | + |
| 128 | + rclcpp_lifecycle::State lstate; |
| 129 | + costmap_ros->on_configure(lstate); |
| 130 | + |
| 131 | + ObstaclesCritic critic; |
| 132 | + // Expect throw when settings mismatched |
| 133 | + EXPECT_THROW( |
| 134 | + critic.on_configure(node, "mppi", "critic", costmap_ros, ¶m_handler), |
| 135 | + nav2_core::PlannerException |
| 136 | + ); |
| 137 | +} |
| 138 | + |
| 139 | +TEST(CriticTests, ObstacleCriticAlignedParams) { |
| 140 | + auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("my_node"); |
| 141 | + auto costmap_ros = std::make_shared<nav2_costmap_2d::Costmap2DROS>( |
| 142 | + "dummy_costmap", "", "dummy_costmap"); |
| 143 | + ParametersHandler param_handler(node); |
| 144 | + auto getParam = param_handler.getParamGetter("critic"); |
| 145 | + bool consider_footprint; |
| 146 | + getParam(consider_footprint, "consider_footprint", false); |
| 147 | + |
| 148 | + rclcpp_lifecycle::State lstate; |
| 149 | + costmap_ros->on_configure(lstate); |
| 150 | + |
| 151 | + ObstaclesCritic critic; |
| 152 | + critic.on_configure(node, "mppi", "critic", costmap_ros, ¶m_handler); |
| 153 | + EXPECT_EQ(critic.getName(), "critic"); |
| 154 | +} |
| 155 | + |
| 156 | + |
| 157 | +TEST(CriticTests, CostCriticMisAlignedParams) { |
| 158 | + // Standard preamble |
| 159 | + auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("my_node"); |
| 160 | + auto costmap_ros = std::make_shared<nav2_costmap_2d::Costmap2DROS>( |
| 161 | + "dummy_costmap", "", "dummy_costmap"); |
| 162 | + ParametersHandler param_handler(node); |
| 163 | + rclcpp_lifecycle::State lstate; |
| 164 | + auto getParam = param_handler.getParamGetter("critic"); |
| 165 | + bool consider_footprint; |
| 166 | + getParam(consider_footprint, "consider_footprint", true); |
| 167 | + costmap_ros->on_configure(lstate); |
| 168 | + |
| 169 | + CostCritic critic; |
| 170 | + // Expect throw when settings mismatched |
| 171 | + EXPECT_THROW( |
| 172 | + critic.on_configure(node, "mppi", "critic", costmap_ros, ¶m_handler), |
| 173 | + nav2_core::PlannerException |
| 174 | + ); |
| 175 | +} |
| 176 | + |
| 177 | +TEST(CriticTests, CostCriticAlignedParams) { |
| 178 | + // Standard preamble |
| 179 | + auto node = std::make_shared<rclcpp_lifecycle::LifecycleNode>("my_node"); |
| 180 | + auto costmap_ros = std::make_shared<nav2_costmap_2d::Costmap2DROS>( |
| 181 | + "dummy_costmap", "", "dummy_costmap"); |
| 182 | + ParametersHandler param_handler(node); |
| 183 | + rclcpp_lifecycle::State lstate; |
| 184 | + auto getParam = param_handler.getParamGetter("critic"); |
| 185 | + bool consider_footprint; |
| 186 | + getParam(consider_footprint, "consider_footprint", false); |
| 187 | + costmap_ros->on_configure(lstate); |
| 188 | + |
| 189 | + CostCritic critic; |
| 190 | + critic.on_configure(node, "mppi", "critic", costmap_ros, ¶m_handler); |
| 191 | + EXPECT_EQ(critic.getName(), "critic"); |
| 192 | +} |
| 193 | + |
118 | 194 | TEST(CriticTests, GoalAngleCritic) |
119 | 195 | { |
120 | 196 | // Standard preamble |
|
0 commit comments