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

Different color for each cube in CUBE_LIST using std_msgs/ColorRGBA[]

asked 2013-08-29 04:40:08 -0600

tuxware gravatar image

updated 2014-01-28 17:17:46 -0600

ngrennan gravatar image

Hey there,

I have a problem creating a CUBE_LIST with different colors for each cube. Below is my code. The strange thing is, that when setColor is set to true, all cubes are drawn in the same color (as expected in green), but when it is set to false, nothing is shown at all. How exactly is the use of the markerMsg attribute colors? Do you see the mistake I made? In the documentation it states "In visualization 1.1+ will also optionally use the colors member for per-vertex color.". How can I find out which version of visualization I am using? I have ros fuerte installed.

ros::Publisher pubTrackMarkers;
pubTrackMarkers = n.advertise<visualization_msgs::Marker>("/track_markers",queue_size, true);
visualization_msgs::Marker markerMsg;

markerMsg.header.frame_id  = "/trackMarkers_frame";
markerMsg.ns = "trackMarkers";
markerMsg.action = visualization_msgs::Marker::ADD;
markerMsg.pose.orientation.w = 1.0;
markerMsg.type = visualization_msgs::Marker::CUBE_LIST;
markerMsg.scale.x = 0.8f;
markerMsg.scale.y = 0.8f;
markerMsg.scale.z = 0.8f;
if (setColor){
    markerMsg.color.r = 0;
    markerMsg.color.g = 1;
    markerMsg.color.b = 0;
    markerMsg.color.a = 1;
}

for (int i=0; i<10; i++){
    geometry_msgs::Point temp;
    temp.x = i;
    temp.y = 1;
    temp.z = 0.5;
    markerMsg.points.push_back(temp);
    std_msgs::ColorRGBA c;
    c.r = (float)i/10.0;
    c.g = 0;
    c.b = 0;
    c.a = 1;
    markerMsg.colors.push_back(c);
}

pubTrackMarkers.publish(markerMsg);
markerMsg->points.clear();
markerMsg->colors.clear();

Thank you so much for your help! Jens

edit: solved! added the line "markerMsg->colors.clear();" now the number of color values and points is the same and it works. Thanks everyone!

edit retag flag offensive close merge delete

Comments

Since i is in the range of zero to nine, could the value you are setting in the red channel be rounding down to zero?

JonW gravatar image JonW  ( 2013-09-03 22:48:48 -0600 )edit

Good point, but that's not it. Changed it to a switch case statement with 5 "hard coded" colors, still not working. Shouldn't the boxes still be drawn but black then? I just added clearing the colors vector in the markerMsg, as I forget that earlier. That was it!! Thanks everybody for the helpt!

tuxware gravatar image tuxware  ( 2013-09-04 07:35:22 -0600 )edit

I have some problem about with CUBE_LIST marker. I use your code, set setColor=true, and I only get 10 points in the RVIZ, not ten cube.

I tried to write my own code to display CUBE_LIST, but still can't get correct result. Is there something error with my RVIZ?

RobustControl gravatar image RobustControl  ( 2020-11-15 07:58:25 -0600 )edit

@RobustControl This question is very old and most answers you see might be outdated. Are you setting the scale field for your cubes?

OzzieTheHead gravatar image OzzieTheHead  ( 2021-08-12 14:37:12 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-08-29 05:02:23 -0600

Gudjohnson gravatar image

One problem is that you are not using a Marker Array. For more than one Marker always use Marker Array. If you are not using Marker Array then push pubTrackMarkers.publish(markerMsg); inside the for loop. If you change to MarkerArray then use publisher of type <visualization_msgs::MarkerArray> Change this and tell me if you still have some problem

edit flag offensive delete link more

Comments

are you really getting more than one marker on your screen in rviz?

Gudjohnson gravatar image Gudjohnson  ( 2013-08-29 05:03:18 -0600 )edit

Yes, I am getting more than one. Why shouldn't I use CUBE_LIST, if I am ok with all cubes having the same size and attributes except for color ans position? This should be working with CUBE_LIST, or not? http://www.ros.org/wiki/rviz/DisplayTypes/Marker#Cube_List_.28CUBE_LIST.3D6.29

tuxware gravatar image tuxware  ( 2013-08-29 05:21:20 -0600 )edit

By the way, I am having the same issue using LINE_LIST. Why should the publish method be called within the for loop? That really makes no sense to me... The msg is filled with 10 cubes and then published at the end. It is working if setColor is set to true!

tuxware gravatar image tuxware  ( 2013-08-29 05:22:46 -0600 )edit

Why is this marked as the correct answer?

First of all the message type is *_LIST. And the DisplayTypes/Marker page clearly states that marker lists will utilize batch-up rendering and perform better than MarkerArrays. You can see that in the code by looking at how context_->queueRender(); is called

OzzieTheHead gravatar image OzzieTheHead  ( 2021-08-11 10:33:55 -0600 )edit

Question Tools

Stats

Asked: 2013-08-29 04:40:08 -0600

Seen: 2,328 times

Last updated: Nov 15 '20