利用插件将solidworks模型转化为URDF文件,再转化为proto文件并导入Webots

如何由solidworks生成urdf模型见我另一篇博客:Solidworks模型转化为urdf文件

插件urdf2webots官网:建议进入urdf2webots 官网查看不同的版本安装和使用方法。
不同版本对webots适应性不同,目前已经更新至2.0.3版本,适配webots2022。
下面以1.0.8版本为例说明
环境:ubuntu18.04,webots为webots_2020b-rev1_amd64,可以适配。

1安装插件

三种安装方法:

  1. pip 安装

需要python环境,高版本插件对python版本有要求,注意要求python3.几还是python2即可,使用pip还是pip3(查看版本:pip -Vorpip3 -V)。安装pip:sudo apt install python-pip ,若是python3,改成python3。1.0.8可以用python2:

pip install urdf2webots==1.0.8

版本号缺省则下载最新的。
pip list可查看到:
在这里插入图片描述

  1. 源码安装
git clone https://github.com/cyberbotics/urdf2webots.git
cd urdf2webots
pip install -r requirements.txt

没试过,自己可以尝试,貌似会下载最新的,不推荐。
3. github手动下载安装
找到releases,下载源码,这里ubuntu下载.tar.gz。
源码
解压之后,进入文件夹,执行:

pip install -r requirements.txt

即可,这样有一个缺点,只能在这个文件夹中使用插件,如下图,且pip list也查不到urdf2webots这个包。
在这里插入图片描述

2使用插件

以前的低版本使用方法为:

python
from urdf2webots.importer import convert2urdf

更新之后的报错:cannot import name ‘convert2urdf’ from 'urdf2webots.importer。
官方更新之后指令变了,上面应该变为:(1.0.8使用此方法)

python -m urdf2webots.importer --input=someRobot.urdf [--output=outputFile] [--normal] [--box-collision] [--tool-slot=linkName] [--help]

[]是argument,支持以下:

-h, --help: Show the help message and exit.
–input=INPUT: Specifies the URDF file to convert.
–output=OUTPUT: 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 (for PROTO conversion only).
–robot-name: Specify the name of the robot and generate a Robot node string instead of a PROTO file (has to be unique).
–normal: If set, the normals are exported if present in the URDF definition.
–box-collision: If set, the bounding objects are approximated using boxes.
–tool-slot=LinkName: Specify the link that you want to add a tool slot to (exact link name from URDF, for PROTO conversion only).
–translation=“0 0 0”: Set the translation field of the PROTO file or Webots Robot node string.
–rotation=“0 0 1 0”: Set the rotation field of the PROTO file or Webots Robot node string.
–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.
–link-to-def: Creates a DEF with the link name for each solid to be able to access it using getFromProtoDef(defName) (for PROTO conversion only).
–joint-to-def: Creates a DEF with the joint name for each joint to be able to access it using getFromProtoDef(defName) (for PROTO conversion only).
–relative-path-prefix: If --input is not set, the relative paths in your URDF file sent through stdin will use this prefix. For example: filename=“head.obj” with --relative-path-prefix=“/home/user/myRobot/” will become filename=“/home/user/myRobot/head.obj”.

需要加上output就会生成proto文件,其他的[]选项里面可以不用,在win10系统执行结果如下:
在这里插入图片描述
ubuntu执行结果:
在这里插入图片描述

直接就已经生成了proto文件,不需要执行第三步了。

3输入路径 老版本执行这一步,现在不怎么需要了

convert2urdf('/home/humphrey/tools/Webots/project/1/name.urdf')

生成的proto文件在当前终端目录下
此处注意,重复导出proto文件时,一定要退出python,然后从第二步重新开始!!!

4导入proto

新建项目,将前面的proto文件放在proto文件夹下面,插入floor,然后点击新增,添加节点proto nodes即可
在这里插入图片描述
导入的proto文件需要注意,如果抓取的话,建议自建碰撞体,不要参考stl模型。质量需要调小,不然会陷入地面。
更新之后,直接导入proto文件会报错找不到mesh,需要把proto文件中geometry DEF base_link Mesh下面的\修改为/,即url "D:\Users\hp\Documents/robot_description/

  • 16
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值