Ask Your Question
0

Rviz doesn't display text marker.

asked 2017-04-24 07:21:17 -0500

Black_Cry1 gravatar image

updated 2017-04-26 13:46:10 -0500

Hello,

I'm trying to display some text in rviz via visualization_msgs/Marker. Other markers displays properly, but when I want to display text, then nothing appears.

This is my message, and code:

header: 
  seq: 755
  stamp: 
    secs: 1493036259
    nsecs: 505534537
  frame_id: /my_frame
ns: basic_shapes
id: 5
type: 9
action: 0
pose: 
  position: 
    x: 5.0
    y: 1.0
    z: 1.0
  orientation: 

    x: 0.0
    y: 0.0
    z: 0.0
    w: 1.0
scale: 
  x: 0.3
  y: 0.3
  z: 1.0
color: 
  r: 1.0
  g: 1.0
  b: 1.0

  a: 1.0
lifetime: 
  secs: 0
  nsecs:         0
frame_locked: False
points: []
colors: []
text: blablabla
mesh_resource: ''
mesh_use_embedded_materials: False
---

#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::TEXT_VIEW_FACING;
  uint32_t action = 0;
  uint32_t iteration = 0;
  while (ros::ok())
  {
    visualization_msgs::Marker marker;
    // Set the frame ID and timestamp.  See the TF tutorials for information on these.
    marker.header.frame_id = "/my_frame";
    marker.header.stamp = ros::Time::now();

// Set the namespace and id for this marker.  This serves to create a unique ID
// Any marker sent with the same namespace and id will overwrite the old one
marker.ns = "basic_shapes";
marker.id = iteration;

// Set the marker type.  Initially this is CUBE, and cycles between that and SPHERE, ARROW, and CYLINDER
marker.type = shape;

// Set the marker action.  Options are ADD, DELETE, and new in ROS Indigo: 3 (DELETEALL)
marker.action = action;

// Set the pose of the marker.  This is a full 6DOF pose relative to the frame/time specified in the header
marker.pose.position.x = 0.0 + iteration;
marker.pose.position.y = 1.0;
marker.pose.position.z = 1.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 = 0.3;
marker.scale.y = 0.3;
marker.scale.z = 1.0;

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


marker.lifetime = ros::Duration();
marker.text = "blablabla";

// 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);
    iteration++;
    if (iteration > 5)
    {
      iteration = 0;

    }
    r.sleep();
  }
}

I don't now if the problem is with the code, or the rviz. I would like to add that I use ros kinetic, and my rviz version is 1.12.4.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-04-26 14:59:06 -0500

Akif gravatar image

updated 2017-04-26 14:59:46 -0500

You can try this;

visualization_msgs::Marker marker;
marker.header.frame_id = "/my_frame";
marker.header.stamp = ros::Time::now();
marker.ns = "basic_shapes";
marker.id = iteration;
marker.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
marker.action = visualization_msgs::Marker::ADD;

marker.pose.position.x = 0.0 + iteration;
marker.pose.position.y = 1.0;
marker.pose.position.z = 1.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;

marker.text = "blablabla";

marker.scale.x = 0.3;
marker.scale.y = 0.3;
marker.scale.z = 0.1;

marker.color.r = 0.0f;
marker.color.g = 1.0f;
marker.color.b = 0.0f;
marker.color.a = 1.0;
edit flag offensive delete link more

Comments

Thank you for your answer Unfortunetly, it didn't helped. It seems like it isn's problem with code or message, but with rvzi.

Black_Cry1 gravatar imageBlack_Cry1 ( 2017-05-05 14:12:53 -0500 )edit

I know this is an old thread, but were you using a virtual machine? I'm finding text markers work ok except when on VMWare or Virtualbox. If you had the same thing, did you find a fix?

Wezzoid gravatar imageWezzoid ( 2018-11-14 12:36:35 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-04-24 07:21:17 -0500

Seen: 2,425 times

Last updated: Apr 26 '17