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

How to set some CollisionObjects not shown in Rviz

asked 2021-05-11 11:56:46 -0600

artemiialessandrini gravatar image

updated 2021-05-13 08:31:54 -0600

Hi, ROS Community!

I'm interested in spawning collision objects e.g. walls, glass in Rviz for Moveit! planning to prevent robot colliding with it in real live. Although, while spawning those, I cannot see an actual workspace, because basically making the "box".

Question: Is there any ways to hide some CollisionObject's visuals in Rviz , but keep others?

Best Regards!
Artemii

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-05-14 03:41:44 -0600

Ranjit Kathiriya gravatar image

updated 2021-05-14 07:45:39 -0600

Hello,

Question: Is there any ways to hide some CollisionObject's visuals in Rviz, but keep others?

Yes, there is a way to hide Collision objects you can hide them by the object name. You just have to change the color of the collision box and while adding color you have to put RGBA values during that set A values to 0.001. Your collision box will be not visible over here and it will also prevent your robot from colliding.

I am adding code for setting color in the RVIZ object:

Imports and variables add this at the time of initializing.

from moveit_msgs.msg import PlanningScene, ObjectColor

# Create a scene publisher to push changes to the scene
self.scene_pub = rospy.Publisher('planning_scene', PlanningScene, queue_size=10)
# Create a dictionary to hold object colors
self.colors = dict()

Add these lines for the calling function and put this line after or below the scene.add_box function calling.

### Make the target purple ###
self.setColor(target_id, 0.6, 0, 1, 1.0)  # X, Y, Z (normalized RGB) and A value

# Send the colors to the planning scene
self.sendColors()

Add both function in your class

    # Set the color of an object
    def setColor(self, name, r, g, b, a = 0.9):
        # Initialize a MoveIt color object
        color = ObjectColor()

        # Set the id to the name given as an argument
        color.id = name

        # Set the rgb and alpha values given as input
        color.color.r = r
        color.color.g = g
        color.color.b = b
        color.color.a = a

        # Update the global color dictionary
        self.colors[name] = color

    # Actually send the colors to MoveIt!
    def sendColors(self):
        # Initialize a planning scene object
        p = PlanningScene()

        # Need to publish a planning scene diff        
        p.is_diff = True

        # Append the colors from the global color dictionary 
        for color in self.colors.values():
            p.object_colors.append(color)

        # Publish the scene diff
        self.scene_pub.publish(p)

If you are using CPP here is a link for you Link

Note: over here you have to put RGB values into a normalized form. You can have a look at this website for converting RGB color to normalized decimal color that will be used into RVIZ.

To sum up: Yes, there is a way to hide the collision box and it also avoids a collision. You have to set color and in color, you have to make A (of RGBA) to 0.001, which means the brightness for that particular color. If you are not stratified with the answer or you are not clear, please! comment I will do my best to answer you.

Just check this image: You can see in image 3, robot position is the same just collision brightness is decreased and the color is eliminated. Are you looking for the same?

image description

edit flag offensive delete link more

Comments

Thank you for such a detailed answer! Marking it as the correct one indeed.
Strangely, importing a scene, using moveit_publish_scene_from_text is not importing colors. But I might need more time to investigate this particular issue.

artemiialessandrini gravatar image artemiialessandrini  ( 2021-05-25 09:42:02 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2021-05-11 11:56:46 -0600

Seen: 561 times

Last updated: May 14 '21