-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update padFootprint function #108
Changes from 5 commits
f8cd41f
f7443af
1eac1c9
e47bca8
7f99c9c
b0f6775
2b65725
c646145
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,12 +137,29 @@ void transformFootprint(double x, double y, double theta, const std::vector<geom | |
|
||
void padFootprint(std::vector<geometry_msgs::Point>& footprint, double padding) | ||
{ | ||
// pad footprint in place | ||
for (unsigned int i = 0; i < footprint.size(); i++) | ||
geometry_msgs::Point footprint_center; | ||
double sum_x = 0.0, sum_y = 0.0; | ||
|
||
for (const auto& point : footprint) | ||
{ | ||
sum_x += point.x; | ||
sum_y += point.y; | ||
} | ||
footprint_center.x = sum_x / footprint.size(); | ||
footprint_center.y = sum_y / footprint.size(); | ||
|
||
for (auto& point : footprint) | ||
{ | ||
geometry_msgs::Point& pt = footprint[ i ]; | ||
pt.x += sign0(pt.x) * padding; | ||
pt.y += sign0(pt.y) * padding; | ||
double dx = point.x - footprint_center.x; | ||
double dy = point.y - footprint_center.y; | ||
|
||
double distance = std::sqrt(dx * dx + dy * dy); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. S: |
||
|
||
if (distance > 0.0) | ||
{ | ||
point.x += padding * (dx / distance); | ||
point.y += padding * (dy / distance); | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,17 +70,17 @@ TEST( Costmap2DROS, padded_footprint_from_string_param ) | |
std::vector<geometry_msgs::Point> footprint = cm.getRobotFootprint(); | ||
EXPECT_EQ( 3, footprint.size() ); | ||
|
||
EXPECT_EQ( 1.5f, footprint[ 0 ].x ); | ||
EXPECT_EQ( 1.5f, footprint[ 0 ].y ); | ||
EXPECT_EQ( 0.0f, footprint[ 0 ].z ); | ||
EXPECT_EQ( 1.66667f, footprint[0].x ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: do we really need to change round numbers? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes because otherwise it fails |
||
EXPECT_EQ( 1.33333f, footprint[0].y ); | ||
EXPECT_EQ( 0.0f, footprint[0].z ); | ||
|
||
EXPECT_EQ( -1.5f, footprint[ 1 ].x ); | ||
EXPECT_EQ( 1.5f, footprint[ 1 ].y ); | ||
EXPECT_EQ( 0.0f, footprint[ 1 ].z ); | ||
EXPECT_EQ( -1.33333f, footprint[1].x ); | ||
EXPECT_EQ( 1.33333f, footprint[1].y ); | ||
EXPECT_EQ( 0.0f, footprint[1].z ); | ||
|
||
EXPECT_EQ( -1.5f, footprint[ 2 ].x ); | ||
EXPECT_EQ( -1.5f, footprint[ 2 ].y ); | ||
EXPECT_EQ( 0.0f, footprint[ 2 ].z ); | ||
EXPECT_EQ( -1.33333f, footprint[2].x ); | ||
EXPECT_EQ( -1.66667f, footprint[2].y ); | ||
EXPECT_EQ( 0.0f, footprint[2].z ); | ||
} | ||
|
||
TEST( Costmap2DROS, radius_param ) | ||
|
@@ -155,7 +155,7 @@ TEST( Costmap2DROS, footprint_empty ) | |
// With no specification of footprint or radius, defaults to 0.46 meter radius plus 0.01 meter padding. | ||
EXPECT_EQ( 16, footprint.size() ); | ||
|
||
EXPECT_NEAR( 0.47f, footprint[ 0 ].x, 0.0001 ); | ||
EXPECT_NEAR( 0.47f, footprint[ 0 ].x, 0.001 ); | ||
EXPECT_NEAR( 0.0f, footprint[ 0 ].y, 0.0001 ); | ||
EXPECT_EQ( 0.0f, footprint[ 0 ].z ); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: I think it makes sense to create a method
centroid
that returnsgeometry_msgs::Point