# Ros/Gazebo defining (and changing) colors within a xacro file

I am trying to make a sphere in my simulation to represent a task location that my robot will be visiting. I would like to be able to recolor the sphere preferably based on a ros channel, but the first challenge is getting it to show up in the assigned color in gazebo at all. Below is the macro I am using to create the links, which has the correct behavior except for the color. I have several colors defined in the included file (red, blue, green, etc). How do I get these colors to pass into gazebo so the xacro that calls the macro can assign different colors to each task, without making separate macros for each color?

<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro">

<xacro:include filename="$(find uuv_descriptions)/urdf/common.urdf.xacro"/> <xacro:macro name="task_vis" params="x y z color number"> <link name="world"/> <link name="taskvisualizer/task_${number}">
<xacro:no_inertial>
</xacro:no_inertial>
<visual>
<origin xyz="${x}${y} ${z}" rpy="0 0 0"/> <geometry> <sphere radius=".2"/> <material name="${color}"/>
</geometry>
</visual>
<static>1</static>
<gazebo reference="task_vis/task_${number}"> <is_static>true</is_static> </gazebo> <gazebo reference="taskvisualizer/task_${number}">
<material>Gazebo/Red</material>
</gazebo>
<joint name="taskvisualizer/task_${number}_joint" type="fixed"> <parent link="world"/> <child link="taskvisualizer/task_${number}"/>
</joint>

</xacro:macro>

</robot>


Edit: I can get it to do a single color as above, but doing it this way would have me make a separate macro for each color I want to use, rather than being able to specify the color as a parameter, which is what I would like to do. I could maybe make this work if there were a way to do some sort of if/else loop, but that still seems cumbersome, and I expect it wouldn't work if I wanted to do the color changing I hope to do with it.

edit retag close merge delete

<gazebo reference="taskvisualizer/task_${number}"> <material value="Gazebo/${color}"/>

<material name="green">
<color rgba="0.0 0.8 ...