Ask Your Question

Xacro convert property to integer

asked 2015-06-15 07:21:47 -0500

Malefitz gravatar image

I'm using ROS Indigo and I want to create a robot with parametrizable camera resolution using just one urdf.xacro file. The camera width gets passed into the myrobot.urdf.xacro file via the prefix parameter when I spawn the robot:

<param name="robot_description" command="$(find xacro)/ '$(find simulator)/urdf/myrobot.urdf.xacro' prefix:=$(arg camera_resolution)" />

In the myrobot.urdf.xacro I then create the properties for a 4:3 aspect ratio:

<xacro:property name="cam_width" value="${arg prefix}" />
<xacro:property name="cam_height" value="${cam_width * 0.75}" />

Later I pass the values into the <sensor> field:

<sensor type="camera" name="camera_link_sensor">
  <camera name="head">
    <plugin name="gazebo_ros_prosilica" filename="">

So far so good. Now when I input a camera_resolution parameter of 1024, the cam_width get's correctly set to 1024, but for the height I just get the default value with an error:

Error [] Unable to set value [768.0] for key[height]

I investigated the error and it seems, the sensor field can't handle float values, but xacro automatically creates cam_height as float. If I manually insert the value 768.0 the same error message appears, but if I manually insert 768, the parameter get's set correctly.

Now to my question: is there a way to manually convert the cam_height property to an integer? I know with ROS Jade arbitrary python expressions will get supported by xacro, so I could use the floor() function, but is there any other way apart from switching to ROS Jade? I already tried stuff like cam_height / 1 without success.

Alternatively, maybe someone has a better idea how I could realize the parametrizable camera resolution.

Best regards, Malefitz

edit retag flag offensive close merge delete


All I can see so far is which says 'All of the math is done using floats'. Also tried this in rrbot.gazebo and Indigo and gazebo 2.2.5 and got same error message.

lucasw gravatar image lucasw  ( 2015-06-15 08:19:58 -0500 )edit
lucasw gravatar image lucasw  ( 2015-06-15 08:50:03 -0500 )edit

I found that "All of the math is done using floats" statement, too. Seems there is no way to reconvert the floats to integers pre-Jade...thanks anyway!

Malefitz gravatar image Malefitz  ( 2015-06-15 09:37:53 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-06-15 08:54:15 -0500

David Lu gravatar image

I haven't tried this, but does this work:

<xacro:property name="cam_height" value="${cam_width * 3 / 4}" />
edit flag offensive delete link more


No it doesn't work, the result is also interpreted as a float.

Malefitz gravatar image Malefitz  ( 2015-06-15 09:34:39 -0500 )edit

It seems like sdformat ought to interpret a float as an int without an error that prevents further operation, a warning at most.

lucasw gravatar image lucasw  ( 2015-06-15 12:51:21 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-06-15 07:21:47 -0500

Seen: 433 times

Last updated: Jun 15 '15