Hi,
Doing the unit 4, services in ROS exercise I reach a solution which is pretty similar to the proposed one. I just wonder why my solution still works when passing the “get_food.txt” file path to the execute_trajectory ServiceProxy, instead of passing an ExecTrajRequest object containing the file path in the “file” attribute as proposed in your solution:
My solution:
# This rospack.get_path() works in the same way as $(find name_of_package) in the launch files.
trajectory_file_path = rospack.get_path('iri_wam_reproduce_trajectory') + "/config/get_food.txt"
# Create the connection to the service
execute_trajectory_service_client = rospy.ServiceProxy('/execute_trajectory', ExecTraj)
# Send through the connection the name of the trajectory to be executed by the robot
result = execute_trajectory_service_client(trajectory_file_path)
Proposed solution:
# This rospack.get_path() works in the same way as $(find name_of_package) in the launch files.
trajectory_file_path = rospack.get_path('iri_wam_reproduce_trajectory') + "/config/get_food.txt"
# Create the connection to the service
execute_trajectory_service_client = rospy.ServiceProxy('/execute_trajectory', ExecTraj)
execute_trajectory_request_object = ExecTrajRequest() # Create an object of type ExecTrajRequest
execute_trajectory_request_object.file = trajectory_file_path # Fill the variable file of this object with the desired file path
result = execute_trajectory_service_client(execute_trajectory_request_object)
Running both of this perform the trajectory as expected.