subscribing to custom message type
I have created a custom message type. I am able to successfully publish it with the topic name "topic".
int8 seq_id
std_msgs/Header timestamp
int8 frame_id
float64 myheight
float64 mywidth
int16 step_value
sensor_msgs/Image my_left
sensor_msgs/Image my_right
is my custom message.
I created a new package. I want to subscribe to the node publishing "topic".
int main(int argc, char **argv)
{
ros::init(argc, argv, "listener");
ros::NodeHandle n;
std::cout << "hello disparity" << std::endl;
ros::Subscriber sub = n.subscribe("mycustomtopic",1000,chatterCallback);
std::cout << "after subscription disparity" << std::endl;
ros::spin();
std::cout << "after spin disparity" << std::endl;
return 0;
}
is my main function.
void chatterCallback(const swahana_v2::rectified_imageConstPtr &msg){
std::cout << "checker " << std::endl;
return;
}
is my callback function written in the same node.
and the output is
hello disparity
after subscription disparity
^Cafter spin disparity
following is my CMakeLists.txt
cmake_minimum_required(VERSION 2.8.3)
project(compute_disparity)
set(CMAKE_BUILD_TYPE Release)
find_package(catkin REQUIRED COMPONENTS
rectifier
roscpp
rospy
std_msgs
swahana_v2
sensor_msgs
)
catkin_package()
include_directories( ${catkin_INCLUDE_DIRS})
include_directories(include ${catkin_INCLUDE_DIRS})
add_executable(hsvgmmN src/hsvgmmN.cpp)
target_link_libraries(hsvgmmN ${catkin_LIBRARIES})
add_dependencies(hsvgmmN compute_disparity_generate_messages_cpp)
target_link_libraries(hsvgmmN ${catkin_LIBRARIES})
target_link_libraries (hsvgmmN elas viso ${PCL_LIBRARIES} ${OpenCV_LIBS} )
find_package(message_generation)
catkin_package(CATKIN_DEPENDS message_runtime)
add_message_files(
DIRECTORY ../swahana_v2/msg
FILES rectified_image.msg
)
find_package(catkin REQUIRED COMPONENTS swahana_v2)
add_dependencies(hsvgmmN swahana_v2_generate_messages_cpp)
but, "checker" is not getting printed. This means, there is still some problem with the callback function. please help!
Have you had a look on rqt_graph like I wrote in the answer? Are the nodes connected by topic?