Ask Your Question
0

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

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

krithika gravatar image

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

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 imagejarvisschultz ( 2020-01-10 11:31:50 -0600 )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 imagekrithika ( 2020-01-10 12:00:27 -0600 )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 imagekrithika ( 2020-01-10 12:42:35 -0600 )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 imagejayess ( 2020-01-10 18:31:42 -0600 )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 imagegvdhoorn ( 2020-01-11 04:09:04 -0600 )edit

1 Answer

Sort by » oldest newest most voted
0

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

gvdhoorn gravatar image

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

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 imagekrithika ( 2020-01-10 12:52:29 -0600 )edit

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

krithika gravatar imagekrithika ( 2020-01-11 16:14:56 -0600 )edit

Could you please mark the question as answered by ticking the checkmark (✓) to the left of the answer if you feel it has been answered? Thanks.

gvdhoorn gravatar imagegvdhoorn ( 2020-01-12 05:30:00 -0600 )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

Stats

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

Seen: 49 times

Last updated: Jan 12