【webots】urdf文件转换为webots文件 详细步骤

1. 使用urdf2webots进行转换

在命令行输入

 python -m urdf2webots.importer --input=urdf所在目录 --box-collision --static-base --tool-slot=base_link --multi-file --rotation="1 0 0 -1.5708"

然后文件会在命令行所在目录生成。

正常情况会输出

Robot name: urdfeasyv5
Root link: base_link
There are 25 links, 24 joints and 0 sensors

以下是几个坑

  • 目录有问题

    urdf文件是xml格式的,urdf2webots工具也是先将其以xml格式进行读取再转换。有一些字符在目录中可使用,但在xml格式中有特殊含义,会干扰proto文件中url的转换。命令行也会输出一堆地址相关的报错。

  • 没有转换坐标轴

    如果urdf是正常生成(z轴向上),那就得用到 --rotation=“1 0 0 -1.5708”,不然在webots中会侧面向上。其他参数意义如下。

    Arguments

    The script accepts the following arguments:

    • -h, --help: Show the help message and exit.
    • –input=INFILE: Specifies the urdf file to convert.
    • –output=OUTFILE: If set, specifies the path and, if ending in “.proto”, name of the resulting PROTO file. The filename minus the .proto extension will be the robot name.
    • –normal: If set, the normals are exported if present in the URDF definition.
    • –box-collision: If set, the bounding objects are approximated using boxes.
    • –disable-mesh-optimization: If set, the duplicated vertices are not removed from the meshes (this can speed up a lot the conversion).
    • –multi-file: If set, the mesh files are exported as separated PROTO files.
    • –static-base: If set, the base link will have the option to be static (disable physics)
    • –tool-slot=LinkName: Specify the link that you want to add a tool slot to (exact link name from urdf).
    • –rotation=“0 1 0 0”: Set the rotation field of your PROTO file. If your URDF file uses the z-axis as ‘up’, use --rotation="1 0 0 -1.5708".
    • –init-pos=JointPositions: Set the initial positions of your robot joints. Example: --init-pos="[1.2, 0.5, -1.5]" would set the first 3 joints of your robot to the specified values, and leave the rest with their default value.

2. 处理proto文件

成功生成了proto可能还有问题,导入进webot之后可能会啥也没有(但好像只在我身上发现)。此时用任意编辑器打开proto文件,可能会发现url的斜杠有问题,如图

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-F0CnBuni-1644651092802)(C:\Users\71046\AppData\Roaming\Typora\typora-user-images\image-20211224212142539.png)]

可以直接全局替换,将\全部换成/

3. 将几个文件放入protos目录

在webots中点击添加节点,在右侧找到protos目录,按照提示将生成的proto文件,meshes、textures文件夹放入该目录,重新打开即可发现左侧nodes下多了一个你的模型。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1ruW2Ig4-1644651092804)(C:\Users\71046\AppData\Roaming\Typora\typora-user-images\image-20211224212615114.png)]

然后双击导入即可。

4. 将导入的模型转为robot

选中webots页面左侧你的机器人并右键,点击Convert Root to Base Nodes。

你可能感兴趣的:(经验分享)