Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
279240a
Modified CMakeLists.txt and package.xml according to ROS2 migration g…
vandanamandlik Dec 17, 2018
067deb9
ROS2 changes for launch file.
vandanamandlik Dec 17, 2018
7e9d350
Modified AssembleScans.srv and AssembleScans2.srv for ROS2.
vandanamandlik Dec 17, 2018
654d367
Added point_cloud_conversion.h and point_field_conversion.h files.
vandanamandlik Dec 17, 2018
fff899e
Renamed base_assembler.h file to base_assembler.hpp.
vandanamandlik Dec 17, 2018
8b43aa2
Renamed base_assembler.h file to base_assembler.hpp
vandanamandlik Dec 17, 2018
47f192d
Added message_filter.hpp file to include directory of this package
vandanamandlik Dec 17, 2018
d1ae9de
Added service code which generates structure for request and response…
vandanamandlik Dec 17, 2018
3b9f7a7
Modified periodic_snapshotter.cpp file as per ros2 migration guide.
vandanamandlik Dec 17, 2018
81c094b
Ported laser_scan_assembler.cpp file to ROS2.
vandanamandlik Dec 17, 2018
1bdc082
Modified following files to ROS2 as per ROS2 migration guide.
vandanamandlik Dec 17, 2018
fdf9591
Ported test/dummy_scan_producer.cpp and test/test_assembler.cpp files…
vandanamandlik Dec 17, 2018
2b0d65f
Modified message_filter.hpp and tested with crystal release.
vandanamandlik Dec 18, 2018
2b09d96
cpp lint and python flake8 changes for laser_assembler.
vandanamandlik Dec 20, 2018
176669a
Added CONTRIBUTING.md and LICENSE file.
vandanamandlik Dec 20, 2018
d6c1b71
Replaced printf with ROS2 logging functions.
vandanamandlik Dec 21, 2018
f8ce9ab
Code cleanup
vandanamandlik Dec 21, 2018
bd19264
Removed commented code from CMakeLists.txt.
vandanamandlik Dec 21, 2018
081d2d7
- Applied linter (cpp_lint, uncrustify, lint_cmake etc) for code format.
vandanamandlik Dec 27, 2018
64ed3c8
Added Ros2 migration read me file.
vandanamandlik Dec 28, 2018
17baa16
Formatted ros2_migration_readme.md file
vandanamandlik Dec 28, 2018
c885af4
modified Ros2_migration_readme file.
vandanamandlik Dec 28, 2018
67771c8
Added ament_export_dependencies for laser_geometry package in CMakeLi…
vandanamandlik Dec 28, 2018
4eebfab
Added comments in source code and removed some unused code.
vandanamandlik Dec 28, 2018
4beead3
- Changed "filters/filter_chain.h" include to "filters/filter_chain.h…
vandanamandlik Jan 1, 2019
ed03910
Renamed ros2_migration_readme.md file to README.md.
vandanamandlik Jan 2, 2019
47fc3b1
Changed raw node pointer to shared pointer.
vandanamandlik Jan 15, 2019
125b134
Removed filters_FOUND flag from CMakeLists.txt file.
vandanamandlik Jan 17, 2019
fcfece9
Removed laser_assembler_srv_gen, now laser_assembler.srv is generated…
vandanamandlik Jan 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 117 additions & 91 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,102 +1,128 @@
cmake_minimum_required(VERSION 2.8.3)
cmake_minimum_required(VERSION 3.5)
project(laser_assembler)

##############################################################################
# Find dependencies
##############################################################################

set(THIS_PACKAGE_ROS_DEPS
tf sensor_msgs message_filters roscpp laser_geometry filters)

find_package(catkin REQUIRED COMPONENTS
${THIS_PACKAGE_ROS_DEPS}
message_generation)
find_package(Boost REQUIRED COMPONENTS system signals)
include_directories(include ${catkin_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})

##############################################################################
# Build service definitions
##############################################################################
add_service_files(FILES
AssembleScans.srv
AssembleScans2.srv)

generate_messages(DEPENDENCIES sensor_msgs std_msgs)

##############################################################################
# Define package
##############################################################################

catkin_package(
INCLUDE_DIRS include
CATKIN_DEPENDS ${THIS_PACKAGE_ROS_DEPS} message_runtime
DEPENDS
)

##############################################################################
# Build
##############################################################################
if(NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
endif()

add_executable(laser_scan_assembler_srv src/laser_scan_assembler_srv.cpp)
target_link_libraries(laser_scan_assembler_srv ${catkin_LIBRARIES} ${Boost_LIBRARIES})
add_dependencies(laser_scan_assembler_srv ${PROJECT_NAME}_gencpp)
set( filters_FOUND 1 )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this variable used somewhere? How do you know filters was found?

Copy link
Author

@vandanamandlik vandanamandlik Jan 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was workaround added previously, because find_package(filters) was giving some errors,
Updating filters package cmake has solved this issue so removed it in commit id
125b134


find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(builtin_interfaces REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(std_msgs REQUIRED)
find_package(message_filters REQUIRED)
find_package(laser_geometry REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(tf2 REQUIRED)
find_package(laser_assembler_srv_gen REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(filters REQUIRED)

set(INCLUDE_DIRS include ${ament_cmake_INCLUDE_DIRS}
${rosidl_default_generators_INCLUDE_DIRS} ${signals_INCLUDE_DIRS}
${builtin_interfaces_INCLUDE_DIRS} ${rclcpp_INCLUDE_DIRS}
${sensor_msgs_INCLUDE_DIRS} ${std_msgs_INCLUDE_DIRS}
${laser_geometry_INCLUDE_DIRS}
${tf2_ros_INCLUDE_DIRS} ${tf2_INCLUDE_DIRS}
${message_filters_INCLUDE_DIRS}
${laser_assembler_srv_gen_INCLUDE_DIRS}
${rostest_INCLUDE_DIRS} ${system_INCLUDE_DIRS}
${geometry_msgs_INCLUDE_DIRS}
${filters_INCLUDE_DIRS})

include_directories(${INCLUDE_DIRS})

set(LIBS ${rclcpp_LIBRARIES} ${ament_cmake_LIBRARIES}
${rosidl_default_generators_LIBRARIES} ${signals_LIBRARIES}
${laser_assembler_srv_gen_LIBRARIES} ${std_msgs_LIBRARIES}
${system_LIBRARIES} ${tf2_ros_LIBRARIES} ${tf2_LIBRARIES}
${laser_geometry_LIBRARIES}
${geometry_msgs_LIBRARIES}
${message_filters_LIBRARIES} ${sensor_msgs_LIBRARIES}
${filters_LIBRARIES})

# add_executable(laser_scan_assembler_srv src/laser_scan_assembler_srv.cpp)
# target_link_libraries(laser_scan_assembler_srv ${LIBS} ${Boost_LIBRARIES})

add_executable(laser_scan_assembler src/laser_scan_assembler.cpp)
target_link_libraries(laser_scan_assembler ${catkin_LIBRARIES} ${Boost_LIBRARIES})
add_dependencies(laser_scan_assembler ${PROJECT_NAME}_gencpp)

add_executable(merge_clouds src/merge_clouds.cpp)
target_link_libraries(merge_clouds ${catkin_LIBRARIES} ${Boost_LIBRARIES})
add_dependencies(merge_clouds ${PROJECT_NAME}_gencpp)

add_executable(point_cloud_assembler_srv src/point_cloud_assembler_srv.cpp)
target_link_libraries(point_cloud_assembler_srv ${catkin_LIBRARIES} ${Boost_LIBRARIES})
add_dependencies(point_cloud_assembler_srv ${PROJECT_NAME}_gencpp)

add_executable(point_cloud_assembler src/point_cloud_assembler.cpp)
target_link_libraries(point_cloud_assembler ${catkin_LIBRARIES} ${Boost_LIBRARIES})
add_dependencies(point_cloud_assembler ${PROJECT_NAME}_gencpp)

add_executable(point_cloud2_assembler src/point_cloud2_assembler.cpp)
target_link_libraries(point_cloud2_assembler ${catkin_LIBRARIES} ${Boost_LIBRARIES})
add_dependencies(point_cloud2_assembler ${PROJECT_NAME}_gencpp)

## unit testing

if(CATKIN_ENABLE_TESTING)
find_package(rostest)
target_link_libraries(laser_scan_assembler ${LIBS})
install(
TARGETS laser_scan_assembler
DESTINATION lib/${PROJECT_NAME})

#add_executable(merge_clouds src/merge_clouds.cpp)
#target_link_libraries(merge_clouds ${LIBS})

# add_executable(point_cloud_assembler_srv src/point_cloud_assembler_srv.cpp)
# target_link_libraries(point_cloud_assembler_srv ${LIBS})

#add_executable(point_cloud_assembler src/point_cloud_assembler.cpp)
#target_link_libraries(point_cloud_assembler ${LIBS})
#install(
# TARGETS point_cloud_assembler
# DESTINATION lib/${PROJECT_NAME})

# add_executable(point_cloud2_assembler src/point_cloud2_assembler.cpp)
# target_link_libraries(point_cloud2_assembler ${LIBS})
# install(
#TARGETS point_cloud2_assembler
#DESTINATION lib/${PROJECT_NAME})

include_directories(include)

install(DIRECTORY "include/"
DESTINATION include)

install(TARGETS laser_scan_assembler
#point_cloud_assembler
#point_cloud2_assembler
DESTINATION lib/${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include)

ament_export_include_directories(include)
ament_export_dependencies(rclcpp)
ament_export_dependencies(signals)
ament_export_dependencies(sensor_msgs)
#ament_export_dependencies(laser_geometry)
ament_export_dependencies(tf2_ros)
ament_export_dependencies(tf2)
ament_export_dependencies(message_filters)
ament_export_include_directories(${INCLUDE_DIRS})

install(DIRECTORY
launch
DESTINATION share/${PROJECT_NAME}
)

add_executable(periodic_snapshotter examples/periodic_snapshotter.cpp)
target_link_libraries(periodic_snapshotter ${catkin_LIBRARIES} ${Boost_LIBRARIES})
add_dependencies(periodic_snapshotter ${PROJECT_NAME}_gencpp)
if(BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()

add_executable(dummy_scan_producer test/dummy_scan_producer.cpp)
target_link_libraries(dummy_scan_producer ${catkin_LIBRARIES} ${Boost_LIBRARIES})
add_dependencies(dummy_scan_producer ${PROJECT_NAME}_gencpp)

add_executable(test_assembler test/test_assembler.cpp)
target_link_libraries(test_assembler ${catkin_LIBRARIES} ${Boost_LIBRARIES} gtest)
add_dependencies(test_assembler ${PROJECT_NAME}_gencpp)
target_link_libraries(dummy_scan_producer ${LIBS})
install(
TARGETS dummy_scan_producer
DESTINATION lib/${PROJECT_NAME})

ament_add_gtest(test_assembler test/test_assembler.cpp)
target_link_libraries(test_assembler ${LIBS})
install(
TARGETS test_assembler
DESTINATION lib/${PROJECT_NAME})

add_executable(periodic_snapshotter examples/periodic_snapshotter.cpp)
target_link_libraries(periodic_snapshotter ${LIBS})
install(
TARGETS periodic_snapshotter
DESTINATION lib/${PROJECT_NAME})

add_rostest(test/test_laser_assembler.launch)
endif()

##############################################################################
# Install
##############################################################################

install(TARGETS
laser_scan_assembler_srv
laser_scan_assembler
merge_clouds
point_cloud_assembler_srv
point_cloud_assembler
point_cloud2_assembler
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

# Install headers
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION})
ament_package()
131 changes: 89 additions & 42 deletions examples/periodic_snapshotter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,25 @@
*********************************************************************/

#include <cstdio>
#include <ros/ros.h>

#include "rclcpp/rclcpp.hpp"
#include <string>
#include <chrono>
// Services
#include "laser_assembler/AssembleScans.h"
#include "laser_assembler_srv_gen/srv/assemble_scans.hpp"

// Messages
#include "sensor_msgs/PointCloud.h"


#include "sensor_msgs/msg/point_cloud.hpp"
#include "rcutils/cmdline_parser.h"
#include "rclcpp/clock.hpp"
#include "std_msgs/msg/string.hpp"

#define ROS_ERROR printf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does ROS2 not have any logging functions yet?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ROS2 has logging functions, fixed it in the next commits.

#define ROS_INFO printf
#define ROS_WARN printf
#define ROS_DEBUG printf

using namespace std::chrono_literals;
using namespace std::placeholders;
/***
* This a simple test app that requests a point cloud from the
* point_cloud_assembler every 4 seconds, and then publishes the
Expand All @@ -50,59 +60,95 @@
namespace laser_assembler
{

class PeriodicSnapshotter
class PeriodicSnapshotter: public rclcpp::Node
{

public:

PeriodicSnapshotter()
explicit PeriodicSnapshotter(const std::string & service_name)
: Node(service_name)
{
// Create a publisher for the clouds that we assemble
pub_ = n_.advertise<sensor_msgs::PointCloud> ("assembled_cloud", 1);

// Create the service client for calling the assembler
client_ = n_.serviceClient<AssembleScans>("assemble_scans");
std::cerr<< " Inside PeriodicSnapshotter constructor " << "\n";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like debugging output that should be removed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed


// Start the timer that will trigger the processing loop (timerCallback)
timer_ = n_.createTimer(ros::Duration(5,0), &PeriodicSnapshotter::timerCallback, this);
client_ = this->create_client<laser_assembler_srv_gen::srv::AssembleScans>("build_cloud");

if (!client_->wait_for_service(20s)) {
printf("Service not available after waiting");
return;
}
printf(" Service assemble_scans started successfully");
//ROS_INFO("Service [%s] detected", SERVICE_NAME.c_str());

// Create a function for when messages are to be sent.
auto timer_callback = [this]() -> void {
// msg_->name = "Hello World: " + std::to_string(count_++);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove all the commented out code and the "Hello world" stuff.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed commented out code in next commits.

// RCLCPP_INFO(this->get_logger(), "Publishing: '%s'", msg_->status)
//RCLCPP_INFO(this->get_logger(), "Publishing: namespce %s and name is %s ",
// this->get_namespace(), this->get_name());

// Put the message into a queue to be processed by the middleware.
// This call is non-blocking.
this->timerCallback();
};

// Create a publisher with a custom Quality of Service profile.
rmw_qos_profile_t custom_qos_profile = rmw_qos_profile_default;
custom_qos_profile.depth = 7;
pub_ = this->create_publisher<sensor_msgs::msg::PointCloud>(
"/assembled_cloud", custom_qos_profile);

// Use a timer to schedule periodic message publishing.
timer_ = this->create_wall_timer(std::chrono::milliseconds(25), timer_callback);

// Need to track if we've called the timerCallback at least once
first_time_ = true;
}

void timerCallback(const ros::TimerEvent& e)
//void timerCallback(const builtin_interfaces::msg::Time& e)
void timerCallback()
{

// We don't want to build a cloud the first callback, since we we
// don't have a start and end time yet
if (first_time_)
{
last_time = rclcpp::Clock().now();
first_time_ = false;
return;
}

// Populate our service request based on our timer callback times
AssembleScans srv;
srv.request.begin = e.last_real;
srv.request.end = e.current_real;

// Make the service call
if (client_.call(srv))
{
ROS_INFO("Published Cloud with %u points", (uint32_t)(srv.response.cloud.points.size())) ;
pub_.publish(srv.response.cloud);
}
else
{
ROS_ERROR("Error making service call\n") ;
}
}
auto request = std::make_shared<laser_assembler_srv_gen::srv::AssembleScans::Request>();

request->begin = last_time.sec;
last_time = rclcpp::Clock().now();
request->end = last_time.sec;


using ServiceResponseFuture =
rclcpp::Client<laser_assembler_srv_gen::srv::AssembleScans>::SharedFuture;

auto response_received_callback = [this](ServiceResponseFuture future) {
auto result = future.get();
printf("\n Cloud points size = %ld\n", result.get()->cloud.points.size());
//RCLCPP_INFO(this->get_logger(), "Got result: [%" PRId64 "]", future.get()->sum)
if (result.get()->cloud.points.size() > 0 ) {

result.get()->cloud;
pub_->publish(result.get()->cloud);
}
else
ROS_INFO("Got an empty cloud. Going to try again on the next scan");
};

auto result = client_->async_send_request(request);
}

private:
ros::NodeHandle n_;
ros::Publisher pub_;
ros::ServiceClient client_;
ros::Timer timer_;
rclcpp::Publisher<sensor_msgs::msg::PointCloud>::SharedPtr pub_;
rclcpp::Client<laser_assembler_srv_gen::srv::AssembleScans>::SharedPtr client_;
builtin_interfaces::msg::Time last_time;
rclcpp::TimerBase::SharedPtr timer_;
bool first_time_;
} ;

Expand All @@ -112,12 +158,13 @@ using namespace laser_assembler ;

int main(int argc, char **argv)
{
ros::init(argc, argv, "periodic_snapshotter");
ros::NodeHandle n;
ROS_INFO("Waiting for [build_cloud] to be advertised");
ros::service::waitForService("build_cloud");
ROS_INFO("Found build_cloud! Starting the snapshotter");
PeriodicSnapshotter snapshotter;
ros::spin();
rclcpp::init(argc, argv);
auto service_name = std::string("periodic_snapshotter");
char * cli_option = rcutils_cli_get_option(argv, argv + argc, "-s");
if (nullptr != cli_option) {
service_name = std::string(cli_option);
}
auto node = std::make_shared<PeriodicSnapshotter>(service_name);
rclcpp::spin(node);
return 0;
}
Loading