在qt下编写基于KUKA youbot API的程序

版权声明:本文为博主原创文章,如需转载,请附上文章原文地址。 https://blog.csdn.net/yaked/article/details/42265325
在qt下编写基于KUKA youbot API的程序

遇到的主要问题还是关于它的lib和include文件,因为KUKA 官网提供了youbot-driver,我们git clone下来,在catkin make 就可以了,在这里我以前装过,就直接在那个文件夹下git pull origin更新,然后进入build 文件夹,cmake..

最后make就在youbot_driver/lib下得到了两个库文件,libsoem.a和libKukaYoubotDriver.a。待会儿我们在qt项目中就是用的这两个文件。


在Linux操作系统中,采用了很多共享对象技术(Shared Object),虽然它和Windows里的动态库相对应,但它并不称为动态库。相

应的共享对象文件以.so作为后缀,为了方便,在本文中,对该概念不进 行专门区分。Linux系统的/lib以及标准图形界面的/usr

/X11R6/lib等目录里面,就有许多以so结尾的共享对象。同样,在Linux 下,也有静态函数库这种调用方式,相应的后缀以.a结束。

Linux采用该共享对象技术以方便程序间共享,节省程序占有空间,增加程序的可扩展性和灵活 性。Linux还可以通过LD-PRELOAD

变量让开发人员可以使用自己的程序库中的模块来替换系统模块。

#include "youbot/YouBotBase.hpp"


using namespace youbot;
#define YOUBOT_CONFIGURATIONS_DIR  "/home/youbot/youbot_driver/config"


int main() {

    /* configuration flags for different system configuration (e.g. base without arm)*/
    bool youBotHasBase = false;


    /* define velocities */
    double translationalVelocity = 0.05; //meter_per_second
    double rotationalVelocity = 0.2; //radian_per_second

    /* create handles for youBot base and manipulator (if available) */
    YouBotBase* myYouBotBase = 0;


    try {
        myYouBotBase = new YouBotBase("youbot-base", YOUBOT_CONFIGURATIONS_DIR);
        myYouBotBase->doJointCommutation();

        youBotHasBase = true;

    } catch (std::exception& e) {
        LOG(warning) << e.what();
        youBotHasBase = false;
    }

    quantity<si::velocity> longitudinalVelocity = 0 * meter_per_second;
    quantity<si::velocity> transversalVelocity = 0 * meter_per_second;
    quantity<si::angular_velocity> angularVelocity = 0 * radian_per_second;

    try {
        if (youBotHasBase) {

            /* forward */
            longitudinalVelocity = translationalVelocity * meter_per_second;
            transversalVelocity = 0 * meter_per_second;
            myYouBotBase->setBaseVelocity(longitudinalVelocity, transversalVelocity, angularVelocity);
            LOG(info) << "drive forward";
            SLEEP_MILLISEC(2000);

            /* backwards */
            longitudinalVelocity = -translationalVelocity * meter_per_second;
            transversalVelocity = 0 * meter_per_second;
            myYouBotBase->setBaseVelocity(longitudinalVelocity, transversalVelocity, angularVelocity);
            LOG(info) << "drive backwards";
            SLEEP_MILLISEC(2000);

            /* stop base */
            longitudinalVelocity = 0 * meter_per_second;
            transversalVelocity = 0 * meter_per_second;
            angularVelocity = 0 * radian_per_second;
            myYouBotBase->setBaseVelocity(longitudinalVelocity, transversalVelocity, angularVelocity);
            LOG(info) << "stop base";
        }



    } catch (std::exception& e) {
        std::cout << e.what() << std::endl;
        std::cout << "unhandled exception" << std::endl;
    }

    /* clean up */
    if (myYouBotBase) {
        delete myYouBotBase;
        myYouBotBase = 0;
    }

    LOG(info) << "Done.";

    return 0;
}

然后主要的是.pro配置文件,qt用它来生成makefile。

TEMPLATE = app
CONFIG += console
CONFIG += thread link_pkgconfig
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp

INCLUDEPATH += /home/youbot/youbot_driver
INCLUDEPATH += /home/youbot/youbot_driver/soem/src

LIBS += -L/home/youbot/youbot_driver/lib -lsoem
LIBS += -L/home/youbot/youbot_driver/lib -lYouBotDriver
LIBS += -L/usr/lib -lboost_thread


INCLUDEPATH += /home/youbot/youbot_driver

这里要注意不要包含到了下层,即不要写成 /home/youbot/youbot_driver/youbot,我们的cpp文件第一行include后面是youbot/YouBotBase.hpp。它有youbot。如果这句没写对会提示

/home/youbot/ROS_qt/move/main.cpp:1: error:youbot/YouBotBase.hpp: No such file or directory


INCLUDEPATH += /home/youbot/youbot_driver/soem/src

这一句主要是ethcat的相关头文件和cpp文件,通信必需。如果这句没写对会提示

/home/youbot/youbot_driver/youbot/YouBotSlaveMsg.hpp:56: error: ethercattype.h: No such file or directory


LIBS += -L/home/youbot/youbot_driver/lib -lsoem
LIBS += -L/home/youbot/youbot_driver/lib -lYouBotDriver

这两句就是我们之前生成的两个库文件,大写的'L'表示目录,小写'l'表示包含的文件,另外细心的你会发现,我们文件名原本生成的时候是libsoem.a和libYouBotDriver.a这里要注意包含的时候要去掉前缀lib也不要后缀.a。千万注意。

/home/youbot/ROS_qt/move/main.cpp:23: error:undefined reference to `youbot::YouBotBase::YouBotBase(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'


/home/youbot/ROS_qt/move/main.cpp:43: error:undefined reference to `youbot::YouBotBase::setBaseVelocity(boost::units::quantity<boost::units::unit<boost::units::list<boost::units::dim<boost::units::length_base_dimension, boost::units::static_rational<1l, 1l> >


LIBS += -L/usr/lib -lboost_thread

这句的文件主要是因为link的时候缺少boost文件,线程所要用到的库。如果没有会提示如下错误

:-1: error: main.o: undefined reference to symbol 'boost::this_thread::sleep(boost::posix_time::ptime const&)'

:-1: error: note: 'boost::this_thread::sleep(boost::posix_time::ptime const&)' is defined in DSO /usr/lib/libboost_thread.so.1.46.1 so try adding it to the linker command line

/usr/lib/libboost_thread.so.1.46.1:-1: error: could not read symbols: Invalid operation


最后的编译生成的文件截图


KUKA API地址点击打开链接

没有更多推荐了,返回首页