Skip to content

Commit c85d4dd

Browse files
add util test node
Signed-off-by: Chiragkumar Makwana <[email protected]>
1 parent 41a9c8d commit c85d4dd

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "nav2_dynamic_util/tracked_obstacle_utils.hpp"
2+
#include "nav2_dynamic_motion_model/constant_velocity_model.hpp"
3+
4+
5+
class TestObstacleNode : public rclcpp::Node
6+
{
7+
public:
8+
TestObstacleNode()
9+
: Node("test_obstacle_node")
10+
{
11+
motion_model_ = std::make_shared<nav2_dynamic_motion_model::ConstantVelocityModel>();
12+
testObstaclePrediction();
13+
}
14+
15+
private:
16+
std::shared_ptr<nav2_dynamic_motion_model::MotionModelInterface> motion_model_;
17+
18+
void testObstaclePrediction()
19+
{
20+
nav2_dynamic_msgs::msg::Obstacle obstacle;
21+
obstacle.position.x = 1.0;
22+
obstacle.position.y = 2.0;
23+
obstacle.velocity.x = 0.5;
24+
obstacle.velocity.y = 0.2;
25+
double dt = 0.5;
26+
double sim_time = 4.0;
27+
28+
for (; dt <= sim_time; dt += 0.5)
29+
{
30+
geometry_msgs::msg::Pose predicted_pose = nav2_dynamic_util::getObstaclePoseAt(dt, obstacle, motion_model_);
31+
RCLCPP_INFO(this->get_logger(), "Predicted Pose at t=%.1f: x=%.2f, y=%.2f",
32+
dt, predicted_pose.position.x, predicted_pose.position.y);
33+
}
34+
}
35+
};
36+
37+
int main(int argc, char **argv)
38+
{
39+
rclcpp::init(argc, argv);
40+
auto node = std::make_shared<TestObstacleNode>();
41+
rclcpp::spin(node);
42+
rclcpp::shutdown();
43+
return 0;
44+
}

0 commit comments

Comments
 (0)