Skip to content

Commit

Permalink
Lidar can now be in any orientation, including updside down
Browse files Browse the repository at this point in the history
  • Loading branch information
milesial committed Apr 21, 2018
1 parent 25b636e commit c82e6d1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project(processing_lidar_objects)

set(CMAKE_CXX_FLAGS "-std=c++11 -fpermissive ${CMAKE_CXX_FLAGS} -Wfatal-errors\ ")

find_package(catkin REQUIRED COMPONENTS roscpp roslaunch nodelet rviz std_msgs std_srvs geometry_msgs sensor_msgs tf laser_geometry message_generation)
find_package(catkin REQUIRED COMPONENTS roscpp roslaunch nodelet rviz std_msgs std_srvs geometry_msgs sensor_msgs tf tf2 tf2_geometry_msgs laser_geometry message_generation)
find_package(Armadillo REQUIRED)
find_package(Boost 1.54.0 REQUIRED system)

Expand All @@ -13,7 +13,7 @@ generate_messages(DEPENDENCIES std_msgs geometry_msgs)
catkin_package(
INCLUDE_DIRS include
LIBRARIES scans_merger obstacle_extractor obstacle_tracker obstacle_publisher ${PROJECT_NAME}_nodelets ${PROJECT_NAME}_gui
CATKIN_DEPENDS roscpp nodelet rviz std_msgs std_srvs geometry_msgs sensor_msgs tf laser_geometry message_runtime
CATKIN_DEPENDS roscpp nodelet rviz std_msgs std_srvs geometry_msgs sensor_msgs tf tf2 tf2_geometry_msgs laser_geometry message_runtime
)

include_directories(include ${catkin_INCLUDE_DIRS} ${ARMADILLO_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
Expand Down
4 changes: 4 additions & 0 deletions include/processing_lidar_objects/obstacle_extractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
#include <sensor_msgs/LaserScan.h>
#include <sensor_msgs/PointCloud.h>
#include <processing_lidar_objects/Obstacles.h>
#include <geometry_msgs/Point.h>
#include <tf2/convert.h>
#include <tf/transform_datatypes.h>
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>

#include "processing_lidar_objects/utilities/point.h"
#include "processing_lidar_objects/utilities/segment.h"
Expand Down
2 changes: 2 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<exec_depend>message_runtime</exec_depend>

<depend>tf</depend>
<depend>tf2</depend>
<depend>tf2_geometry_msgs</depend>
<depend>rviz</depend>
<depend>roscpp</depend>
<depend>roslaunch</depend>
Expand Down
29 changes: 23 additions & 6 deletions src/obstacle_extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "processing_lidar_objects/utilities/figure_fitting.h"
#include "processing_lidar_objects/utilities/math_utilities.h"


using namespace std;
using namespace processing_lidar_objects;

Expand Down Expand Up @@ -408,26 +409,42 @@ void ObstacleExtractor::publishObstacles() {

if (p_transform_coordinates_) {
tf::StampedTransform transform;
geometry_msgs::TransformStamped geom_transform;

try {
tf_listener_.waitForTransform(p_frame_id_, base_frame_id_, stamp_, ros::Duration(0.1));
tf_listener_.lookupTransform(p_frame_id_, base_frame_id_, stamp_, transform);
tf::transformStampedTFToMsg(transform, geom_transform);
}
catch (tf::TransformException& ex) {
ROS_INFO_STREAM(ex.what());
return;
}

tf::Vector3 origin = transform.getOrigin();
double theta = tf::getYaw(transform.getRotation());
geometry_msgs::PointStamped geom_point;
geom_point.header = obstacles_msg->header;

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);
geom_point.point.x = s.first_point.x;
geom_point.point.y = s.first_point.y;
tf2::doTransform(geom_point, geom_point, geom_transform);
s.first_point.x = geom_point.point.x;
s.first_point.y = geom_point.point.y;

geom_point.point.x = s.last_point.x;
geom_point.point.y = s.last_point.y;
tf2::doTransform(geom_point, geom_point, geom_transform);
s.last_point.x = geom_point.point.x;
s.last_point.y = geom_point.point.y;
}

for (Circle& c : circles_)
c.center = transformPoint(c.center, origin.x(), origin.y(), theta);
for (Circle& c : circles_) {
geom_point.point.x = c.center.x;
geom_point.point.y = c.center.y;
tf2::doTransform(geom_point, geom_point, geom_transform);
c.center.x = geom_point.point.x;
c.center.y = geom_point.point.y;
}

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

0 comments on commit c82e6d1

Please sign in to comment.