我正在开发ROS Qt GUI应用程序,我在ROS Hydro上面临一个问题(我在使用ROS Fuerte时遇到了同样的问题).我的项目不能识别我的图书馆image_transport.h.我将它添加到qnode.hpp文件的开头,但它没有解决问题.
我的主要问题:
/home/attila/catkin_ws/src/arayuz/src/qnode.cpp:-1:错误:未定义引用`image_transport :: ImageTransport :: ImageTransport(ros :: NodeHandle const&)'
这是生成错误的代码:
#include "ros/ros.h"
#include "ros/network.h"
#include "string"
#include "std_msgs/String.h"
#include "sstream"
#include "../include/arayuz/qnode.hpp"
namespace enc=sensor_msgs::image_encodings;
static const char WINDOW[ ]="Kinect";
namespace arayuz {
QNode::QNode(int argc, char** argv ) :
init_argc(argc),
init_argv(argv)
{}
QNode::~QNode() {
if(ros::isStarted()) {
ros::shutdown(); // explicitly needed since we use ros::start();
ros::waitForShutdown();
}
cv::destroyWindow(WINDOW);
wait();
}
bool QNode::init() {
ros::init(init_argc,init_argv,"arayuz");
if ( ! ros::master::check() ) {
return false;
}
ros::start(); // explicitly needed since our nodehandle is going out of scope.
ros::NodeHandle n;
// Add your ros communications here.
image_transport::ImageTransport it(n);
imagesub = it.subscribe("/kinectCamera", 1,&QNode::chatterimage,this);
start();
return true;
}
bool QNode::init(const std::string &master_url, const std::string &host_url) {
std::map<std::string,std::string> remappings;
remappings["__master"] = master_url;
remappings["__hostname"] = host_url;
ros::init(remappings,"arayuz");
if ( ! ros::master::check() ) {
return false;
}
ros::start(); // explicitly needed since our nodehandle is going out of scope.
ros::NodeHandle n;
// Add your ros communications here.
image_transport::ImageTransport it(n);
imagesub = it.subscribe("/kinectCamera",1,&QNode::chatterimage,this);
start();
return true;
}
void QNode::chatterimage(const sensor_msgs::ImageConstPtr& msg)
{
rgbimage=cv_bridge::toCvCopy(msg,enc::BGR8);
Q_EMIT chatterimageupdate();
}
void QNode::run() {
while ( ros::ok() ) {
ros::spin();
}
std::cout << "Ros shutdown, proceeding to close the gui." << std::endl;
Q_EMIT rosShutdown(); // used to signal the gui for a shutdown (useful to roslaunch)
}
}
Run Code Online (Sandbox Code Playgroud)
小智 13
要链接ROS库,您需要将依赖项添加到您的package.xml文件:
<build_depend>image_transport</build_depend>
<run_depend>image_transport</run_depend>
Run Code Online (Sandbox Code Playgroud)
和你的CMakeLists.txt:
find_package(catkin REQUIRED COMPONENTS
...
image_transport
...
)
Run Code Online (Sandbox Code Playgroud)