Skip to content

Commit

Permalink
Port pose_initializer to ROS2 (#11)
Browse files Browse the repository at this point in the history
* CMakeLists.txt & package.xml

* Compiles

* Works

* Use callback instead

* Reviewer feedback

* Add sequence number check

* Review feedback
  • Loading branch information
nnmm authored and 1222-takeshi committed Dec 1, 2021
1 parent 0b8fc36 commit 88d6a92
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 176 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# A sequence number is included to do primitive error checking
uint32 seq
geometry_msgs/PoseWithCovarianceStamped pose_with_cov
---
uint32 seq
geometry_msgs/PoseWithCovarianceStamped pose_with_cov
66 changes: 40 additions & 26 deletions localization/pose_initializer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,47 +1,61 @@
cmake_minimum_required(VERSION 3.0.2)
cmake_minimum_required(VERSION 3.5)
project(pose_initializer)

add_compile_options(-std=c++14)
### Compile options
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
add_compile_options(-Wno-unused-parameter)
endif()

### Dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(tf2_geometry_msgs REQUIRED)
find_package(std_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(PCL REQUIRED)
find_package(pcl_conversions REQUIRED)
find_package(autoware_localization_srvs REQUIRED)

### Includes
include_directories(include)

find_package(catkin REQUIRED COMPONENTS
roscpp
add_executable(pose_initializer
src/pose_initializer_node.cpp
src/pose_initializer_core.cpp
)

set(POSE_INITIALIZER_DEPENDENCIES
rclcpp
tf2
tf2_ros
tf2_geometry_msgs
std_msgs
geometry_msgs
sensor_msgs
dynamic_reconfigure
pcl_ros
PCL
pcl_conversions
autoware_localization_srvs
)

catkin_package(
INCLUDE_DIRS include
)

include_directories(include ${catkin_INCLUDE_DIRS})

add_executable(pose_initializer
src/pose_initializer_node.cpp
src/pose_initializer_core.cpp
)

add_dependencies(pose_initializer ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

target_link_libraries(pose_initializer ${catkin_LIBRARIES})
ament_target_dependencies(pose_initializer ${POSE_INITIALIZER_DEPENDENCIES})
ament_export_dependencies(${POSE_INITIALIZER_DEPENDENCIES})

install(
TARGETS
pose_initializer
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
TARGETS pose_initializer
DESTINATION lib/${PROJECT_NAME}
)

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

ament_package()
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -16,62 +16,65 @@

#pragma once

#include <memory>
#include <string>

#include <ros/ros.h>
#include <rclcpp/rclcpp.hpp>

#include <tf2/transform_datatypes.h>
#include <tf2_ros/transform_listener.h>

#include <geometry_msgs/PoseWithCovarianceStamped.h>
#include <sensor_msgs/PointCloud2.h>

#include <dynamic_reconfigure/server.h>
#include <geometry_msgs/msg/pose_with_covariance_stamped.hpp>
#include <sensor_msgs/msg/point_cloud2.hpp>

#include <pcl/point_cloud.h>
#include <pcl/point_types.h>

#include "autoware_localization_srvs/PoseWithCovarianceStamped.h"
#include "autoware_localization_srvs/srv/pose_with_covariance_stamped.hpp"

class PoseInitializer
class PoseInitializer : public rclcpp::Node
{
public:
PoseInitializer(ros::NodeHandle nh, ros::NodeHandle private_nh);
PoseInitializer();
~PoseInitializer();

private:
void callbackMapPoints(const sensor_msgs::PointCloud2::ConstPtr & pointcloud2_msg_ptr);
bool serviceInitial(
autoware_localization_srvs::PoseWithCovarianceStamped::Request & req,
autoware_localization_srvs::PoseWithCovarianceStamped::Response & res);
void callbackMapPoints(sensor_msgs::msg::PointCloud2::ConstSharedPtr pointcloud2_msg_ptr);
void serviceInitial(
const std::shared_ptr<autoware_localization_srvs::srv::PoseWithCovarianceStamped::Request> req,
std::shared_ptr<autoware_localization_srvs::srv::PoseWithCovarianceStamped::Response> res);
void callbackInitialPose(
const geometry_msgs::PoseWithCovarianceStamped::ConstPtr & pose_cov_msg_ptr);
geometry_msgs::msg::PoseWithCovarianceStamped::ConstSharedPtr pose_cov_msg_ptr);
void callbackGNSSPoseCov(
const geometry_msgs::PoseWithCovarianceStamped::ConstPtr & pose_cov_msg_ptr);
geometry_msgs::msg::PoseWithCovarianceStamped::ConstSharedPtr pose_cov_msg_ptr);

bool getHeight(
const geometry_msgs::PoseWithCovarianceStamped & input_pose_msg,
const geometry_msgs::PoseWithCovarianceStamped::Ptr & output_pose_msg_ptr);
bool callAlignService(
const geometry_msgs::PoseWithCovarianceStamped & msg,
const geometry_msgs::PoseWithCovarianceStamped::Ptr & output_pose_msg_ptr);

ros::NodeHandle nh_;
ros::NodeHandle private_nh_;
const geometry_msgs::msg::PoseWithCovarianceStamped & input_pose_msg,
const geometry_msgs::msg::PoseWithCovarianceStamped::SharedPtr output_pose_msg_ptr);
void callAlignServiceAndPublishResult(
const geometry_msgs::msg::PoseWithCovarianceStamped::SharedPtr msg);

ros::Subscriber initial_pose_sub_;
ros::Subscriber gnss_pose_sub_;
ros::Subscriber map_points_sub_;
rclcpp::Subscription<geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr initial_pose_sub_;
rclcpp::Subscription<geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr gnss_pose_sub_;
rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr map_points_sub_;

ros::Publisher initial_pose_pub_;
rclcpp::Publisher<geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr initial_pose_pub_;

ros::ServiceClient ndt_client_;
rclcpp::Client<autoware_localization_srvs::srv::PoseWithCovarianceStamped>::SharedPtr ndt_client_;

ros::ServiceServer gnss_service_;
rclcpp::Service<autoware_localization_srvs::srv::PoseWithCovarianceStamped>::SharedPtr
gnss_service_;

tf2_ros::Buffer tf2_buffer_;
tf2::BufferCore tf2_buffer_;
tf2_ros::TransformListener tf2_listener_;

pcl::PointCloud<pcl::PointXYZ>::Ptr map_ptr_;
std::string map_frame_;

// With the currently available facilities for calling a service, there is no
// easy way of detecting whether an answer was received within a reasonable
// amount of time. So, as a sanity check, we check whether a response for the
// previous request was received when a new request is sent.
uint32_t request_id_ = 0;
uint32_t response_id_ = 0;
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<launch>

<arg name="ndt_align_server_name" default="ndt_align_srv"/>
<node pkg="pose_initializer" type="pose_initializer" name="pose_initializer" output="log">
<node pkg="pose_initializer" exec="pose_initializer" name="pose_initializer" output="log">
<remap from="initialpose" to="/initialpose" />
<remap from="initialpose3d" to="/initialpose3d" />
<remap from="gnss_pose_cov" to="/sensing/gnss/pose_with_covariance" />
<remap from="pointcloud_map" to="/map/pointcloud_map" />
<remap from="ndt_align_srv" to="/localization/pose_estimator/ndt_align_srv" />
<param name="use_first_gnss_topic" value="true" />
</node>

</launch>
51 changes: 21 additions & 30 deletions localization/pose_initializer/package.xml
Original file line number Diff line number Diff line change
@@ -1,34 +1,25 @@
<?xml version="1.0"?>
<package>
<name>pose_initializer</name>
<version>0.1.0</version>
<description>The pose_initializer package</description>
<maintainer email="yamato.ando@gmail.com">Yamato Ando</maintainer>
<license>Apache 2</license>
<buildtool_depend>catkin</buildtool_depend>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>pose_initializer</name>
<version>0.1.0</version>
<description>The pose_initializer package</description>
<maintainer email="yamato.ando@gmail.com">Yamato Ando</maintainer>
<license>Apache 2</license>
<buildtool_depend>ament_cmake</buildtool_depend>

<build_depend>roscpp</build_depend>
<build_depend>tf2</build_depend>
<build_depend>tf2_ros</build_depend>
<build_depend>tf2_geometry_msgs</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>geometry_msgs</build_depend>
<build_depend>sensor_msgs</build_depend>
<build_depend>pcl_ros</build_depend>
<build_depend>pcl_conversions</build_depend>
<build_depend>autoware_localization_srvs</build_depend>
<depend>rclcpp</depend>
<depend>tf2</depend>
<depend>tf2_ros</depend>
<depend>tf2_geometry_msgs</depend>
<depend>std_msgs</depend>
<depend>geometry_msgs</depend>
<depend>sensor_msgs</depend>
<depend>libpcl-all-dev</depend>
<depend>pcl_conversions</depend>
<depend>autoware_localization_srvs</depend>

<run_depend>roscpp</run_depend>
<run_depend>tf2</run_depend>
<run_depend>tf2_ros</run_depend>
<run_depend>tf2_geometry_msgs</run_depend>
<run_depend>std_msgs</run_depend>
<run_depend>geometry_msgs</run_depend>
<run_depend>sensor_msgs</run_depend>
<run_depend>pcl_ros</run_depend>
<run_depend>pcl_conversions</run_depend>
<run_depend>autoware_localization_srvs</run_depend>

<export>
</export>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Loading

0 comments on commit 88d6a92

Please sign in to comment.