Unit 5 simple_service_client.py

Hello,

When I copy the Python Program: simple_service_client.py. The script said I can not import service trajectory_by_name_srv.srv. I added service like this in Cmakelist image Should I do something in the package.xml too?

Sorry in advance, i might forget something important

Hi @xj2106 ,
Are you copying this script to a new package? if yes, then you have to add the name of the package containing the srv file as a dependency while creating the new package.

catkin_create_pkg new_package rospy name_of_pkg_containing_srv_file

@Joseph1001 Thank you for answering. No But the my_examples_pkg does not have this dependencys. I tried to manually add them in the CMAKELIST but it wont work. Should I add service or the package of trajectory_by_name_srv.srv?

This is the error btw.

Why don’t you try creating a new package, one with the package containg the srv file as a dependency and then copy the python file you are working on into that?

This way the program knows that this is a dependency from the start

Also, sometime, you are able to run the program even though this red lines exists, so try compiling the program using catkin_make and try running the program.

Hi there, I am having the same issue. I have remade built and sourced the package with the relevant dependencies but I am still getting the same error unfortunately.

When I run the launch file this error occurs as a result - “process[iri_wam_reproduce_trajectory-1]: started with pid [8602]
RLException: Unable to launch [service_demo-2].
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
[ INFO] [1646759687.278063473]: Waiting for action server to start.
[service_demo-2] killing on exit
[iri_wam_reproduce_trajectory-1] killing on exit”

@Joseph1001 Hello, I created a new pkg like this

However, it still can not find the trajectory.srv

are you sure you have entered as the first line in the python script?:
#! /usr/bin/env python

you should get set as interpreter in text below it, if you have done this correctly.

I understand that you are getting the red line showing error in the IDE, but are you getting any errors when running the program? because sometimes the program works as intended even with the red line. Try running the program after compiling using catkin_make and source using source devel/setup.bash. Share any errors that pop up. Will be easier to troubelshoot from there.

Yes, It worked. Thanks Joseph

1 Like

Hi yes I have a script with #! /usr/bin/env python at the start of it. I have used catkin_make and source devel etc. My launch file also launchs iri_wam_reproduce_trajectory)/launch/start_service.launch as per the exercise. Could it be a problem there?

I have removed the interperter line and rewritten it incase of hidden characters in the copy paste. I am now getting new errors “linter pylint is not installed” and “Formatter autopep8 is not installed. Install?”

Hi, can you share the following:

  • The unit number in the course where this error occurred

  • the launch file code using image

  • The python script ,using image

Lastly, can you try loggin out and loggin back in, since this gives you a new VM and that has also worked sometimes.