Quantcast
Channel: ROS Answers: Open Source Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 46

Linking Classes in 2 user defined packages

$
0
0
Hello. I'm beggeing with ROS I'm studing CMakeLists.txt using diffrent approches to execute same code. I have a problem with the linking phase of compilation of two user defined packages : pkg1 : sphero_imu_reader I've defined a Class ImuTopicReader pkg 2 : sphero_crash_server I've defined a Class CrashServer I want to use the Class ImuTopicReader inside CrashServer class the files: - sphero_imu_reader : ->src/topic_reader.h ->src/topic_reader.cpp - sphero_crash_server : ->/include/sphero_crash_server/topic_reader.h ->src/topic_reader.h ->src/topic_reader.cpp I've got these problems : fatal error: topic_reader.h: no such file or directory CMakeLists.txt for sphero_topic_reader : ---------- cmake_minimum_required(VERSION 2.8.3) project(sphero_imu_reader) ## Compile as C++11, supported in ROS Kinetic and newer add_compile_options(-std=c++11) ## Find catkin macros and libraries ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) ## is used, also find other catkin packages find_package(catkin REQUIRED COMPONENTS sensor_msgs roscpp ) catkin_package( # INCLUDE_DIRS include # LIBRARIES imu_topic_reader CATKIN_DEPENDS sensor_msgs roscpp # DEPENDS system_lib ) ## Specify additional locations of header files ## Your package locations should be listed before other locations include_directories( # include ${catkin_INCLUDE_DIRS} ) add_executable(${PROJECT_NAME}_node src/topic_reader.cpp) add_dependencies(${PROJECT_NAME}_node ${catkin_EXPORTED_TARGETS}) target_link_libraries(${PROJECT_NAME}_node ${catk ## Mark cpp header files for installation install(DIRECTORY include/${PROJECT_NAME}/ DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} FILES_MATCHING PATTERN "*.h" PATTERN ".svn" EXCLUDE ) ---------- package.xml for Sphero_imu_reader catkinsensor_msgsroscppsensor_msgsroscppsensor_msgsroscpp ---------- topic_reader.h for sphero_imu_reader pkg #ifndef SPHERO_IMU_READER #define SPHERO_IMU_READER #include "ros/ros.h" #include "sensor_msgs/Imu.h" #endif class ImuTopicReader { private: std::string name_; ros::NodeHandle n_; ros::Subscriber subs_; sensor_msgs::Imu imu_; public: ImuTopicReader(std::string name) { name_ = name; subs_ = n_.subscribe(name_,1,&ImuTopicReader::imuCallback,this); } void imuCallback(const sensor_msgs::Imu::ConstPtr& msg); sensor_msgs::Imu getImu(); }; ---------- CMakeLists.txt for sphero_crash_server : cmake_minimum_required(VERSION 2.8.3) project(sphero_crash_server) add_compile_options(-std=c++11) find_package(catkin REQUIRED COMPONENTS roscpp sensor_msgs sphero_imu_reader ) catkin_package( CATKIN_DEPENDS roscpp sphero_imu_reader sensor_msgs ) include_directories( # include ${catkin_INCLUDE_DIRS} ) add_executable(${PROJECT_NAME}_node src/server.cpp) add_dependencies(${PROJECT_NAME}_node } ${catkin_EXPORTED_TARGETS} ${catkin_LIBRARIES}) target_link_libraries(${PROJECT_NAME}_node ${catkin_LIBRARIES} ) install(DIRECTORY include/${PROJECT_NAME}/ DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} FILES_MATCHING PATTERN "*.h" PATTERN ".svn" EXCLUDE ) ---------- package.xml for sphero_crash_server : catkinroscppsphero_imu_readersensor_msgsroscppsphero_imu_readersensor_msgsroscppsphero_imu_readersensor_msgs ---------- server.h in pgk sphero_crash_server : #include "ros/ros.h" #include "sphero_crash_server/topic_reader.h" #include "std_srvs/Trigger.h" #include "sensor_msgs/Imu.h" #include #include class CrashServer { private: ros::NodeHandle n_; ImuTopicReader imu_topic_; float threshold_; ros::ServiceServer service_; std::string name_; public: CrashServer (std::string name,float threshold) { name_ = name; imu_topic_ = ImuTopicReader(name_); threshold_ = threshold; service_ = n_.advertiseService("detect_crash_action_serv",&CrashServer::detectionCallback,this); std::cout << "done" <

Viewing all articles
Browse latest Browse all 46

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>