Skip to content

Commit

Permalink
Add new test for nav2_regulated_pure_pursuit (#2542)
Browse files Browse the repository at this point in the history
* unit test for findDirChg

* lint fix

* add test for unchanged direction

* fix  for loop ending
  • Loading branch information
sathak93 authored and SteveMacenski committed Sep 14, 2021
1 parent d9983a5 commit 8088162
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ double RegulatedPurePursuitController::findDirectionChange(
const geometry_msgs::msg::PoseStamped & pose)
{
// Iterating through the global path to determine the position of the cusp
for (unsigned int pose_id = 1; pose_id < global_plan_.poses.size(); ++pose_id) {
for (unsigned int pose_id = 1; pose_id < global_plan_.poses.size() - 1; ++pose_id) {
// We have two vectors for the dot product OA and AB. Determining the vectors.
double oa_x = global_plan_.poses[pose_id].pose.position.x -
global_plan_.poses[pose_id - 1].pose.position.x;
Expand Down
33 changes: 33 additions & 0 deletions nav2_regulated_pure_pursuit_controller/test/test_regulated_pp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <memory>
#include <string>
#include <vector>
#include <limits>

#include "gtest/gtest.h"
#include "rclcpp/rclcpp.hpp"
Expand Down Expand Up @@ -91,6 +92,12 @@ class BasicAPIRPP : public nav2_regulated_pure_pursuit_controller::RegulatedPure
dist_error, lookahead_dist, curvature, curr_speed, pose_cost,
linear_vel, sign);
}

double findDirectionChangeWrapper(
const geometry_msgs::msg::PoseStamped & pose)
{
return findDirectionChange(pose);
}
};

TEST(RegulatedPurePursuitTest, basicAPI)
Expand Down Expand Up @@ -144,6 +151,32 @@ TEST(RegulatedPurePursuitTest, createCarrotMsg)
EXPECT_EQ(rtn->point.z, 0.01);
}

TEST(RegulatedPurePursuitTest, findDirectionChange)
{
auto ctrl = std::make_shared<BasicAPIRPP>();
geometry_msgs::msg::PoseStamped pose;
pose.pose.position.x = 1.0;
pose.pose.position.y = 0.0;

nav_msgs::msg::Path path;
path.poses.resize(3);
path.poses[0].pose.position.x = 1.0;
path.poses[0].pose.position.y = 1.0;
path.poses[1].pose.position.x = 2.0;
path.poses[1].pose.position.y = 2.0;
path.poses[2].pose.position.x = -1.0;
path.poses[2].pose.position.y = -1.0;
ctrl->setPlan(path);
auto rtn = ctrl->findDirectionChangeWrapper(pose);
EXPECT_EQ(rtn, sqrt(5.0));

path.poses[2].pose.position.x = 3.0;
path.poses[2].pose.position.y = 3.0;
ctrl->setPlan(path);
rtn = ctrl->findDirectionChangeWrapper(pose);
EXPECT_EQ(rtn, std::numeric_limits<double>::max());
}

TEST(RegulatedPurePursuitTest, lookaheadAPI)
{
auto ctrl = std::make_shared<BasicAPIRPP>();
Expand Down

0 comments on commit 8088162

Please sign in to comment.