ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How can i send markers to specified position along with point cloud, inside rviz ?

asked 2016-07-07 11:24:58 -0500

dinesh gravatar image

updated 2016-07-07 12:50:42 -0500

I was trying to use tf2 method to do that, but dont know how can i achive this task with tf2/ tf1 method, can anyone provide me some idea that how markers( in my case lines, vectors, planes, point with specific color, text). Is their another method rather than tf ? i was sending this marker node to check it:

  #include <ros/ros.h>
   #include <visualization_msgs/Marker.h>

   int main( int argc, char** argv )
   {
     ros::init(argc, argv, "basic_shapes");
     ros::NodeHandle n;
     ros::Rate r(1);
     ros::Publisher marker_pub = n.advertise<visualization_msgs::Marker>("visualization_marker", 1);

     // Set our initial shape type to be a cube
     uint32_t shape = visualization_msgs::Marker::CUBE;

     while (ros::ok())
     {
       visualization_msgs::Marker marker;

       marker.header.frame_id = "/my_frame";
       marker.header.stamp = ros::Time::now();

       marker.ns = "basic_shapes";
       marker.id = 0;

    marker.type = shape;

     marker.action = visualization_msgs::Marker::ADD;
   marker.pose.position.x = 0;
       marker.pose.position.y = 0;
       marker.pose.position.z = 0;
       marker.pose.orientation.x = 0.0;
       marker.pose.orientation.y = 0.0;
       marker.pose.orientation.z = 0.0;
       marker.pose.orientation.w = 1.0;

           // Set the scale of the marker -- 1x1x1 here means 1m on a side
           marker.scale.x = 1.0;
           marker.scale.y = 1.0;
           marker.scale.z = 1.0;


       // Set the color -- be sure to set alpha to something non-zero!
       marker.color.r = 0.0f;
       marker.color.g = 1.0f;
       marker.color.b = 0.0f;
       marker.color.a = 1.0;

       marker.lifetime = ros::Duration();

       // Publish the marker
       while (marker_pub.getNumSubscribers() < 1)
       {
         if (!ros::ok())
         {
           return 0;
         }
         ROS_WARN_ONCE("Please create a subscriber to the marker");
         sleep(1);
       }
       marker_pub.publish(marker);

       // Cycle between different shapes
       switch (shape)
       {
       case visualization_msgs::Marker::CUBE:
         shape = visualization_msgs::Marker::SPHERE;
        break;
      case visualization_msgs::Marker::SPHERE:
        shape = visualization_msgs::Marker::ARROW;
        break;
      case visualization_msgs::Marker::ARROW:
        shape = visualization_msgs::Marker::CYLINDER;
        break;
      case visualization_msgs::Marker::CYLINDER:
        shape = visualization_msgs::Marker::CUBE;
        break;
      }

      r.sleep();
    }
  }

Inside the rviz i put /my_frame than i could see the markers, but at same time point cloud cant be visualized, how sould i visualize point cloud along with markers?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2016-07-07 11:30:03 -0500

dcconner gravatar image

updated 2016-07-07 11:30:17 -0500

You need to publish a specific marker message. You code needs to define the type and location of the markers, and publish them to a topic.

http://docs.ros.org/jade/api/visualiz...

http://docs.ros.org/jade/api/visualiz...

edit flag offensive delete link more

Comments

ok but after sending the marker topic, how to visualize it at the same time point cloud is been displaying? I added the marker topic = visualization,but it needs fixed frame to be my frameand when i do that i cant visualize cloud at same time how to solve this, how to visualize both at same time?

dinesh gravatar image dinesh  ( 2016-07-07 12:26:00 -0500 )edit

Define the marker in the same frame as the cloud?

joq gravatar image joq  ( 2016-07-07 12:31:48 -0500 )edit

How can i do that ? is using tf neccesary for this task?

dinesh gravatar image dinesh  ( 2016-07-07 12:52:07 -0500 )edit

Set header.frame_id in the marker message to the correct frame ID.

joq gravatar image joq  ( 2016-07-07 13:14:37 -0500 )edit

o god now it is working, yes, im feeling very happy now. thank u for your support.

dinesh gravatar image dinesh  ( 2016-07-07 14:21:10 -0500 )edit

Please accept the answer of @dcconner, so others will know it works.

joq gravatar image joq  ( 2016-07-07 14:46:30 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-07-07 11:24:58 -0500

Seen: 1,268 times

Last updated: Jul 07 '16