之前的ROS+UR机器人联调只包含了机器人本体,没有加上抓手,现在有空了把robotiq的手抓加上,这是第一步,先把包编译过。
首先下载功能包,采用官方包(注意在工作空间的src目录中clone):
git clone https://github.com/ros-industrial/robotiq.git
然后就是安装依赖(可以和ur机器人的包一起下载好了之后再编译):
sudo apt update -qq
rosdep update
rosdep install --from-paths src --ignore-src -y
编译过程中会有报错,因为robotiq官方包只支持到kinetic和melodic版本,需要修改一些内容,有兴趣的
(1)报错:
robotiq_modbus_rtu: No definition of [python-pymodbus] for OS version [focal]
robotiq_modbus_tcp: No definition of [python-pymodbus] for OS version [focal]
修改robotiq_modbus_rtu和robotiq_modbus_tcp文件夹内的package.xml文件,将
<depend>python-pymodbus</depend>
修改为
<depend>python3-pymodbus</depend>
两个里面都要改
参考:https://github.com/ros-industrial/robotiq/issues/198
(2)报错:
error: ‘chrono_literals’ is not a namespace-name
或
error: ‘optional’ in namespace ‘std’ does not name a template type
类似问题为C++版本问题,注意下面有提示适用的C++版本,根据提示修改相应包中的CMakelist.txt文件,在最上方增加:
set(CMAKE_CXX_STANDARD 14)#若提示为C++14
set(CMAKE_CXX_STANDARD 17)#若提示为C++17
或者根据提示信息增加:
add_compile_options(-std=c++11)
add_compile_options(-std=c++14)
add_compile_options(-std=c++17)
(3)报错:
error: ‘struct std::any::_Manager_internal<_Tp>’ redeclared with different access 380 | struct _Manager_internal
这是将私有变量强制变为公开变量在高版本编译器中不能使用造成的错误,我在编译过程中发现只有一个文件有问题,
修改robotiq/robotiq_3f_gripper_articulated_gazebo_plugins/src/RobotiqHandPlugin.cpp文件,将下面的宏定义内容注释掉,
#define private public
#include <gazebo/common/Plugin.hh>
#include <gazebo/common/Time.hh>
#include <gazebo/physics/physics.hh>
#include <robotiq_3f_gripper_articulated_gazebo_plugins/RobotiqHandPlugin.h>
#undef private
即修改为:
//#define private public
#include <gazebo/common/Plugin.hh>
#include <gazebo/common/Time.hh>
#include <gazebo/physics/physics.hh>
#include <robotiq_3f_gripper_articulated_gazebo_plugins/RobotiqHandPlugin.h>
//#undef private
此时如果编译,会出现错误(会有很多,别慌):
error: ‘double gazebo::common::PID::dGain’ is private within this context
此时,因为上面把强制转换变量公私有属性的定义注释掉了,导致源码中存在的访问私有变量出错,这些变量调用的是:/usr/include/gazebo-11/gazebo/common/PID.hh文件中的函数,即gazebo中的PID参数定义,查看该头文件中内容,发现有定义Public函数:
public: double GetDGain() const;
因此在源文件中可以调用此函数代替调用私有变量,修改下面内容
std::cout << "dGain after overloading: " << this->posePID[i].dGain
为:
std::cout << "dGain after overloading: " << this->posePID[i].GetDGain()
即将this->posePID[i].dGain修改为this->posePID[i].GetDGain(),根据报错信息,修改所有涉及到的变量。
至此再编译就可以通过了。
我上传了一份可以编译通过的在github上,大家可以参考
https://github.com/Siva552/robotiq
或者csdn
https://download.youkuaiyun.com/download/Siva5/89287427
未完待续...