Skip to content

Commit 4eac439

Browse files
nnmmtaikitanaka3
authored andcommitted
Port dummy_perception_publisher to ROS2 (autowarefoundation#90)
* Port dummy_perception_publisher to ROS2 * Uncrustify * Lint * Copyright * Period * Further ament_cpplint fixes Signed-off-by: tanaka3 <ttatcoder@outlook.jp>
1 parent a18002b commit 4eac439

File tree

8 files changed

+334
-306
lines changed

8 files changed

+334
-306
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,102 @@
1-
cmake_minimum_required(VERSION 3.0.2)
1+
cmake_minimum_required(VERSION 3.5)
22
project(dummy_perception_publisher)
33

4-
add_compile_options(-std=c++14)
4+
### Compile options
5+
if(NOT CMAKE_CXX_STANDARD)
6+
set(CMAKE_CXX_STANDARD 14)
7+
endif()
8+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
9+
add_compile_options(-Wno-unused-parameter -Wall -Wextra -Wpedantic)
10+
endif()
511

6-
find_package(catkin REQUIRED COMPONENTS
7-
message_generation
8-
roscpp
12+
# Dependencies for messages
13+
find_package(ament_cmake REQUIRED)
14+
find_package(rosidl_default_generators REQUIRED)
15+
find_package(autoware_perception_msgs REQUIRED)
16+
find_package(geometry_msgs REQUIRED)
17+
find_package(std_msgs REQUIRED)
18+
find_package(unique_identifier_msgs REQUIRED)
19+
20+
rosidl_generate_interfaces(${PROJECT_NAME}
21+
"msg/InitialState.msg"
22+
"msg/Object.msg"
23+
DEPENDENCIES autoware_perception_msgs geometry_msgs std_msgs unique_identifier_msgs
24+
)
25+
26+
# See ndt_omp package for documentation on why PCL is special
27+
find_package(PCL REQUIRED COMPONENTS common filters)
28+
find_package(ament_cmake_auto REQUIRED)
29+
ament_auto_find_build_dependencies()
30+
31+
set(${PROJECT_NAME}_DEPENDENCIES
32+
autoware_perception_msgs
33+
pcl_conversions
34+
rclcpp
935
sensor_msgs
1036
std_msgs
1137
tf2
1238
tf2_geometry_msgs
1339
tf2_ros
14-
autoware_perception_msgs
15-
pcl_ros
16-
uuid_msgs
17-
unique_id
18-
)
19-
20-
add_message_files(
21-
DIRECTORY msg
22-
FILES
23-
Object.msg
24-
InitialState.msg
25-
)
26-
generate_messages(
27-
DEPENDENCIES
28-
std_msgs
29-
geometry_msgs
30-
autoware_perception_msgs
31-
uuid_msgs
32-
)
33-
34-
catkin_package(
35-
INCLUDE_DIRS
36-
include
37-
CATKIN_DEPENDS
38-
message_runtime
39-
roscpp
40-
sensor_msgs
41-
tf2
42-
tf2_geometry_msgs
43-
tf2_ros
44-
autoware_perception_msgs
45-
pcl_ros
46-
uuid_msgs
47-
unique_id
48-
)
49-
50-
include_directories(
51-
include
52-
${catkin_INCLUDE_DIRS}
5340
)
5441

5542
add_executable(dummy_perception_publisher_node
5643
src/main.cpp
5744
src/node.cpp
5845
)
5946

60-
add_dependencies(dummy_perception_publisher_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
47+
ament_target_dependencies(dummy_perception_publisher_node ${${PROJECT_NAME}_DEPENDENCIES})
48+
49+
target_include_directories(dummy_perception_publisher_node
50+
PUBLIC
51+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
52+
$<INSTALL_INTERFACE:include>)
53+
54+
# For using message definitions from the same package
55+
rosidl_target_interfaces(dummy_perception_publisher_node
56+
${PROJECT_NAME} "rosidl_typesupport_cpp")
57+
58+
# PCL dependencies – `ament_target_dependencies` doesn't respect the
59+
# components/modules selected above and only links in `common` ,so we need
60+
# to do this manually.
61+
target_compile_definitions(dummy_perception_publisher_node PRIVATE ${PCL_DEFINITIONS})
62+
target_include_directories(dummy_perception_publisher_node PRIVATE ${PCL_INCLUDE_DIRS})
63+
# Unfortunately, this one can't be PRIVATE because only the plain or only the
64+
# keyword (PRIVATE) signature of target_link_libraries can be used for one
65+
# target, not both. The plain signature is already used inside
66+
# `ament_target_dependencies` and possibly rosidl_target_interfaces.
67+
target_link_libraries(dummy_perception_publisher_node ${PCL_LIBRARIES})
68+
target_link_directories(dummy_perception_publisher_node PRIVATE ${PCL_LIBRARY_DIRS})
6169

62-
target_link_libraries(dummy_perception_publisher_node
63-
${catkin_LIBRARIES}
64-
)
6570

6671
add_executable(empty_objects_publisher
6772
src/empty_objects_publisher.cpp
6873
)
6974

70-
add_dependencies(empty_objects_publisher ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
75+
ament_target_dependencies(empty_objects_publisher PUBLIC ${${PROJECT_NAME}_DEPENDENCIES})
7176

72-
target_link_libraries(empty_objects_publisher
73-
${catkin_LIBRARIES}
74-
)
77+
target_include_directories(empty_objects_publisher
78+
PUBLIC
79+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
80+
$<INSTALL_INTERFACE:include>)
7581

7682
install(
7783
TARGETS
7884
dummy_perception_publisher_node
7985
empty_objects_publisher
80-
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
81-
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
82-
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
86+
ARCHIVE DESTINATION lib/${PROJECT_NAME}
87+
LIBRARY DESTINATION lib/${PROJECT_NAME}
88+
RUNTIME DESTINATION bin/${PROJECT_NAME}
8389
)
8490

8591
install(
8692
DIRECTORY
8793
launch
88-
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
94+
DESTINATION launch
8995
)
96+
97+
if(BUILD_TESTING)
98+
find_package(ament_lint_auto REQUIRED)
99+
ament_lint_auto_find_test_dependencies()
100+
endif()
101+
102+
ament_package()

simulator/util/dummy_perception_publisher/COLCON_IGNORE

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,66 @@
1-
/*
2-
* Copyright 2020 Tier IV, Inc. All rights reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
#pragma once
17-
#include <autoware_perception_msgs/DynamicObjectArray.h>
18-
#include <autoware_perception_msgs/DynamicObjectWithFeatureArray.h>
19-
#include <dummy_perception_publisher/Object.h>
1+
// Copyright 2020 Tier IV, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef DUMMY_PERCEPTION_PUBLISHER__NODE_HPP_
16+
#define DUMMY_PERCEPTION_PUBLISHER__NODE_HPP_
17+
18+
#include <autoware_perception_msgs/msg/dynamic_object_array.hpp>
19+
#include <autoware_perception_msgs/msg/dynamic_object_with_feature_array.hpp>
20+
#include <dummy_perception_publisher/msg/object.hpp>
21+
#include <pcl/common/distances.h>
2022
#include <pcl/point_types.h>
2123
#include <pcl_conversions/pcl_conversions.h>
22-
#include <pcl_ros/point_cloud.h>
23-
#include <ros/ros.h>
24-
#include <sensor_msgs/PointCloud2.h>
24+
#include <rclcpp/rclcpp.hpp>
25+
#include <sensor_msgs/msg/point_cloud2.hpp>
2526
#include <tf2/LinearMath/Transform.h>
2627
#include <tf2/convert.h>
2728
#include <tf2/transform_datatypes.h>
2829
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
2930
#include <tf2_ros/buffer.h>
3031
#include <tf2_ros/transform_listener.h>
31-
#include <memory>
32+
3233
#include <random>
33-
#include <tuple>
34+
#include <vector>
3435

35-
class DummyPerceptionPublisherNode
36+
37+
class DummyPerceptionPublisherNode : public rclcpp::Node
3638
{
3739
private:
38-
ros::NodeHandle nh_, pnh_;
39-
ros::Publisher pointcloud_pub_;
40-
ros::Publisher dynamic_object_pub_;
41-
ros::Subscriber object_sub_;
42-
ros::Timer timer_;
40+
rclcpp::Publisher<sensor_msgs::msg::PointCloud2>::SharedPtr pointcloud_pub_;
41+
rclcpp::Publisher<autoware_perception_msgs::msg::DynamicObjectWithFeatureArray>::SharedPtr
42+
dynamic_object_pub_;
43+
rclcpp::Subscription<dummy_perception_publisher::msg::Object>::SharedPtr object_sub_;
44+
rclcpp::TimerBase::SharedPtr timer_;
4345
tf2_ros::Buffer tf_buffer_;
4446
tf2_ros::TransformListener tf_listener_;
45-
std::vector<dummy_perception_publisher::Object> objects_;
47+
std::vector<dummy_perception_publisher::msg::Object> objects_;
4648
double visible_range_;
4749
double detection_successful_rate_;
4850
bool enable_ray_tracing_;
4951
bool use_object_recognition_;
5052
std::mt19937 random_generator_;
51-
void timerCallback(const ros::TimerEvent &);
53+
void timerCallback();
5254
void createObjectPointcloud(
5355
const double length, const double width, const double height, const double std_dev_x,
5456
const double std_dev_y, const double std_dev_z,
5557
const tf2::Transform & tf_base_link2moved_object,
5658
pcl::PointCloud<pcl::PointXYZ>::Ptr & pointcloud_ptr);
57-
void objectCallback(const dummy_perception_publisher::Object::ConstPtr & msg);
59+
void objectCallback(const dummy_perception_publisher::msg::Object::ConstSharedPtr msg);
5860

5961
public:
6062
DummyPerceptionPublisherNode();
61-
~DummyPerceptionPublisherNode(){};
63+
~DummyPerceptionPublisherNode() {}
6264
};
65+
66+
#endif // DUMMY_PERCEPTION_PUBLISHER__NODE_HPP_

simulator/util/dummy_perception_publisher/msg/Object.msg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
std_msgs/Header header
2-
uuid_msgs/UniqueID id
2+
unique_identifier_msgs/UUID id
33
dummy_perception_publisher/InitialState initial_state
44
autoware_perception_msgs/Semantic semantic
55
autoware_perception_msgs/Shape shape
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,34 @@
11
<?xml version="1.0"?>
2-
<package format="2">
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
34
<name>dummy_perception_publisher</name>
45
<version>0.1.0</version>
56
<description>The dummy_perception_publisher package</description>
67

78
<maintainer email="yukihiro.saito@tier4.jp">Yukihiro Saito</maintainer>
8-
<license>Apache2</license>
9+
<license>Apache License 2.0</license>
910

10-
<buildtool_depend>catkin</buildtool_depend>
11-
<build_depend>message_generation</build_depend>
12-
<build_depend>roscpp</build_depend>
13-
<build_depend>sensor_msgs</build_depend>
14-
<build_depend>std_msgs</build_depend>
15-
<build_depend>tf2</build_depend>
16-
<build_depend>tf2_geometry_msgs</build_depend>
17-
<build_depend>tf2_ros</build_depend>
18-
<build_depend>autoware_perception_msgs</build_depend>
19-
<build_depend>pcl_ros</build_depend>
20-
<build_depend>uuid_msgs</build_depend>
21-
<build_depend>unique_id</build_depend>
22-
<build_export_depend>message_generation</build_export_depend>
23-
<build_export_depend>roscpp</build_export_depend>
24-
<build_export_depend>sensor_msgs</build_export_depend>
25-
<build_export_depend>tf2</build_export_depend>
26-
<build_export_depend>tf2_geometry_msgs</build_export_depend>
27-
<build_export_depend>tf2_ros</build_export_depend>
28-
<build_export_depend>autoware_perception_msgs</build_export_depend>
29-
<build_export_depend>pcl_ros</build_export_depend>
30-
<build_export_depend>uuid_msgs</build_export_depend>
31-
<build_export_depend>unique_id</build_export_depend>
32-
<exec_depend>message_runtime</exec_depend>
33-
<exec_depend>roscpp</exec_depend>
34-
<exec_depend>sensor_msgs</exec_depend>
35-
<exec_depend>tf2</exec_depend>
36-
<exec_depend>tf2_geometry_msgs</exec_depend>
37-
<exec_depend>tf2_ros</exec_depend>
38-
<exec_depend>autoware_perception_msgs</exec_depend>
39-
<exec_depend>pcl_ros</exec_depend>
40-
<exec_depend>uuid_msgs</exec_depend>
41-
<exec_depend>unique_id</exec_depend>
11+
<buildtool_depend>ament_cmake_auto</buildtool_depend>
12+
<buildtool_depend>rosidl_default_generators</buildtool_depend>
13+
<exec_depend>rosidl_default_runtime</exec_depend>
4214

43-
<!-- The export tag contains other, unspecified, tags -->
44-
<export>
45-
<!-- Other tools can request additional information be placed here -->
15+
<test_depend>ament_lint_auto</test_depend>
16+
<test_depend>ament_lint_common</test_depend>
17+
18+
<depend>geometry_msgs</depend>
19+
<depend>autoware_perception_msgs</depend>
20+
<depend>libpcl-all-dev</depend>
21+
<depend>pcl_conversions</depend>
22+
<depend>rclcpp</depend>
23+
<depend>sensor_msgs</depend>
24+
<depend>std_msgs</depend>
25+
<depend>tf2</depend>
26+
<depend>tf2_geometry_msgs</depend>
27+
<depend>tf2_ros</depend>
28+
<depend>unique_identifier_msgs</depend>
4629

30+
<member_of_group>rosidl_interface_packages</member_of_group>
31+
<export>
32+
<build_type>ament_cmake</build_type>
4733
</export>
4834
</package>

0 commit comments

Comments
 (0)