0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Xacro勉強メモ

Last updated at Posted at 2023-05-07

Xacroとは?

URDFファイルにコードの再利用性が悪く、この問題を解決するため、値の定数化、変数化、モデルのパターン化できるXacro形式ファイルを導入

機能

1.パラメータ機能
c言語のconstかな

定義:
<xacro:property name="PI" value="3.14159"/>

使用:
<origin xyz="000" rpy="${PI}00"/>

コメント:{}の中は常数を使用するのみならず、計算式入れることもできる。例えば、${PI*7}

2.マクロ機能
cの構造体のイメージかな
例えば、タイヤは4本あるから、4本それぞれ定義するとダルいので、1本作って、後マクロ機能を使って、位置のパラメータを作って、位置を4つ設定すれば、4本のタイヤがそれぞれ配置してくれる。

定義:
<xacro:macro name="macro_q"> params="A B C"
    ......
</xacro:macro>

使用:
<xacro:macro_q A="left" B="3" C="4">
<xacro:macro_q A="right" B="2" C="4">

例.

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

    <xacro:macro name="usb_camera" params="prefix:=camera">
        <link name="${prefix}_link">
            <inertial>
                <mass value="0.1" />
                <origin xyz="0 0 0" />
                <inertia ixx="0.01" ixy="0.0" ixz="0.0"
                         iyy="0.01" iyz="0.0"
                         izz="0.01" />
            </inertial>

            <visual>
                <origin xyz=" 0 0 0 " rpy="0 0 0" />
                <geometry>
                    <box size="0.01 0.04 0.04" />
                </geometry>
                <material name="black"/>
            </visual>

            <collision>
                <origin xyz="0.0 0.0 0.0" rpy="0 0 0" />
                <geometry>
                    <box size="0.01 0.04 0.04" />
                </geometry>
            </collision>
        </link>
    </xacro:macro>

</robot>

3.include
c言語のincludeと同じ感じ

文法:
<xacro:include filenames="$(find pkg名)/urdf/xacro/ファイル名.xacro"/>

xacroの中階層分けの考え方も実現しやすい。
例:Top階層にロボット全体を表現、その下にベース階層としてBody xacro、センサー xacro、アクチュエータ xacroをインクルートすれば、かなり自由自在に組み合わせでき、色んなパターンを作れるわけ

例:

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

    <xacro:include filename="$(find mrobot_description)/urdf/mrobot_body.urdf.xacro" />
    <xacro:include filename="$(find mrobot_description)/urdf/kinect.xacro" />

    <xacro:property name="kinect_offset_x" value="-0.06" />
    <xacro:property name="kinect_offset_y" value="0" />
    <xacro:property name="kinect_offset_z" value="0.035" />

    <!-- MRobot ボディ-->
    <xacro:mrobot_body/>

    <!-- センサー -->
    <joint name="kinect_frame_joint" type="fixed">
        <origin xyz="${kinect_offset_x} ${kinect_offset_y} ${kinect_offset_z}" rpy="0 0 0" />
        <parent link="plate_2_link"/>
        <child link="camera_link"/>
    </joint>
    <xacro:kinect_camera prefix="camera"/>

</robot>

Xacroファイルを使用する2つの方法

1.Xacroファイルを作成したら、手動で URDFファイルに変換した上URDFファイルを使用する.

rosrun xacro xacro ***.xacro > ***.urdf

2.Launchファイルの中xarcoファイルを直接使うことを声明し、xarcoファイルを使う.

	<arg name="model" default="$(find xacro)/xacro --inorder '$(find **)/urdf/***.xacro'" />
	<arg name="gui" default="true" />

	<param name="**_description" command="$(arg model)" />

** はpkg名,***はxacro名.

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?