00001 /* 00002 * Copyright (c) 2010, Willow Garage, Inc. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of the Willow Garage, Inc. nor the names of its 00014 * contributors may be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 00030 // %Tag(FULLTEXT)% 00031 // %Tag(INCLUDES)% 00032 #include <ros/ros.h> 00033 #include <visualization_msgs/Marker.h> 00034 // %EndTag(INCLUDES)% 00035 00036 // %Tag(INIT)% 00037 int main( int argc, char** argv ) 00038 { 00039 ros::init(argc, argv, "basic_shapes"); 00040 ros::NodeHandle n; 00041 ros::Rate r(1); 00042 ros::Publisher marker_pub = n.advertise<visualization_msgs::Marker>("visualization_marker", 1); 00043 // %EndTag(INIT)% 00044 00045 // Set our initial shape type to be a cube 00046 // %Tag(SHAPE_INIT)% 00047 uint32_t shape = visualization_msgs::Marker::CUBE; 00048 // %EndTag(SHAPE_INIT)% 00049 00050 // %Tag(MARKER_INIT)% 00051 while (ros::ok()) 00052 { 00053 visualization_msgs::Marker marker; 00054 // Set the frame ID and timestamp. See the TF tutorials for information on these. 00055 marker.header.frame_id = "/my_frame"; 00056 marker.header.stamp = ros::Time::now(); 00057 // %EndTag(MARKER_INIT)% 00058 00059 // Set the namespace and id for this marker. This serves to create a unique ID 00060 // Any marker sent with the same namespace and id will overwrite the old one 00061 // %Tag(NS_ID)% 00062 marker.ns = "basic_shapes"; 00063 marker.id = 0; 00064 // %EndTag(NS_ID)% 00065 00066 // Set the marker type. Initially this is CUBE, and cycles between that and SPHERE, ARROW, and CYLINDER 00067 // %Tag(TYPE)% 00068 marker.type = shape; 00069 // %EndTag(TYPE)% 00070 00071 // Set the marker action. Options are ADD, DELETE, and new in ROS Indigo: 3 (DELETEALL) 00072 // %Tag(ACTION)% 00073 marker.action = visualization_msgs::Marker::ADD; 00074 // %EndTag(ACTION)% 00075 00076 // Set the pose of the marker. This is a full 6DOF pose relative to the frame/time specified in the header 00077 // %Tag(POSE)% 00078 marker.pose.position.x = 0; 00079 marker.pose.position.y = 0; 00080 marker.pose.position.z = 0; 00081 marker.pose.orientation.x = 0.0; 00082 marker.pose.orientation.y = 0.0; 00083 marker.pose.orientation.z = 0.0; 00084 marker.pose.orientation.w = 1.0; 00085 // %EndTag(POSE)% 00086 00087 // Set the scale of the marker -- 1x1x1 here means 1m on a side 00088 // %Tag(SCALE)% 00089 marker.scale.x = 1.0; 00090 marker.scale.y = 1.0; 00091 marker.scale.z = 1.0; 00092 // %EndTag(SCALE)% 00093 00094 // Set the color -- be sure to set alpha to something non-zero! 00095 // %Tag(COLOR)% 00096 marker.color.r = 0.0f; 00097 marker.color.g = 1.0f; 00098 marker.color.b = 0.0f; 00099 marker.color.a = 1.0; 00100 // %EndTag(COLOR)% 00101 00102 // %Tag(LIFETIME)% 00103 marker.lifetime = ros::Duration(); 00104 // %EndTag(LIFETIME)% 00105 00106 // Publish the marker 00107 // %Tag(PUBLISH)% 00108 while (marker_pub.getNumSubscribers() < 1) 00109 { 00110 if (!ros::ok()) 00111 { 00112 return 0; 00113 } 00114 ROS_WARN_ONCE("Please create a subscriber to the marker"); 00115 sleep(1); 00116 } 00117 marker_pub.publish(marker); 00118 // %EndTag(PUBLISH)% 00119 00120 // Cycle between different shapes 00121 // %Tag(CYCLE_SHAPES)% 00122 switch (shape) 00123 { 00124 case visualization_msgs::Marker::CUBE: 00125 shape = visualization_msgs::Marker::SPHERE; 00126 break; 00127 case visualization_msgs::Marker::SPHERE: 00128 shape = visualization_msgs::Marker::ARROW; 00129 break; 00130 case visualization_msgs::Marker::ARROW: 00131 shape = visualization_msgs::Marker::CYLINDER; 00132 break; 00133 case visualization_msgs::Marker::CYLINDER: 00134 shape = visualization_msgs::Marker::CUBE; 00135 break; 00136 } 00137 // %EndTag(CYCLE_SHAPES)% 00138 00139 // %Tag(SLEEP_END)% 00140 r.sleep(); 00141 } 00142 // %EndTag(SLEEP_END)% 00143 } 00144 // %EndTag(FULLTEXT)%