ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

missing a '#!' declaration at the top in ROS basic C++ tutorial

asked 2020-01-10 10:09:21 -0500

krithika gravatar image

updated 2020-01-10 18:29:49 -0500

jayess gravatar image

Unable to execute exercise 3.1 in ROS C++ tutorial for beginners. I am getting the the error as shown above.

Steps used to execute are:

  1. Create package with dependencies roscpp and trajectory_by_name_srv.
  2. Create Cpp program under src folder using 3.1 exercise cpp code
  3. Create launch folder with launch file simple_service.launch

contents:

<launch>

  <include file="$(find trajectory_by_name)/launch/start_service.launch"/>

  <node pkg ="service_client_pkg"
        type="simple_service_client.cpp"
        name="service_client"
        output="screen"/>

</launch>
  1. run catkin_make
  2. run source devel/setup.bash
  3. Roslaunch the service

Edit:

Error

process[traj_by_name_node-2]: started with pid [25837]
Unable to launch [service_client-3].
If it is a script, you may be missing a '#!' declaration at the top.
The traceback for the exception was written to the log file
[service_client-3] killing on exit
[traj_by_name_node-2] killing on exit
[iri_wam_reproduce_trajectory-1] killing on exit
Traceback (most recent call last):
  File "/home/simulations/public_sim_ws/src/all/iri_wam/trajectory_by_name/src/traj_by_name.py", line 21, in <module>
    rospy.init_node('traj_by_name_node')
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/client.py", line 323, in init_node
    raise rospy.exceptions.ROSInitException("init_node interrupted before it could complete")
rospy.exceptions.ROSInitException: init_node interrupted before it could complete
edit retag flag offensive close merge delete

Comments

Do you have a question? Are you referring to a particular tutorial that has an issue? It's a bit tough for people to know how to help you the way the question is written.

jarvisschultz gravatar image jarvisschultz  ( 2020-01-10 11:31:50 -0500 )edit

I do have a question, i am unable to execute exercise 3.1 on ROS services, I followed the instructions but i am still getting an error

krithika gravatar image krithika  ( 2020-01-10 12:00:27 -0500 )edit

This is the error i am getting :

process[traj_by_name_node-2]: started with pid [25837] Unable to launch [service_client-3]. If it is a script, you may be missing a '#!' declaration at the top. The traceback for the exception was written to the log file [service_client-3] killing on exit [traj_by_name_node-2] killing on exit [iri_wam_reproduce_trajectory-1] killing on exit Traceback (most recent call last): File "/home/simulations/public_sim_ws/src/all/iri_wam/trajectory_by_name/src/traj_by_name.py", line 21, in <module> rospy.init_node('traj_by_name_node') File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/client.py", line 323, in init_node raise rospy.exceptions.ROSInitException("init_node interrupted before it could complete") rospy.exceptions.ROSInitException: init_node interrupted before it could complete

krithika gravatar image krithika  ( 2020-01-10 12:42:35 -0500 )edit

@krithika please make sure to update your question with this type of information rather than using a comment. It makes the question easier to follow. Also, you don't need to use HTML <br> tags, you can use newlines to separate content (and activate the list too)

jayess gravatar image jayess  ( 2020-01-10 18:31:42 -0500 )edit

@krithika: always link to any tutorials or pages you are reading/using.

Right now we don't know what you are referring to, which complicates me helping you.


Edit: you are most likely doing some exercises created by the Construct. Have you asked them for help?

gvdhoorn gravatar image gvdhoorn  ( 2020-01-11 04:09:04 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-01-10 12:05:44 -0500

gvdhoorn gravatar image

updated 2020-01-12 05:44:32 -0500

I'm guessing the OP reports an issue he ran into, namely the inability of roslaunch to start the node service_client. The #! mentioned in the title of the question would be the shebang, which would help if this was a Python script. But this is C++ (as evidenced by simple_service_client.cpp), so must be compiled first.

There is a way to use a shebang with C++, but it's not used in the beginner tutorials, and I doubt it should be.

@krithika: did you remember to actually build your workspace? You cannot directly execute .cpp files. They need to be compiled into executable binaries first.


Edit:

yes, I built my workspace using catkin_make --only-pkg-with-deps <package-name>

the problem is here:

  <node pkg ="service_client_pkg"
        type="simple_service_client.cpp"
        name="service_client"
        output="screen"/>

Note how you have type="simple_service_client.cpp". This is incorrect, the type should be set to the name of the binary, not the name of the source file.

We don't know what the name of your node actually is, but assuming it is simple_service_client, you should set type to simple_service_client, source your workspace (ie: source /home/simulations/public_sim_ws/devel/setup.bash) and then try again to launch your .launch file.

edit flag offensive delete link more

Comments

yes, I built my workspace using catkin_make --only-pkg-with-deps <package-name>

krithika gravatar image krithika  ( 2020-01-10 12:52:29 -0500 )edit

I changed the name to the executable and it worked. Thank you

krithika gravatar image krithika  ( 2020-01-11 16:14:56 -0500 )edit

Question Tools

Stats

Asked: 2020-01-10 10:09:21 -0500

Seen: 7,669 times

Last updated: Jan 12 '20