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?