Ubuntu系统中Webot机器人配置

一、SolidWorks模型转URDF文件

1. 下载并安装sw2urdf插件

插件介绍:http://wiki.ros.org/sw_urdf_exporter
插件:https://github.com/ros/solidworks_urdf_exporter/releases (注意安装对应SolidWorks版本的插件)
插件安装
1)下载exe文件双击安装;
2)SolidWorks软件主页 - 工具 - 插件 - 勾选 SW2URDF
3)打开SolidWorks模型 - 工具 - file - Export as URDF

2. 建立旋转轴和参考坐标系

根据构建机器人的需求,在需要添加驱动的位置构建机器人关机的参考坐标系和旋转轴(机械臂可以参考DH方法构建)。
注意:这里的旋转轴和坐标系只要方向对即可(旋转轴同轴,坐标系Z轴方向是对的),无需特别精细。

3.生成URDF文件

3.1 添加运动副

1)初始只有 base_link;
2)点击 base_link ,可以改动连杆的名字,参考坐标系,添加连杆零件(即相对于基坐标固定的零件),添加子连杆;
3)点击构建的子连杆,可以改动连杆的名字,运动副的名字(即joint),参考坐标系,旋转轴,设置运动副类型(continuous电机可无限旋转;revolute舵机可加限位;prismatic移动电机,fixed固定),添加连杆零件(即相对于此坐标固定的零件),添加子连杆。
200

3.2 生成urdf配置文件

1)点击 Preview and Export 进入配置界面;
2)确定关节属性,可以在此步骤进行改动,点击next;
3)确定连杆属性,包括惯性矩,可视化和碰撞体属性(确认加载即可,不需要改动);
4)点击 Export URDF and Meshes;
5)将生成的文件拷到相应的系统中。

3.3 显示URDF文件

在Ubuntu系统中,可以直接 launch 生成的功能包中的 display.launch 文件。

可能存在问题:
1)机器人整体散架:
可能原因:SolidWorks2018 中的模型不能相同,不只是名字,模型也要有差别(虽然很扯,但模型更改后就没问题了)。

二、URDF转PROTO文件

1. 安装 urdf2webots 插件

官网:https://pypi.org/project/urdf2webots/2.0.3/
GitHub:https://github.com/cyberbotics/urdf2webots

具体安装说明,推荐看官网
注意:不同版本的 Webots 对应不同版本的插件

安装方法1: pip (推荐)

# 最新版本插件
pip install urdf2webots
# 相应版本的插件,经测试 Webots2020a可用; 可能需要使用不同的 pip 版本,如 pip3
pip install urdf2webots==1.0.8

安装方法2: sources

# 最新版本插件,相应版本的插件可以在 releases 中查找
git clone https://github.com/cyberbotics/urdf2webots.git
cd urdf2webots
pip install -r requirements.txt

2. 使用urdf2webots 插件

参考:官网

使用方法1:(推荐)

# 可能需要使用不同的 python 版本,如 python3.5 - m 
python -m urdf2webots.importer --input=someRobot.urdf [--output=outputFile] [--normal] [--box-collision] [--tool-slot=linkName] [--help]

使用方法2:

# 可能需要使用不同的 python 版本,如 python3.5
python
>> from urdf2webots.importer import convertUrdfFile
>> convertUrdfFile(input = 'MY_PATH/MY_URDF.urdf')

可能存在问题:
1)AttributeError: ‘_NamespacePath’ object has no attribute ‘sort’
解决方法:

pip3 install --upgrade pip
pip3 install --upgrade setuptools

3. 导入 proto 文件

1)将生成的 proto 文件放入对应世界的 proto 文件件中;
2)Webots软件主页 - 点击新增 - 添加 PROTO nodes (Current Project)。

三、Webots机器人控制器添加

向导 - 新增机器人控制器 - C++/Python - 确定控制器名称 - 完成。
四轮车控制器:

// File:          car_controller.cpp
// Date:
// Description:
// Author: summer
// Modifications:

// You may need to add webots include files such as
// <webots/DistanceSensor.hpp>, <webots/Motor.hpp>, etc.
// and/or to add some other includes
#include <webots/Robot.hpp>
#include <webots/Motor.hpp>
// All the webots classes are defined in the "webots" namespace
using namespace webots;

// This is the main program of your controller.
// It creates an instance of your Robot instance, launches its
// function(s) and destroys it at the end of the execution.
// Note that only one instance of Robot should be created in
// a controller program.
// The arguments of the main function can be specified by the
// "controllerArgs" field of the Robot node
int main(int argc, char **argv) {
  // create the Robot instance.
  Robot *robot = new Robot();

  // get the time step of the current world.
  int timeStep = (int)robot->getBasicTimeStep();

  // You should insert a getDevice-like function in order to get the
  // instance of a device of the robot. Something like:
    Motor *motor1 = robot->getMotor("left_wheel_j1");
    Motor *motor2 = robot->getMotor("left_wheel_j2");
    Motor *motor3 = robot->getMotor("right_wheel_j1");
    Motor *motor4 = robot->getMotor("right_wheel_j2");
  //  DistanceSensor *ds = robot->getDistanceSensor("dsname");
  //  ds->enable(timeStep);

  // Main loop:
  // - perform simulation steps until Webots is stopping the controller
  while (robot->step(timeStep) != -1) {
    // Read the sensors:
    // Enter here functions to read sensor data, like:
    //  double val = ds->getValue();

    // Process sensor data here.

    // Enter here functions to send actuator commands, like:
      // forword
      // motor1->setPosition(-100.0);
      // motor2->setPosition(-100.0);
      // motor3->setPosition(100.0);
      // motor4->setPosition(100.0);
      
      // back
      motor1->setPosition(35.0);
      motor2->setPosition(35.0);
      motor3->setPosition(-35.0);
      motor4->setPosition(-35.0);
      
      motor1->setVelocity(1.5);
      motor2->setVelocity(1.5);
      motor3->setVelocity(1.5);
      motor4->setVelocity(1.5);
  };

  // Enter here exit cleanup code.

  delete robot;
  return 0;
}

四、添加 ROS 控制器

# 安装ros控制器
sudo apt install ros-noetic-webots-ros
# 加入环境变量
gedit ~/.bashrc 
# 在最后一行添加
export WEBOTS_HOME=/usr/local/webots/
  1. 官网:http://wiki.ros.org/webots_ros
  2. CSDN:ROS联合Webots仿真
  3. 知乎:ROS联合webots实战案例(三)在webots中使用ROS控制小机器人1
  4. CSDN:webots模型联合ros仿真,实现ros自定义控制器

五、MATLAB与Webots联合仿真

  1. 古月居:Webots+Matlab:使用Simulink搭建RHex控制器(1)
  2. 古月居:Webots+Matlab:使用Simulink搭建RHex控制器(2)

本文参考文档均以超链接形式在文中给出。
以上内容根据自己理解和实践所写,如有错误,请批评指正。

  • 4
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lx-summer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值