Ask Your Question
0

What exactly is causing this error whne compiling the node ?

asked 2020-04-02 06:25:10 -0500

microbot gravatar image

updated 2020-04-02 07:11:55 -0500

I am trying to write a simple node that responds with a message when an image from camera is received. I have specific node provided by the ROS for this camera to open it and other to request the data. Now i want to write a simple subscriber that is subscribed to the topic that is being published by the request data node and i want my node to simple acknowledge the image received with a simple message.

Here is the code for my simple node

void imageCallback(const sensor_msgs::ImageConstPtr& msg){
     ROS_INFO("I heard the image");
}

int main(int argc, char **argv){

    ros::init(argc, argv, "test_node_vision");

    ros::NodeHandle nh;
    ros::Subscriber sub = nh.subscribe("image_listener", 1000, imageCallback);

    ros::spin();


    return 0;
}

when trying to ros run this node, there is a syntax error with '(' token near the line where i am defining the imageCallback function. But to me all the syntax looks correct and hence I suspect there is something somewhere else going wrong with this node which then caused a domino effect ended up with this error. Can anyone please help me with this. Thank you.

Here is the error

/home/sganapa/catkin_ws/src/montage-anwendung/montage_roboter/src/ensenso_tutorial.cpp: line 10: syntax error near unexpected token `(' /home/sganapa/catkin_ws/src/montage-anwendung/montage_roboter/src/ensenso_tutorial.cpp: line 10: `void imageCallback(const sensor_msgs::ImageConstPtr& msg){'

edit retag flag offensive close merge delete

Comments

No one will be able to help you unless you show the error message you received.

gvdhoorn gravatar image gvdhoorn  ( 2020-04-02 07:06:35 -0500 )edit

Here I have added the error. As said, it says syntax error.

microbot gravatar image microbot  ( 2020-04-02 07:12:29 -0500 )edit

It's likely there are other errors before this one.

gvdhoorn gravatar image gvdhoorn  ( 2020-04-02 07:35:43 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted
0

answered 2020-04-02 07:53:05 -0500

How did you run the the node? What is the exact command? This error seems like you were trying to execute a cpp file instead of the binary compiled by catkin. I guess you probably ran your node like this

rosrun package_name ensenso_tutorial.cpp

Replace ensenso_tutorial.cpp with your executable target in CMakeLists.txt

edit flag offensive delete link more

Comments

yea exactly that was the error. Thank you.

microbot gravatar image microbot  ( 2020-04-02 08:07:49 -0500 )edit
0

answered 2020-04-02 07:49:18 -0500

microbot gravatar image

I have solved it, it was just a basic mistake where after catkin_make , instead of trying to run the target i was still calling the .cpp file. Now it is solved. Thanks.

edit flag offensive delete link more
0

answered 2020-04-02 07:20:55 -0500

jahim44229 gravatar image

updated 2020-04-02 07:23:12 -0500

Please add -> #include <image_transport/image_transport.h>

#include <ros/ros.h>
#include <image_transport/image_transport.h>


void imageCallback(const sensor_msgs::ImageConstPtr& msg){
     ROS_INFO("I heard the image");
}

int main(int argc, char **argv){

    ros::init(argc, argv, "test_node_vision");

    ros::NodeHandle nh;
    ros::Subscriber sub = nh.subscribe("/image_listener", 1000, imageCallback);

    ros::spin();


    return 0;
}
edit flag offensive delete link more

Comments

Hello, I have added the header file and the error still remains same.

microbot gravatar image microbot  ( 2020-04-02 07:25:44 -0500 )edit

My system compiled the code I sent to you. The error is not in the code.

You should control the CMakeLists.txt.

jahim44229 gravatar image jahim44229  ( 2020-04-02 07:29:47 -0500 )edit

yes, the code was right, i am trying to rosrun the cpp file instead of catkin_make binray. All the time looking at that syntax error i expected it to be a literal error. Thank you.

microbot gravatar image microbot  ( 2020-04-02 08:08:45 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-04-02 06:25:10 -0500

Seen: 27 times

Last updated: Apr 02