Commit cf4842c1 authored by Joan Vallvé Navarro's avatar Joan Vallvé Navarro
Browse files

hellooo!

parents
cmake_minimum_required(VERSION 2.8.3)
project(wolf_ros_laser)
## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)
# SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/wolf_ros_wrapper/cmake_modules")
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
roscpp
sensor_msgs
std_msgs
tf
dynamic_reconfigure
wolf_demo
)
## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
# find_package(Ceres REQUIRED)
# find_package(Eigen3 REQUIRED)
find_package(wolf REQUIRED)
find_package(wolflaser REQUIRED)
## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()
################################################
## Declare ROS messages, services and actions ##
################################################
## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
## * add a build_depend tag for "message_generation"
## * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET
## * If MSG_DEP_SET isn't empty the following dependency has been pulled in
## but can be declared for certainty nonetheless:
## * add a exec_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
## * add "message_generation" and every package in MSG_DEP_SET to
## find_package(catkin REQUIRED COMPONENTS ...)
## * add "message_runtime" and every package in MSG_DEP_SET to
## catkin_package(CATKIN_DEPENDS ...)
## * uncomment the add_*_files sections below as needed
## and list every .msg/.srv/.action file to be processed
## * uncomment the generate_messages entry below
## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)
## Generate messages in the 'msg' folder
# add_message_files(
# FILES
# Message1.msg
# Message2.msg
# )
## Generate services in the 'srv' folder
# add_service_files(
# FILES
# Service1.srv
# Service2.srv
# )
## Generate actions in the 'action' folder
# add_action_files(
# FILES
# Action1.action
# Action2.action
# )
## Generate added messages and services with any dependencies listed here
#generate_messages(
# DEPENDENCIES
# iri_gnss_msgs
#)
################################################
## Declare ROS dynamic reconfigure parameters ##
################################################
## To declare and build dynamic reconfigure parameters within this
## package, follow these steps:
## * In the file package.xml:
## * add a build_depend and a exec_depend tag for "dynamic_reconfigure"
## * In this file (CMakeLists.txt):
## * add "dynamic_reconfigure" to
## find_package(catkin REQUIRED COMPONENTS ...)
## * uncomment the "generate_dynamic_reconfigure_options" section below
## and list every .cfg file to be processed
## Generate dynamic reconfigure parameters in the 'cfg' folder
#generate_dynamic_reconfigure_options(
# cfg/WolfROS.cfg
#)
###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES wolf_ros1
# CATKIN_DEPENDS roscpp sensor_msgs std_msgs
# DEPENDS system_lib
)
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
message("Wolf include path: ${wolf_INCLUDE_DIR}")
include_directories(
include
${EIGEN_INCLUDE_DIRS}
${wolf_INCLUDE_DIRS}
${wolflaser_INCLUDE_DIRS}
${laser_scan_utils_INCLUDE_DIRS}
${catkin_INCLUDE_DIRS}
${CERES_INCLUDE_DIRS}
)
# link_directories(/usr/local/lib/iri-algorithms)
## Declare a C++ library
# add_library(${PROJECT_NAME}
# src/${PROJECT_NAME}/wolf_ros.cpp
# )
add_library(wolf_subscriber_laser src/wolf_ros_subscriber_laser.cpp)
## Add cmake target dependencies of the library
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure
# add_dependencies(${PROJECT_NAME}_node ${PROJECT_NAME}_gencfg)
# add_dependencies(${PROJECT_NAME}_visualizer ${PROJECT_NAME}_gencfg)
## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg"
# set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME node PREFIX "")
## Add cmake target dependencies of the executable
## same as for the library above
#add_dependencies(${PROJECT_NAME}_node ${PROJECT_NAME}_gencfg)
#add_dependencies(${PROJECT_NAME}_visualizer ${PROJECT_NAME}_gencfg)
## Specify libraries to link a library or executable target against
target_link_libraries(wolf_subscriber_laser
${wolf_LIBRARIES}
${wolflaser_LIBRARIES}
)
#############
## Install ##
#############
# all install targets should use catkin DESTINATION variables
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html
## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
# install(PROGRAMS
# scripts/my_python_script
# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
## Mark executables and/or libraries for installation
# install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
## Mark cpp header files for installation
# install(DIRECTORY include/${PROJECT_NAME}/
# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
# FILES_MATCHING PATTERN "*.h"
# PATTERN ".svn" EXCLUDE
# )
## Mark other files for installation (e.g. launch and bag files, etc.)
# install(FILES
# # myfile1
# # myfile2
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )
#############
## Testing ##
#############
## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_wolf_ros.cpp)
# if(TARGET ${PROJECT_NAME}-test)
# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()
## Add folders to be run by python nosetests
# catkin_add_nosetests(test)
# wolf_ros_gnss
#ifndef WOLF_ROS_SCAN_VISUALIZER_H
#define WOLF_ROS_SCAN_VISUALIZER_H
/**************************
* ROS includes *
**************************/
#include "ros/publisher.h"
#include <ros/ros.h>
/**************************
* WOLF includes *
**************************/
#include <core/common/wolf.h>
#include <core/problem/problem.h>
/**************************
* PCL includes *
**************************/
#include <pcl/point_cloud.h>
#include <pcl_conversions/pcl_conversions.h>
using namespace wolf;
class WolfRosScanVisualizer
{
public:
WolfRosScanVisualizer();
void initialize(ros::NodeHandle& nh);
virtual ~WolfRosScanVisualizer(){};
pcl::PointCloud<pcl::PointXYZ> buildPointCloud(const ProblemPtr);
void publishPointCloud(const ProblemPtr);
ros::Publisher pub;
};
#endif
\ No newline at end of file
/**************************
* WOLF includes *
**************************/
#include <core/capture/capture_odom_2D.h>
#include <core/sensor/sensor_odom_2D.h>
#include <core/processor/processor_odom_2D.h>
#include <core/yaml/parser_yaml.hpp>
#include <core/common/wolf.h>
#include <core/problem/problem.h>
#include <core/utils/params_server.hpp>
#include <laser/capture/capture_laser_2D.h>
#include <laser/sensor/sensor_laser_2D.h>
// #include <core/processor/processor_odom_2D.h>
/**************************
* CERES includes *
**************************/
#include <core/ceres_wrapper/ceres_manager.h>
//#include "glog/logging.h"
/**************************
* ROS includes *
**************************/
#include <ros/ros.h>
#include <nav_msgs/Odometry.h>
#include <sensor_msgs/LaserScan.h>
/**************************
* STD includes *
**************************/
#include <iostream>
#include <iomanip>
#include <queue>
#include "wolf_ros_subscriber.h"
#include "subscriber_factory.h"
using namespace wolf;
class WolfSubscriberWrapperLaser2D : public WolfSubscriberWrapper
{
protected:
bool laser_intrinsics_set_;
public:
// Constructor
WolfSubscriberWrapperLaser2D(const SensorBasePtr& sensor_ptr);
virtual void initSubscriber(ros::NodeHandle& nh, const std::string& topic);
void callback(const sensor_msgs::LaserScan::ConstPtr& msg);
static std::shared_ptr<WolfSubscriberWrapper> create(const std::string& _unique_name, const ParamsServer& _params, const SensorBasePtr _sensor_ptr);
};
WOLF_REGISTER_SUBSCRIBER(WolfSubscriberWrapperLaser2D)
<?xml version="1.0"?>
<package format="2">
<name>wolf_ros_laser</name>
<version>0.0.0</version>
<description>The wolf_ros package of laser plugin</description>
<!-- One maintainer tag required, multiple allowed, one person per tag -->
<!-- Example: -->
<!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
<maintainer email="jvallve@iri.upc.edu">jvallve</maintainer>
<!-- One license tag required, multiple allowed, one license per tag -->
<!-- Commonly used license strings: -->
<!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
<license>TODO</license>
<!-- Url tags are optional, but multiple are allowed, one per tag -->
<!-- Optional attribute type can be: website, bugtracker, or repository -->
<!-- Example: -->
<!-- <url type="website">http://wiki.ros.org/wolf_ros1</url> -->
<!-- Author tags are optional, multiple are allowed, one per tag -->
<!-- Authors do not have to be maintainers, but could be -->
<!-- Example: -->
<!-- <author email="jane.doe@example.com">Jane Doe</author> -->
<!-- The *depend tags are used to specify dependencies -->
<!-- Dependencies can be catkin packages or system dependencies -->
<!-- Examples: -->
<!-- Use depend as a shortcut for packages that are both build and exec dependencies -->
<!-- <depend>roscpp</depend> -->
<!-- Note that this is equivalent to the following: -->
<!-- <build_depend>roscpp</build_depend> -->
<!-- <exec_depend>roscpp</exec_depend> -->
<!-- Use build_depend for packages you need at compile time: -->
<!-- <build_depend>message_generation</build_depend> -->
<!-- Use build_export_depend for packages you need in order to build against this package: -->
<!-- <build_export_depend>message_generation</build_export_depend> -->
<!-- Use buildtool_depend for build tool packages: -->
<!-- <buildtool_depend>catkin</buildtool_depend> -->
<!-- Use exec_depend for packages you need at runtime: -->
<!-- <exec_depend>message_runtime</exec_depend> -->
<!-- Use test_depend for packages you need only for testing: -->
<!-- <test_depend>gtest</test_depend> -->
<!-- Use doc_depend for packages you need only for building documentation: -->
<!-- <doc_depend>doxygen</doc_depend> -->
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>sensor_msgs</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>tf</build_depend>
<build_depend>wolf_demo</build_depend>
<build_export_depend>roscpp</build_export_depend>
<build_export_depend>sensor_msgs</build_export_depend>
<build_export_depend>std_msgs</build_export_depend>
<build_export_depend>tf</build_export_depend>
<exec_depend>roscpp</exec_depend>
<exec_depend>sensor_msgs</exec_depend>
<exec_depend>std_msgs</exec_depend>
<exec_depend>tf</exec_depend>
<exec_depend>wolf_demo</exec_depend>
<!-- The export tag contains other, unspecified, tags -->
<export>
<!-- Other tools can request additional information be placed here -->
</export>
</package>
#include "wolf_ros_scan_visualizer.h"
#include "Eigen/src/Geometry/AngleAxis.h"
#include "pcl/impl/point_types.hpp"
#include "pcl_conversions/pcl_conversions.h"
#include <laser/sensor/sensor_laser_2D.h>
#include <laser_scan_utils/laser_scan.h>
#include <laser/capture/capture_laser_2D.h>
#include <laser_scan_utils/laser_scan_utils.h>
/**************************
* ROS includes *
**************************/
#include <sensor_msgs/LaserScan.h>
/**************************
* PCL includes *
**************************/
#include <laser_geometry/laser_geometry.h>
#include <pcl_ros/point_cloud.h>
#include <pcl_ros/transforms.h>
WolfRosScanVisualizer::WolfRosScanVisualizer()
{
}
void WolfRosScanVisualizer::initialize(ros::NodeHandle &nh)
{
pub = nh.advertise<sensor_msgs::PointCloud2>("point_cloud", 1);
}
pcl::PointCloud<pcl::PointXYZ> WolfRosScanVisualizer::buildPointCloud(const ProblemPtr problem) {
std::ofstream file;
pcl::PointCloud<pcl::PointXYZ> agg_cloud;
for (auto key_frame : problem->getTrajectory()->getFrameList()) {
if (key_frame->isKey()) {
for (auto cptr : key_frame->getCaptureList()) {
if (cptr->getType() == "LASER 2D") {
// Preparation
CaptureLaser2DPtr cptr_laser = std::static_pointer_cast<CaptureLaser2D>(cptr);
SensorLaser2DPtr sensor_laser = std::static_pointer_cast<SensorLaser2D>(cptr->getSensor());
sensor_msgs::LaserScan laser_msg;
laserscanutils::LaserScan scan = cptr_laser->getScan();
laser_msg.angle_max = sensor_laser->getScanParams().angle_max_;
laser_msg.angle_min = sensor_laser->getScanParams().angle_min_;
laser_msg.angle_increment = sensor_laser->getScanParams().angle_step_;
laser_msg.range_max = sensor_laser->getScanParams().range_max_;
laser_msg.range_min = sensor_laser->getScanParams().range_min_;
// Fill ranges
for (auto it : scan.ranges_raw_) {
laser_msg.ranges.emplace_back(it);
}
pcl::PointCloud<pcl::PointXYZ> aux_cloud;
laser_geometry::LaserProjection laser_projector;
sensor_msgs::PointCloud2 p_cloud_msg;
// LaserScan to PointCloud transformation
laser_projector.projectLaser(laser_msg, p_cloud_msg);
// Transform into a "proper" point cloud (not a ROS message)
pcl::fromROSMsg(p_cloud_msg, aux_cloud);
// Build transform matrix according to the frame
Eigen::Affine3f T_world_2_robot = Eigen::Affine3f::Identity();
auto p_f = key_frame->getP()->getState();
auto o_f = key_frame->getO()->getState();
T_world_2_robot.translation() << p_f(0), p_f(1), 0;
T_world_2_robot.rotate(Eigen::AngleAxisf(o_f(0), Eigen::Vector3f::UnitZ()));
// Build transform matrix according to the sensor
Eigen::Affine3f T_robot_2_sensor = Eigen::Affine3f::Identity();
auto p_s = sensor_laser->getP()->getState();
auto o_s = sensor_laser->getO()->getState();
T_robot_2_sensor.translation() << p_s(0), p_s(1), 0;
T_robot_2_sensor.rotate(Eigen::AngleAxisf(o_s(0), Eigen::Vector3f::UnitZ()));
Eigen::Affine3f T_world_2_sensor = T_robot_2_sensor * T_world_2_robot;
// Transform laser scan point cloud
pcl::PointCloud<pcl::PointXYZ> local_cloud;
pcl::transformPointCloud(aux_cloud, aux_cloud, T_world_2_sensor);
agg_cloud = agg_cloud + aux_cloud;
}
}
}
}
return agg_cloud;
}
void WolfRosScanVisualizer::publishPointCloud(const ProblemPtr problem) {
auto pcl = this->buildPointCloud(problem);
sensor_msgs::PointCloud2 msg;
pcl::toROSMsg(pcl, msg);
msg.header.frame_id = "map";
this->pub.publish(msg);
}
#include "wolf_ros_subscriber_laser2D.h"
using namespace wolf;
// Constructor
WolfSubscriberWrapperLaser2D::WolfSubscriberWrapperLaser2D(const SensorBasePtr& sensor_ptr): WolfSubscriberWrapper(sensor_ptr)
{
laser_intrinsics_set_ = false;
}
void WolfSubscriberWrapperLaser2D::initSubscriber(ros::NodeHandle& nh, const std::string& topic)
{
sub_ = nh.subscribe(topic, 100, &WolfSubscriberWrapperLaser2D::callback, this);
}
void WolfSubscriberWrapperLaser2D::callback(const sensor_msgs::LaserScan::ConstPtr& msg)
{
CaptureLaser2DPtr new_capture = std::make_shared<CaptureLaser2D>(TimeStamp(msg->header.stamp.sec, msg->header.stamp.nsec), sensor_ptr_, msg->ranges);
//Currently this line is just to bypass the ROS "auto config". from the ROS msg. Maybe we want to explore
//getting the params from the msg instead of the yaml file in the future.
laser_intrinsics_set_ = true;
if (!laser_intrinsics_set_)
{
auto sensor_laser_ptr = std::dynamic_pointer_cast<SensorLaser2D>(sensor_ptr_);
assert(sensor_laser_ptr != nullptr);
laserscanutils::LaserScanParams params = sensor_laser_ptr->getScanParams();
// params.angle_min_ = msg->angle_min;
// params.angle_max_ = msg->angle_max;
WOLF_DEBUG("angle min msg", msg->angle_min, " angle max msg", msg->angle_max);
// params.angle_min_ = 0.4;
// params.angle_max_ = 1.44;
WOLF_DEBUG("angle min ", params.angle_min_, " angle max ", params.angle_max_);
params.angle_step_ = msg->angle_increment;
params.scan_time_ = msg->time_increment;
params.range_min_ = msg->range_min;
params.range_max_ = msg->range_max;
params.range_std_dev_ = 0.05; // TODO: get from param
params.angle_std_dev_ = 0.05; // TODO: get from param
sensor_laser_ptr->setScanParams(params);
laser_intrinsics_set_ = true;
ROS_INFO("LASER 2D: Intrinsics parameters SET");
}
new_capture->process();
}
std::shared_ptr<WolfSubscriberWrapper> WolfSubscriberWrapperLaser2D::create(const std::string& _unique_name, const ParamsServer& _params, const SensorBasePtr _sensor_ptr)
{
return std::make_shared<WolfSubscriberWrapperLaser2D>(_sensor_ptr);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment