Skip to content

Commit

Permalink
Extractor: obstacles are now correctly transformed
Browse files Browse the repository at this point in the history
  • Loading branch information
milesial committed Apr 28, 2018
1 parent 7c2cec9 commit dc769d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 7 additions & 0 deletions include/obstacle_detector/utilities/math_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ inline Point transformPoint(const Point point, double x, double y, double theta)
return p;
}

inline Point transformPoint(const Point& point, const tf::StampedTransform& transform) {
tf::Vector3 v(point.x, point.y, 0);
v = transform * v;

return {v.x(), v.y()};
}

inline bool checkPointInLimits(const geometry_msgs::Point32& p, double x_min, double x_max, double y_min, double y_max) {
if ((p.x > x_max) || (p.x < x_min) || (p.y > y_max) || (p.y < y_min))
return false;
Expand Down
10 changes: 4 additions & 6 deletions src/obstacle_extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,16 +418,14 @@ void ObstacleExtractor::publishObstacles() {
return;
}

tf::Vector3 origin = transform.getOrigin();
double theta = tf::getYaw(transform.getRotation());

tf::Vector3 vec;
for (Segment& s : segments_) {
s.first_point = transformPoint(s.first_point, origin.x(), origin.y(), theta);
s.last_point = transformPoint(s.last_point, origin.x(), origin.y(), theta);
s.first_point = transformPoint(s.first_point, transform);
s.last_point = transformPoint(s.last_point, transform);
}

for (Circle& c : circles_)
c.center = transformPoint(c.center, origin.x(), origin.y(), theta);
c.center = transformPoint(c.center, transform);

obstacles_msg->header.frame_id = p_frame_id_;
}
Expand Down

0 comments on commit dc769d3

Please sign in to comment.