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

include *.xacro in *.urdf

asked 2022-06-22 07:18:39 -0600

Saurabh Rahatekar gravatar image

Hi all, I m trying to attach the intel realsense camera to my robot. My robot is in .urdf format and the camera is in *.urdf.xacro format. Is there any way to do this without converting either to another format?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-06-22 07:57:26 -0600

dwd394 gravatar image

updated 2022-06-22 07:59:55 -0600

yeah you can just copy the meat of the xacro into your urdf...its all the stuff in the <xacro:macro> section. alternatively, you can add a <xacro:create> tag at the end of the realsense file and then just <include> it in your urdf.

but you should really get comfortable with xacro. its great.

i feel your pain I had learn the xacro format while adding a _d415.urdf.xacro file too. but no. you don't need to make everything a macro and call it in a common file.

here is an example of making a common file to call all the macros I made

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

  <!-- A common file to tie together all of the bits and bobs of the entire robot
  Modeled after turtlebot_description 
  NOTE: All Gazebo references are gone, so simulation will have to be rebuilt if you want it -->

  <!-- From $(find turtlebot_description)/urdf/common_properties.urdf.xacro -->
  <!-- It is required by asus_xtion_pro.urdf.xacro -->
  <xacro:property name="M_PI" value="3.1415926535897931"/>

  <!-- Include 3D camera -->
  <xacro:include filename="$(find realsense2_description)/urdf/_d415.urdf.xacro"/>

  <!-- Arlo -->
  <xacro:include filename="$(find arlo-description)/urdf/arlo_temp.urdf.xacro"/>

  <!-- RPLIDAR -->
  <!-- <xacro:include filename="$(find arlobot_ros)/urdf/asus_xtion_pro_chrisl8.urdf.xacro"/> -->

  <xacro:arlobot/>
  <xacro:stack_circles parent="base_link"/>
  <xacro:sensor_d415 parent="plate_0_link" use_nominal_extrinsics="true" add_plug="false" use_mesh="true">
    <origin xyz=".1945 0 .00475" rpy="0 0 0"/>
  </xacro:sensor_d415>
</robot>
edit flag offensive delete link more

Comments

Hey, Thank you so much for the quick response. I will try this and get back to you if I run into any further errors.

Saurabh Rahatekar gravatar image Saurabh Rahatekar  ( 2022-06-23 03:31:37 -0600 )edit

I want to add this code to my urdf file.

<robot <a="" href="http://xmlns:xacro="http://ros.org/wiki/xacro%22" name="realsense2_camera">xmlns:xacro="http://ros.org/wiki/xacro"> <xacro:include filename="$(find realsense2_description)/urdf/_d435.urdf.xacro"></xacro:include></robot>

<link name="camera_body"/> <xacro:sensor_d435 name="camera" topics_ns="camera" parent="camera_body" publish_pointcloud="true"> <origin xyz="0.35 0.0 0.15" rpy="0 0 0"/> </xacro:sensor_d435>
</robot>

Saurabh Rahatekar gravatar image Saurabh Rahatekar  ( 2022-06-23 04:58:12 -0600 )edit

so i don't think the publish_pointcloud is a xacro arg for _d415.urdf.xacro ..... your arguments topic_ns and publish_pointcloud are wrong. open the _d415.urdf.xacro and the test_d415.urdf.xacro files in the realsense2_description package to get a better idea of what is going on. i believe you are mistaking the arguments as if they are in a launch file. all you are doing in URDF is specifying dimensions for the transforms. that's it.

the only arguments you can pass into a macro are ones that are explicitly called for in the macro.

dwd394 gravatar image dwd394  ( 2022-06-23 04:59:45 -0600 )edit

But these are the contents of test_d435_camera.urdf.xacro this file and it is called in the launch file as well. launch file

urdf file

Saurabh Rahatekar gravatar image Saurabh Rahatekar  ( 2022-06-23 05:33:01 -0600 )edit

I converted my robot urdf into xacro and then included the camera xacro in it. It worked perfectly. I don't know why I was holding back on xacro. Thank you for recommending this path.

Saurabh Rahatekar gravatar image Saurabh Rahatekar  ( 2022-06-24 03:24:01 -0600 )edit

When I m launching the xacro from launch file, it is showing me some errors. But when I convert it to urdf using "xacro robot.urdf.xacro > model.urdf" and launch the urdf file using the same, it doesn't give me any error. Do you know why?

Saurabh Rahatekar gravatar image Saurabh Rahatekar  ( 2022-07-26 01:50:10 -0600 )edit

i can't give any advice without knowing the error, but here is my launch file to display the urdf above.

<?xml version="1.0" ?>
<launch>
  <param name="robot_description" command="$(find xacro)/xacro $(find arlo-description)/urdf/test_arlo.urdf.xacro"/>

  <arg name="rviz_fixed_frame" default="base_link"/>

  <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"/>
  <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher"/>

  <node name="rviz" pkg="rviz" type="rviz" required="true" args="-d $(find arlo-utilities)/config/rviz/arlo.rviz -f $(arg rviz_fixed_frame)"/>

</launch>
dwd394 gravatar image dwd394  ( 2022-07-26 13:35:44 -0600 )edit

here is my launch file

<launch>
<arg name="model" default="$(find xacro)/xacro --inorder'$(find robot_bringup)/urdf/model.urdf'"/>
<arg name="gui" default="true" />
<node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"/>
<param name="robot_description" textfile="$(find robot_bringup)/urdf/model.urdf" />
<node name="spawn_robot" pkg="gazebo_ros" type="spawn_model" respawn="false" args="-param robot_description -urdf -model fielderbot"/>
<node name="rviz" pkg="rviz" type="rviz" args="-d $(find robot_bringup)/rviz/outdoor_ros.rviz" required="true" />

</launch>

Saurabh Rahatekar gravatar image Saurabh Rahatekar  ( 2022-07-29 03:11:35 -0600 )edit

Question Tools

Stats

Asked: 2022-06-22 07:18:39 -0600

Seen: 815 times

Last updated: Jun 22 '22