Skip to content

Commit f5ec347

Browse files
committed
Added grasp pose vis marker
1 parent db91413 commit f5ec347

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

object_detection/perception.rviz

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Panels:
2525
Experimental: false
2626
Name: Time
2727
SyncMode: 0
28-
SyncSource: Clean Object PCL
28+
SyncSource: ""
2929
Visualization Manager:
3030
Class: ""
3131
Displays:
@@ -216,6 +216,14 @@ Visualization Manager:
216216
Use Fixed Frame: true
217217
Use rainbow: true
218218
Value: true
219+
- Class: rviz/Marker
220+
Enabled: true
221+
Marker Topic: /object_pose_detection/object_pose_detection/grasp_pose
222+
Name: Marker
223+
Namespaces:
224+
{}
225+
Queue Size: 100
226+
Value: true
219227
Enabled: true
220228
Global Options:
221229
Background Color: 48; 48; 48

object_detection/src/object_pose_detection.cpp

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ target_link_libraries(ground_plane_segmentation ${catkin_LIBRARIES})
1414

1515
#include <ros/ros.h>
1616
#include "object_detection/boost.h"
17+
#include <visualization_msgs/Marker.h>
1718

1819
// TF includes
1920
#include <tf/tf.h>
@@ -57,6 +58,7 @@ ros::Publisher coef_pub;
5758
ros::Publisher bbox_pub;
5859
ros::Publisher template_pub;
5960
ros::Publisher pose_pub;
61+
ros::Publisher marker_pub;
6062

6163
// Globals
6264
bool invert;
@@ -75,7 +77,7 @@ sensor_msgs::PointCloud2 template_msg;
7577
tf::TransformListener *listener;
7678
geometry_msgs::Pose pose_msg;
7779
Eigen::Affine3d pose_transform;
78-
double dimensions[3];
80+
double dimensions[] = {0.1, 0.02, 0.02};
7981
double icp_fitness_score;
8082
pcl::PCLPointCloud2::Ptr input_pcl(new pcl::PCLPointCloud2);
8183

@@ -90,6 +92,48 @@ bool ICP_SUCCESS = false;
9092
bool FIRST = true;
9193
bool POSE_FLAG = false;
9294

95+
void publish_grasp_marker(geometry_msgs::Pose& p)
96+
{
97+
visualization_msgs::Marker marker;
98+
// Set the frame ID and timestamp. See the TF tutorials for information on these.
99+
marker.header.frame_id = "camera_depth_optical_frame";
100+
marker.header.stamp = ros::Time::now();
101+
102+
// Set the namespace and id for this marker
103+
marker.ns = "grasp_pose";
104+
marker.id = 0;
105+
106+
// Set the marker type. Initially this is CUBE, and cycles between that and SPHERE, ARROW, and CYLINDER
107+
marker.type = visualization_msgs::Marker::CUBE;
108+
109+
// Set the marker action. Options are ADD, DELETE, and new in ROS Indigo: 3 (DELETEALL)
110+
marker.action = visualization_msgs::Marker::ADD;
111+
112+
// Set the pose of the marker. This is a full 6DOF pose relative to the frame/time specified in the header
113+
marker.pose.position.x = p.position.x;
114+
marker.pose.position.y = p.position.y;
115+
marker.pose.position.z = p.position.z;
116+
marker.pose.orientation.x = p.orientation.x;
117+
marker.pose.orientation.y = p.orientation.y;
118+
marker.pose.orientation.z = p.orientation.z;
119+
marker.pose.orientation.w = p.orientation.w;
120+
121+
// Set the scale of the marker -- 1x1x1 here means 1m on a side
122+
marker.scale.x = dimensions[0];
123+
marker.scale.y = dimensions[1];
124+
marker.scale.z = dimensions[2];
125+
126+
// Set the color -- be sure to set alpha to something non-zero!
127+
marker.color.r = 1.0f;
128+
marker.color.g = 0.0f;
129+
marker.color.b = 0.0f;
130+
marker.color.a = 0.5f;
131+
132+
// Publish the marker
133+
marker.lifetime = ros::Duration();
134+
marker_pub.publish(marker);
135+
}
136+
93137
void publish_pose(Eigen::Matrix4d H)
94138
{
95139
// Set translation
@@ -119,6 +163,9 @@ void publish_pose(Eigen::Matrix4d H)
119163
p.orientation.z = quaternion.z();
120164
p.orientation.w = quaternion.w();
121165

166+
// Publish visualization marker
167+
publish_grasp_marker(p);
168+
122169
// Broadcast the transforms
123170
static tf::TransformBroadcaster br;
124171
br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "camera_depth_optical_frame", "object_frame"));
@@ -211,7 +258,7 @@ void pcl_callback(const sensor_msgs::PointCloud2ConstPtr& input)
211258
icp_pub.publish(output_msg);
212259
template_msg.header.frame_id = "camera_depth_optical_frame";
213260
template_pub.publish(template_msg);
214-
publish_bounding_box(icp_transform);
261+
// publish_bounding_box(icp_transform);
215262
publish_pose(icp_transform);
216263
}
217264
}
@@ -415,6 +462,7 @@ int main(int argc, char** argv)
415462
bbox_pub = nh.advertise<sensor_msgs::PointCloud2>("/icp/bbox_points", 1);
416463
template_pub = nh.advertise<sensor_msgs::PointCloud2>("/icp/template", 1);
417464
pose_pub = nh.advertise<geometry_msgs::Pose>("/icp/pose", 1);
465+
marker_pub = nh.advertise<visualization_msgs::Marker>("object_pose_detection/grasp_pose", 1);
418466

419467
// Spin
420468
ros::spin();

0 commit comments

Comments
 (0)