5
5
#include < yaml-cpp/yaml.h>
6
6
7
7
#include < rclcpp/rclcpp.hpp>
8
- #include < visualization_msgs /msg/marker .hpp>
8
+ #include < geometry_msgs /msg/pose .hpp>
9
9
#include < visualization_msgs/msg/interactive_marker.hpp>
10
10
#include < visualization_msgs/msg/interactive_marker_control.hpp>
11
11
#include < interactive_markers/interactive_marker_server.hpp>
16
16
std::shared_ptr<rclcpp::Node> node;
17
17
static std::vector <wp_map_tools::msg::Waypoint> arWaypoint;
18
18
static std::vector <wp_map_tools::msg::Waypoint> arCharger;
19
+ static rclcpp::Publisher<visualization_msgs::msg::Marker>::SharedPtr marker_pub;
19
20
static visualization_msgs::msg::Marker text_marker;
20
21
static interactive_markers::InteractiveMarkerServer* pWaypointServer = NULL ;
21
22
@@ -161,12 +162,12 @@ void processWaypointFeedback(
161
162
const visualization_msgs::msg::InteractiveMarkerFeedback::ConstSharedPtr & feedback,
162
163
rclcpp::Logger logger)
163
164
{
164
- // std::ostringstream oss;
165
- // oss << feedback->marker_name << " is now at " << feedback->pose.position.x << ", " <<
166
- // feedback->pose.position.y << ", " << feedback->pose.position.z;
167
- // RCLCPP_WARN(logger, "%s", oss.str().c_str());
165
+ // std::ostringstream oss;
166
+ // oss << feedback->marker_name << " is now at " << feedback->pose.position.x << ", " <<
167
+ // feedback->pose.position.y << ", " << feedback->pose.position.z;
168
+ // RCLCPP_WARN(logger, "%s", oss.str().c_str());
168
169
169
- int nNumWP = arWaypoint.size ();
170
+ int nNumWP = arWaypoint.size ();
170
171
for (int i=0 ; i<nNumWP ; i++ )
171
172
{
172
173
if (feedback->marker_name == arWaypoint[i].name )
@@ -182,18 +183,16 @@ void NewWaypointInterMarker(interactive_markers::InteractiveMarkerServer* inServ
182
183
{
183
184
visualization_msgs::msg::InteractiveMarker wp_itr_marker;
184
185
visualization_msgs::msg::InteractiveMarkerControl wp_dis_ctrl;
185
- visualization_msgs::msg::Marker wp_dis_marker;
186
186
visualization_msgs::msg::InteractiveMarkerControl move_control;
187
187
wp_itr_marker.header .stamp =node->get_clock ()->now ();
188
188
wp_itr_marker.name = inName;
189
189
wp_itr_marker.description = inName;
190
190
wp_itr_marker.pose = InPose;
191
-
192
- // 显示外形
193
191
wp_itr_marker.header .frame_id = " map" ;
194
192
wp_itr_marker.header .stamp =node->get_clock ()->now ();
195
193
196
- // wp_dis_marker.ns = "waypoint_markers";
194
+ // 显示3D模型
195
+ visualization_msgs::msg::Marker wp_dis_marker;
197
196
wp_dis_marker.action = visualization_msgs::msg::Marker::ADD;
198
197
wp_dis_marker.type = visualization_msgs::msg::Marker::MESH_RESOURCE;
199
198
wp_dis_marker.mesh_resource = " package://wp_map_tools/meshes/waypoint.dae" ;
@@ -204,8 +203,20 @@ void NewWaypointInterMarker(interactive_markers::InteractiveMarkerServer* inServ
204
203
wp_dis_marker.color .g = 0.0 ;
205
204
wp_dis_marker.color .b = 1.0 ;
206
205
wp_dis_marker.color .a = 1.0 ;
207
-
208
206
wp_dis_ctrl.markers .push_back ( wp_dis_marker );
207
+
208
+ // 显示航点名称文字
209
+ visualization_msgs::msg::Marker text_marker;
210
+ text_marker.type = visualization_msgs::msg::Marker::TEXT_VIEW_FACING;
211
+ text_marker.scale .z = 0.3 ;
212
+ text_marker.color .r = 1 ;
213
+ text_marker.color .g = 1 ;
214
+ text_marker.color .b = 0 ;
215
+ text_marker.color .a = 1.0 ;
216
+ text_marker.text = inName;
217
+ text_marker.pose .position .z = 0.8 ;
218
+ wp_dis_ctrl.markers .push_back ( text_marker );
219
+
209
220
wp_dis_ctrl.always_visible = true ;
210
221
wp_itr_marker.controls .push_back ( wp_dis_ctrl );
211
222
@@ -294,7 +305,6 @@ void AddWayPointCallback(const wp_map_tools::msg::Waypoint::ConstPtr& wp)
294
305
}
295
306
}
296
307
297
-
298
308
int main (int argc, char ** argv)
299
309
{
300
310
rclcpp::init (argc, argv);
@@ -318,6 +328,7 @@ int main(int argc, char ** argv)
318
328
// 服务和话题初始化
319
329
auto add_waypoint_sub = node->create_subscription <wp_map_tools::msg::Waypoint>(" waterplus/add_waypoint" ,10 ,AddWayPointCallback);
320
330
auto service = node->create_service <wp_map_tools::srv::SaveWaypoints>(" waterplus/save_waypoints" , saveWaypoints);
331
+ marker_pub = node->create_publisher <visualization_msgs::msg::Marker>(" text_marker" , 100 );
321
332
322
333
RCLCPP_INFO (node->get_logger (), " wp_edit_node 初始化完毕" );
323
334
0 commit comments