Skip to content

Commit f81dc0f

Browse files
authored
Added publisher for points in addition to poses (#15)
1 parent c200eb0 commit f81dc0f

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

include/rviz_tool_cursor/rviz_tool_cursor.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,13 @@ public Q_SLOTS:
6060

6161
ros::NodeHandle nh_;
6262

63-
ros::Publisher pub_;
63+
ros::Publisher pose_pub_;
6464

65-
rviz::StringProperty* topic_property_;
65+
ros::Publisher point_pub_;
66+
67+
rviz::StringProperty* pose_topic_property_;
68+
69+
rviz::StringProperty* point_topic_property_;
6670

6771
rviz::IntProperty* patch_size_property_;
6872

src/rviz_tool_cursor/rviz_tool_cursor.cpp

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <geometry_msgs/PoseStamped.h>
2+
#include <geometry_msgs/PointStamped.h>
23

34
#include <OgreMovableObject.h>
45
#include <OgreSceneManager.h>
@@ -102,8 +103,12 @@ ToolCursor::ToolCursor()
102103
shortcut_key_ = 'c';
103104

104105

105-
topic_property_ = new rviz::StringProperty("Topic", "/selection_point",
106-
"The topic on which to publish points",
106+
pose_topic_property_ = new rviz::StringProperty("Pose Topic", "/selection_point",
107+
"The topic on which to publish pose messages",
108+
getPropertyContainer(), SLOT(updateTopic()), this);
109+
110+
point_topic_property_ = new rviz::StringProperty("Point Topic", "/clicked_point",
111+
"The topic on which to publish point messages",
107112
getPropertyContainer(), SLOT(updateTopic()), this);
108113

109114
patch_size_property_ = new rviz::IntProperty("Patch Size", 10,
@@ -151,7 +156,8 @@ void ToolCursor::deactivate()
151156

152157
void ToolCursor::updateTopic()
153158
{
154-
pub_ = nh_.advertise<geometry_msgs::PoseStamped>(topic_property_->getStdString(), 1, true);
159+
pose_pub_ = nh_.advertise<geometry_msgs::PoseStamped>(pose_topic_property_->getStdString(), 1, true);
160+
point_pub_ = nh_.advertise<geometry_msgs::PointStamped>(point_topic_property_->getStdString(), 1, true);
155161
}
156162

157163
int ToolCursor::processMouseEvent(rviz::ViewportMouseEvent& event)
@@ -185,20 +191,30 @@ int ToolCursor::processMouseEvent(rviz::ViewportMouseEvent& event)
185191
if(event.leftUp())
186192
{
187193
// Publish a point message upon release of the left mouse button
188-
geometry_msgs::PoseStamped msg;
189-
msg.header.frame_id = context_->getFixedFrame().toStdString();
190-
msg.header.stamp = ros::Time::now();
194+
geometry_msgs::PoseStamped pose_msg;
195+
pose_msg.header.frame_id = context_->getFixedFrame().toStdString();
196+
pose_msg.header.stamp = ros::Time::now();
197+
198+
pose_msg.pose.position.x = static_cast<double>(position.x);
199+
pose_msg.pose.position.y = static_cast<double>(position.y);
200+
pose_msg.pose.position.z = static_cast<double>(position.z);
201+
202+
pose_msg.pose.orientation.w = static_cast<double>(q.w);
203+
pose_msg.pose.orientation.x = static_cast<double>(q.x);
204+
pose_msg.pose.orientation.y = static_cast<double>(q.y);
205+
pose_msg.pose.orientation.z = static_cast<double>(q.z);
206+
207+
pose_pub_.publish(pose_msg);
191208

192-
msg.pose.position.x = static_cast<double>(position.x);
193-
msg.pose.position.y = static_cast<double>(position.y);
194-
msg.pose.position.z = static_cast<double>(position.z);
209+
geometry_msgs::PointStamped point_msg;
210+
point_msg.header.frame_id = context_->getFixedFrame().toStdString();
211+
point_msg.header.stamp = ros::Time::now();
195212

196-
msg.pose.orientation.w = static_cast<double>(q.w);
197-
msg.pose.orientation.x = static_cast<double>(q.x);
198-
msg.pose.orientation.y = static_cast<double>(q.y);
199-
msg.pose.orientation.z = static_cast<double>(q.z);
213+
point_msg.point.x = static_cast<double>(position.x);
214+
point_msg.point.y = static_cast<double>(position.y);
215+
point_msg.point.z = static_cast<double>(position.z);
200216

201-
pub_.publish(msg);
217+
point_pub_.publish(point_msg);
202218
}
203219
}
204220
else

0 commit comments

Comments
 (0)