0

Environment: ROS Noetic, Gazebo11

I try to use xacro with YAML, but there is a problem about argument of variable:

My yaml:

---
  color_0: "1 1 1 1.0"
  color_1: "0 0 0 1.0"
  color_2: "0.84 0 0 1.0"
  color_3: "0.55 0.24 1 1.0"
  color_4: "0.01 0.53 0 1.0"

Because I want to use different value at different time.

So I tried to load the value as below:

<xacro:property name="YAML_FILE" value="$(find gazebo_ros_model_color)/configs/colors.yaml" />
<xacro:property name="COLORS" value="${load_yaml(YAML_FILE)}"/>
    
<xacro:arg name="color" default="color_0" />
<color>${COLORS[${color}]}</color>

But it cause the ERROR :((

...
invalid expression: ${color 
when evaluating expression 'COLORS['${color'
    ...

Is it possible to get the value from YAML by key variable given? Or other solving method?

Any suggestion is welcome.

Thank you

NEET
  • 61
  • 1
  • 2
  • 11

1 Answers1

0

The different use of xacro:property, xacro:arg, and xacro:params is:

xacro:arg is use $(arg VAR)
xacro:property and xacro:params are use ${VAR}

So, I solve my problem as below:

<xacro:arg name="color" default="color_${id_num}" />
<color>${COLORS['$(arg color)']}</color>

And I also tried to use xacro:property, but CAN NOT use it like:

<xacro:property name="color" value="color_0" />
<color>${COLORS['${color}']}</color>
NEET
  • 61
  • 1
  • 2
  • 11