Skip to content

Commit 8721757

Browse files
committed
first commit
1 parent d945bbc commit 8721757

28 files changed

+1489
-0
lines changed

CMakeLists.txt

+172
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
cmake_minimum_required(VERSION 3.8)
2+
project(wp_map_tools)
3+
4+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
5+
add_compile_options(-Wall -Wextra -Wpedantic)
6+
endif()
7+
8+
# find dependencies
9+
find_package(ament_cmake REQUIRED)
10+
find_package(geometry_msgs REQUIRED)
11+
find_package(visualization_msgs REQUIRED)
12+
find_package(interactive_markers REQUIRED)
13+
find_package(nav_msgs REQUIRED)
14+
find_package(rclcpp REQUIRED)
15+
find_package(rclcpp_components REQUIRED)
16+
find_package(yaml-cpp REQUIRED)
17+
18+
find_package(rviz_common REQUIRED)
19+
find_package(rviz_default_plugins REQUIRED)
20+
find_package(rviz_ogre_vendor REQUIRED)
21+
find_package(rviz_rendering REQUIRED)
22+
find_package(pluginlib REQUIRED)
23+
24+
find_package(tf2 REQUIRED)
25+
find_package(tf2_geometry_msgs REQUIRED)
26+
find_package(tf2_ros REQUIRED)
27+
28+
include_directories(include)
29+
include_directories(${QT_INCLUDE_DIRS})
30+
# uncomment the following section in order to fill in
31+
# further dependencies manually.
32+
# find_package(<dependency> REQUIRED)
33+
34+
ament_export_dependencies(
35+
"interactive_markers"
36+
"rclcpp"
37+
"rclcpp_components"
38+
"tf2"
39+
"tf2_geometry_msgs"
40+
"tf2_ros"
41+
"visualization_msgs"
42+
"geometry_msgs"
43+
"yaml-cpp")
44+
45+
find_package(rosidl_default_generators REQUIRED)
46+
rosidl_generate_interfaces(${PROJECT_NAME}
47+
"msg/Waypoint.msg"
48+
"srv/SaveWaypoints.srv"
49+
DEPENDENCIES
50+
"geometry_msgs"
51+
)
52+
53+
rosidl_get_typesupport_target(cpp_typesupport_target ${PROJECT_NAME} "rosidl_typesupport_cpp")
54+
55+
# 库
56+
set(wp_map_plugins_headers_to_moc
57+
include/wp_map_tools/add_waypoint_tool.hpp
58+
)
59+
60+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
61+
set(CMAKE_AUTOMOC ON)
62+
63+
find_package(Qt5 ${rviz_QT_VERSION} REQUIRED Core Widgets)
64+
set(QT_LIBRARIES Qt5::Widgets)
65+
add_definitions(-DQT_NO_KEYWORDS)
66+
67+
set(library_name wp_map_plugins)
68+
69+
add_library(${library_name} SHARED
70+
include/wp_map_tools/add_waypoint_tool.hpp
71+
src/add_waypoint_tool.cpp
72+
${wp_map_plugins_headers_to_moc}
73+
)
74+
75+
set(dependencies
76+
geometry_msgs
77+
pluginlib
78+
Qt5
79+
rclcpp
80+
rviz_common
81+
rviz_default_plugins
82+
rviz_ogre_vendor
83+
rviz_rendering
84+
tf2_geometry_msgs
85+
visualization_msgs
86+
)
87+
88+
ament_target_dependencies(${library_name}
89+
${dependencies}
90+
)
91+
92+
target_include_directories(${library_name} PUBLIC
93+
${Qt5Widgets_INCLUDE_DIRS}
94+
${OGRE_INCLUDE_DIRS}
95+
)
96+
97+
target_link_libraries(${library_name}
98+
rviz_common::rviz_common
99+
${QT_LIBRARIES}
100+
"${cpp_typesupport_target}"
101+
)
102+
103+
# Causes the visibility macros to use dllexport rather than dllimport,
104+
# which is appropriate when building the dll but not consuming it.
105+
# TODO: Make this specific to this project (not rviz default plugins)
106+
target_compile_definitions(${library_name} PRIVATE "RVIZ_DEFAULT_PLUGINS_BUILDING_LIBRARY")
107+
ament_export_targets(${library_name} HAS_LIBRARY_TARGET)
108+
109+
# prevent pluginlib from using boost
110+
target_compile_definitions(${library_name} PUBLIC "PLUGINLIB__DISABLE_BOOST_FUNCTIONS")
111+
112+
pluginlib_export_plugin_description_file(rviz_common plugins_description.xml)
113+
114+
install(
115+
FILES
116+
plugins_description.xml
117+
DESTINATION share/${PROJECT_NAME}
118+
)
119+
120+
install(
121+
TARGETS ${library_name}
122+
EXPORT ${library_name}
123+
ARCHIVE DESTINATION lib
124+
LIBRARY DESTINATION lib
125+
RUNTIME DESTINATION bin
126+
INCLUDES DESTINATION include
127+
)
128+
129+
install(
130+
DIRECTORY include/
131+
DESTINATION include/
132+
)
133+
134+
# 编译节点
135+
add_executable(wp_edit_node src/wp_edit_node.cpp)
136+
ament_target_dependencies(wp_edit_node
137+
"rclcpp"
138+
"visualization_msgs"
139+
"interactive_markers"
140+
"yaml-cpp"
141+
)
142+
target_link_libraries(wp_edit_node "yaml-cpp" "${cpp_typesupport_target}")
143+
144+
add_executable(wp_saver src/wp_saver.cpp)
145+
ament_target_dependencies(wp_saver rclcpp )
146+
target_link_libraries(wp_saver "${cpp_typesupport_target}")
147+
148+
# 安装节点
149+
install(DIRECTORY launch meshes rviz msg srv icons
150+
DESTINATION share/${PROJECT_NAME})
151+
152+
install(
153+
TARGETS
154+
wp_edit_node
155+
wp_saver
156+
DESTINATION
157+
lib/${PROJECT_NAME}
158+
)
159+
160+
if(BUILD_TESTING)
161+
find_package(ament_lint_auto REQUIRED)
162+
# the following line skips the linter which checks for copyrights
163+
# comment the line when a copyright and license is added to all source files
164+
set(ament_cmake_copyright_FOUND TRUE)
165+
# the following line skips cpplint (only works in a git repo)
166+
# comment the line when this package is in a git repo and when
167+
# a copyright and license is added to all source files
168+
set(ament_cmake_cpplint_FOUND TRUE)
169+
ament_lint_auto_find_test_dependencies()
170+
endif()
171+
172+
ament_package()

