basic_shapes.cpp
Go to the documentation of this file.
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 and DELETE
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     marker_pub.publish(marker);
00109 // %EndTag(PUBLISH)%
00110 
00111     // Cycle between different shapes
00112 // %Tag(CYCLE_SHAPES)%
00113     switch (shape)
00114     {
00115     case visualization_msgs::Marker::CUBE:
00116       shape = visualization_msgs::Marker::SPHERE;
00117       break;
00118     case visualization_msgs::Marker::SPHERE:
00119       shape = visualization_msgs::Marker::ARROW;
00120       break;
00121     case visualization_msgs::Marker::ARROW:
00122       shape = visualization_msgs::Marker::CYLINDER;
00123       break;
00124     case visualization_msgs::Marker::CYLINDER:
00125       shape = visualization_msgs::Marker::CUBE;
00126       break;
00127     }
00128 // %EndTag(CYCLE_SHAPES)%
00129 
00130 // %Tag(SLEEP_END)%
00131     r.sleep();
00132   }
00133 // %EndTag(SLEEP_END)%
00134 }
00135 // %EndTag(FULLTEXT)%


visualization_marker_tutorials
Author(s): Josh Faust
autogenerated on Sat Dec 28 2013 17:47:35