README.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# MapTools工具
2+
3+
## 使用步骤
4+
5+
1. 安装ROS(Humble)
6+
2. 获取源码:
7+
```
8+
cd ~/catkin_ws/src/
9+
git clone https://github.com/6-robot/wp_map_tools.git
10+
```
11+
3. 安装依赖项(根据ROS版本选择其中一个):
12+
```
13+
cd ~/ros2_ws/src/wp_map_tools/scripts/
14+
./install_for_humble.sh
15+
```
16+
4. 编译
17+
```
18+
cd ~/ros2_ws
19+
colcon build --symlink-install
20+
```
21+
22+
## 平台介绍
23+
MapTools工具是[北京六部工坊科技有限公司](http://www.6-robot.com)为旗下WP系列机器人快速设置地图航点所设计的辅助工具,具有操作简单,效果直观的优点。目前支持启智ROS,启智MANI,启程3,启程4和启明1等型号的机器人.
24+
![Nav pic](./media/wpb_home_nav.png)
25+
26+
## 操作方法
27+
28+
### 1. 打开地图
29+
仿真:
30+
```
31+
ros2 launch wp_map_tools add_waypoint_sim.launch.py
32+
```
33+
![1 pic](./media/map.png)
34+
35+
### 2. 设置航点
36+
在Rviz工具栏点击"Add Waypoint"按钮可在地图上设置航点。
37+
![2 pic](./media/toolbar.png)
38+
![3 pic](./media/add_waypoint.png)
39+
![4 pic](./media/waypoint.png)
40+
![MapTools pic](./media/map_tools.png)
41+
42+
### 3. 保存航点
43+
航点设置完毕后,使用如下指令保存航点:
44+
```
45+
ros2 run wp_map_tools wp_saver
46+
```

icons/classes/AddCharger.png

488 Bytes
Loading

icons/classes/AddWaypointTool.png

2.98 KB
Loading
+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#ifndef ADD_WAYPOINT_TOOL_H
2+
#define ADD_WAYPOINT_TOOL_H
3+
4+
#ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829
5+
# include <QObject>
6+
# include <rclcpp/rclcpp.hpp>
7+
# include <rviz_common/tool.hpp>
8+
#include "rviz_default_plugins/tools/pose/pose_tool.hpp"
9+
#include <rviz_default_plugins/tools/pose/pose_tool.hpp>
10+
#include "rviz_default_plugins/visibility_control.hpp"
11+
#include <rviz_common/display_context.hpp>
12+
#include <rviz_common/properties/string_property.hpp>
13+
#endif
14+
15+
#include <wp_map_tools/msg/waypoint.hpp>
16+
17+
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
18+
#include <tf2_ros/transform_listener.h>
19+
20+
21+
namespace rviz_common
22+
{
23+
24+
class DisplayContext;
25+
26+
namespace properties
27+
{
28+
class StringProperty;
29+
} // namespace properties
30+
} // namespace rviz_common
31+
32+
namespace wp_map_tools
33+
{
34+
class Arrow;
35+
class DisplayContext;
36+
class StringProperty;
37+
38+
class RVIZ_DEFAULT_PLUGINS_PUBLIC AddWaypointTool: public rviz_default_plugins::tools::PoseTool
39+
{
40+
Q_OBJECT
41+
public:
42+
AddWaypointTool();
43+
~AddWaypointTool() override;
44+
45+
void onInitialize() override;
46+
47+
protected:
48+
void onPoseSet(double x, double y, double theta) override;
49+
50+
private Q_SLOTS:
51+
void updateTopic();
52+
53+
private:
54+
rclcpp::Node::SharedPtr raw_node;
55+
rclcpp::Publisher<wp_map_tools::msg::Waypoint>::SharedPtr pub_;
56+
// ros::ServiceClient cliGetWPName;
57+
rviz_common::properties::StringProperty* topic_property_;
58+
};
59+
60+
}
61+
62+
#endif // ADD_WAYPOINT_TOOL_H

launch/add_waypoint_sim.launch.py

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright 2023 6-robot.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# Authors: Zhang Wanjie
18+
19+
import os
20+
from ament_index_python.packages import get_package_share_directory
21+
from launch import LaunchDescription
22+
from launch.substitutions import LaunchConfiguration
23+
from launch_ros.actions import Node
24+
import launch_ros.actions
25+
import launch.actions
26+
import launch.events
27+
28+
def generate_launch_description():
29+
launch_file_dir = os.path.join(get_package_share_directory('wp_map_tools'), 'launch')
30+
31+
# 声明launch文件参数,用于指定map.yaml文件路径
32+
map_file = os.path.join(
33+
get_package_share_directory('wpr_simulation2'),
34+
'map',
35+
'map.yaml'
36+
)
37+
38+
# 创建map_server节点
39+
map_server_cmd = Node(
40+
package='nav2_map_server',
41+
executable='map_server',
42+
name='map_server',
43+
output='screen',
44+
parameters=[{'yaml_filename': map_file},
45+
{'topic': 'map'},
46+
{'frame_id': 'map'},
47+
{'output': 'screen'},
48+
{'use_sim_time': True}]
49+
)
50+
51+
lifecycle_nodes = ['map_server']
52+
use_sim_time = True
53+
autostart = True
54+
55+
start_lifecycle_manager_cmd = launch_ros.actions.Node(
56+
package='nav2_lifecycle_manager',
57+
executable='lifecycle_manager',
58+
name='lifecycle_manager',
59+
output='screen',
60+
emulate_tty=True, # https://github.com/ros2/launch/issues/188
61+
parameters=[{'use_sim_time': use_sim_time},
62+
{'autostart': autostart},
63+
{'node_names': lifecycle_nodes}])
64+
65+
map_tf_cmd = launch_ros.actions.Node(
66+
package='tf2_ros',
67+
executable='static_transform_publisher',
68+
output='screen',
69+
arguments=['0', '0', '0', '0', '0', '0', 'map', 'base_link'])
70+
71+
wp_edit_cmd = Node(
72+
package='wp_map_tools',
73+
executable='wp_edit_node',
74+
name='wp_edit_node',
75+
output='screen'
76+
)
77+
78+
rviz_cmd = Node(
79+
package='rviz2',
80+
executable='rviz2',
81+
name='rviz2',
82+
arguments=['-d', [os.path.join(get_package_share_directory('wp_map_tools'), 'rviz', 'edit.rviz')]]
83+
)
84+
85+
# 创建一个事件处理程序,用于在Rviz2退出时发送一个事件
86+
shutdown_handler = launch.actions.RegisterEventHandler(
87+
launch.event_handlers.OnProcessExit(
88+
target_action=rviz_cmd,
89+
on_exit=[
90+
launch.actions.LogInfo(
91+
msg=(launch.substitutions.EnvironmentVariable(name='USER'),' closed the RViz2 window')
92+
),
93+
launch.actions.EmitEvent(event=launch.events.Shutdown(reason='Window closed'))
94+
]
95+
)
96+
)
97+
98+
ld = LaunchDescription()
99+
100+
# Add the commands to the launch description
101+
ld.add_action(map_server_cmd)
102+
ld.add_action(start_lifecycle_manager_cmd)
103+
ld.add_action(map_tf_cmd)
104+
ld.add_action(wp_edit_cmd)
105+
ld.add_action(rviz_cmd)
106+
# 添加事件处理程序到LaunchDescription
107+
ld.add_action(shutdown_handler)
108+
109+
return ld

media/add_waypoint.png

143 KB
Loading

media/map.png

149 KB
Loading

media/map_tools.png

150 KB
Loading

media/toolbar.png

5.72 KB
Loading

media/waypoint.png

153 KB
Loading

media/wpb_home_nav.png

339 KB
Loading

0 commit comments

Comments
 (0)