# I would like to know how I can call the /execute\_trajectory service from the terminal

**URL:** <https://get-help.theconstruct.ai/t/i-would-like-to-know-how-i-can-call-the-execute-trajectory-service-from-the-terminal/31789>\
**Category:** ROS Basics In 5 Days (Python)\
**Created:** [August 13, 2024, 10:26pm UTC](https://get-help.theconstruct.ai/t/i-would-like-to-know-how-i-can-call-the-execute-trajectory-service-from-the-terminal/31789 "2024-08-13T22:26:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![RicardoCarpio](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/ricardocarpio/32/8970_2.png) [@RicardoCarpio](https://get-help.theconstruct.ai/u/RicardoCarpio)\
**Post date:** [August 13, 2024, 10:26pm UTC](https://get-help.theconstruct.ai/t/i-would-like-to-know-how-i-can-call-the-execute-trajectory-service-from-the-terminal/31789/1 "2024-08-13T22:26:26Z")

</div>

Hello everyone.  
First of all, I want to tell everyone that I’m just starting out with ROS and that this is my first post on the forum. I think this will be noticed, so I apologize in advance if my question is not formatted correctly or is not in the right place. Please let me know so I can improve future posts on this forum.

My situation is the following:  
• ROS Fundamentals Course in 5 days (Python)  
• Unit 5 Understanding ROS services - Clients

I would like to know how I can call the _ **/execute\_trajectory** _ service from the terminal, once it has been previously launched from another terminal of course.

My actions are as follows:

The node that provides the _ **/execute\_trajectory service** _ is _ **iri\_wam\_reproduce\_trajectory** _ so I look at the structure of this package using:

```auto
roscd iri_wam_reproduce_trajectory
ls

```

 ![image](https://get-help.theconstruct.ai/uploads/default/original/2X/6/66c43bb479379fe9d34d0852686ca3d43dbb355d.png)

I see that there is a launch folder where the start\_service.launch file is to launch the node. There is a config folder with three .txt files _ **get\_food.txt** _, _ **init\_pos.txt** _ and _ **release\_food.txt** _ (with the coordinates of the trajectories to be followed by the WAM robot when it is called by another node) and there is the _ **srv** _ folder where the _ **ExecTraj.srv** _ service message file is. This message file contains:

```auto
string file
---

```

What I understand, as explained in the course, is that to call the _ **/execute\_trajectory** _ service, it is necessary to pass as a call parameter a file (of the three that are in the config folder above) to specify which trajectory I want the robotic arm to execute.  
I launch the _ **/execute\_trajectory** _ service using:

```auto
roslaunch iri_wam_reproduce_trajectory start_service.launch

```

The service starts perfectly waiting for someone to call it.

 ![image](https://get-help.theconstruct.ai/uploads/default/original/2X/d/da935f06381a58593cfe5f306b0f5144880c82c1.jpeg)

from another terminal

 ![image](https://get-help.theconstruct.ai/uploads/default/original/2X/f/f01159e56793248d0b3d650f406e892155df152b.jpeg)

With all this, I run to call the service _ **/execute\_trajectory** _ with the trajectory for example of _ **get\_food.txt** _ (with the help of [TAB]+ [TAB] of course) using

```auto
rosservice call /execute_trajectory "file:'get_food.txt'"

```

but I get an error:  
ERROR: service [/execute\_trajectory] responded with an error: b’’

 ![image](https://get-help.theconstruct.ai/uploads/default/original/2X/4/49a7f5ac951af0e0260742b391beb1887fe0cfd5.png)

And in the terminal where I launched the service a message appears telling me that it cannot open the file get\_food.txt (Unable to open file [get\_food.txt]

 ![image](https://get-help.theconstruct.ai/uploads/default/original/2X/7/7c3b33b0638f834048a3d8316c1663ac9ea4b22b.png)

Please, if someone could tell me where the error in my approach is. Thank you all very much!!!

---

<div class="post-metadata">

**Author:** ![roalgoal](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/roalgoal/32/7280_2.png) [@roalgoal](https://get-help.theconstruct.ai/u/roalgoal)\
**Post date:** [August 14, 2024, 7:59am UTC](https://get-help.theconstruct.ai/t/i-would-like-to-know-how-i-can-call-the-execute-trajectory-service-from-the-terminal/31789/2 "2024-08-14T07:59:14Z")

</div>

Hi @RicardoCarpio, welcome to the community!

Thank you for the detailed post.

My guess here is that the service server can’t find `get_food.txt` because it can’t resolve the path it is at.

Make sure the file is at `iri_warm_reproduce_trajectory/config` and that the server can resolve the path with

```auto
import rospkg
rospack = rospkg.RosPack()
# This rospack.get_path() works in the same way as $(find name_of_package) in the launch files.
traj = rospack.get_path('iri_wam_reproduce_trajectory') + "/config/get_food.txt"

```

You can further debug by printing `traj` and see if it’s correct.

---

<div class="post-metadata">

**Author:** ![RicardoCarpio](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/ricardocarpio/32/8970_2.png) [@RicardoCarpio](https://get-help.theconstruct.ai/u/RicardoCarpio)\
**Post date:** [August 14, 2024, 1:36pm UTC](https://get-help.theconstruct.ai/t/i-would-like-to-know-how-i-can-call-the-execute-trajectory-service-from-the-terminal/31789/3 "2024-08-14T13:36:28Z")

</div>

Hi _ **roalgoal** _, thanks a lot for your reply.

I have run the python code you have provided to get the full path of the get\_food.txt file. I had already tried something similar….but I get the same error if I call the service with the full path of the file.

I really appreciate the idea you have given.

Thanks roalgoal

Your code and the result when called the service:

 ![image](https://get-help.theconstruct.ai/uploads/default/original/2X/d/d274f2381bf5d22dff69109176d756e143bb353e.jpeg)

the terminal since it launched the service

 ![image](https://get-help.theconstruct.ai/uploads/default/original/2X/a/a6f8d0025bfbb5ba4d1b8c816b0d8b6d541a0e7c.png)

---

<div class="post-metadata">

**Author:** ![roalgoal](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/roalgoal/32/7280_2.png) [@roalgoal](https://get-help.theconstruct.ai/u/roalgoal)\
**Post date:** [August 16, 2024, 7:49am UTC](https://get-help.theconstruct.ai/t/i-would-like-to-know-how-i-can-call-the-execute-trajectory-service-from-the-terminal/31789/4 "2024-08-16T07:49:49Z")

</div>

🤔 that is defintely strange, since I can find the file with

```auto
user:~$ ls /home/simulations/public_sim_ws/src/all/iri_wam/iri_wam_reproduce_trajectory/config/get_food.txt
/home/simulations/public_sim_ws/src/all/iri_wam/iri_wam_reproduce_trajectory/config/get_food.txt

```

maybe the issue here is that the terminal is not sourcing that workspace correctly? Make sure that the file exists and then also source before running your service server:

```auto
source /home/simulations/public_sim_ws/devel/setup.bash

```

---

<div class="post-metadata">

**Author:** ![RicardoCarpio](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/ricardocarpio/32/8970_2.png) [@RicardoCarpio](https://get-help.theconstruct.ai/u/RicardoCarpio)\
**Post date:** [August 16, 2024, 4:23pm UTC](https://get-help.theconstruct.ai/t/i-would-like-to-know-how-i-can-call-the-execute-trajectory-service-from-the-terminal/31789/5 "2024-08-16T16:23:06Z")

</div>

Thanks roalgoal…the get\_food.txt file exists and is in place. I have also checked that my workspace has access to this location as you have recommended but I still cannot call the /execute\_trajectory service 😔 The same error appears:

```auto
ERROR: service [/execute_trajectory] responded with an error: b''

```

Thank you very much for your time 🙏

---

<div class="post-metadata">

**Author:** ![roalgoal](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/roalgoal/32/7280_2.png) [@roalgoal](https://get-help.theconstruct.ai/u/roalgoal)\
**Post date:** [August 19, 2024, 10:01am UTC](https://get-help.theconstruct.ai/t/i-would-like-to-know-how-i-can-call-the-execute-trajectory-service-from-the-terminal/31789/6 "2024-08-19T10:01:11Z")

</div>

Hi @RicardoCarpio, I finally understand your issue, sorry it took me so long.

You are simply following the instructions here, not writing your own service server.

In the example, the server is launched and then a client that calls the service `/execute_trajectory`. This is the same as calling `/trajectory_by_name` and setting the name to `get_food`.

The file you created `foro_1.py` does nothing, so you can disregard it. I was answering thinking you were writing the service server you were trying to call.

---

<div class="post-metadata">

**Author:** ![RicardoCarpio](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/ricardocarpio/32/8970_2.png) [@RicardoCarpio](https://get-help.theconstruct.ai/u/RicardoCarpio)\
**Post date:** [August 19, 2024, 12:35pm UTC](https://get-help.theconstruct.ai/t/i-would-like-to-know-how-i-can-call-the-execute-trajectory-service-from-the-terminal/31789/7 "2024-08-19T12:35:05Z")

</div>

> [@roalgoal](#):
>
> /trajectory\_by\_name

Hi @roalgoal. Thanks 🙏 and sorry 😔 but I don’t understand what you’re trying to tell me.  
I understand that _ **/execute\_trajectory** _ and _ **/execute\_trajectory\_by\_name** _ are two different services.  
If I launch the _ **/execute\_trajectory\_by\_name** _ service, I have no problems calling it from the console passing the name of the trajectory as a parameter (get\_food).  
But if I launch the _ **/execute\_trajectory** _ service I can’t call it from the console passing the name of the file that represents the trajectory as a parameter (get\_food.txt).  
Sorry but I didn’t understand your answer. 🤫

---

<div class="post-metadata">

**Author:** ![roalgoal](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/roalgoal/32/7280_2.png) [@roalgoal](https://get-help.theconstruct.ai/u/roalgoal)\
**Post date:** [August 20, 2024, 8:05am UTC](https://get-help.theconstruct.ai/t/i-would-like-to-know-how-i-can-call-the-execute-trajectory-service-from-the-terminal/31789/8 "2024-08-20T08:05:36Z")

</div>

I am sorry for confusing you @RicardoCarpio, I was just trying to explain you the difference without giving you the answer outright.

Yes, there are two separate services that are provided when you launch `roslaunch trajectory_by_name start_service.launch`:

1. `/trajectory_by_name`, offered by `/traj_by_name_node`.
2. `/execute_trajectory`, offered by `/iri_wam_reproduce_trajectory`.

They both do the same. `trajectory_by_name` the name of the trajectory, while `execute_trajectory` requries the actual path to the file.

To call `/execute_trajectory` from a terminal:

```auto
rosservice call /execute_trajectory "file: '/home/simulations/public_sim_ws/src/all/iri_wam/iri_wam_reproduce_trajectory/config/get_fo
od.txt'

```

![rb5dp_execute_trajectory](https://get-help.theconstruct.ai/uploads/default/original/2X/8/88ea13303b29c211218bccfef0636959fe51cd8c.gif)

---

<div class="post-metadata">

**Author:** ![RicardoCarpio](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/ricardocarpio/32/8970_2.png) [@RicardoCarpio](https://get-help.theconstruct.ai/u/RicardoCarpio)\
**Post date:** [August 20, 2024, 11:20am UTC](https://get-help.theconstruct.ai/t/i-would-like-to-know-how-i-can-call-the-execute-trajectory-service-from-the-terminal/31789/9 "2024-08-20T11:20:31Z")

</div>

Hi @roalgoal, perfect!! For some strange reason I already tried this and it didn’t work. In your answer

> that is defintely strange, since I can find the file with

```auto
user:~$ ls 
/home/simulations/public_sim_ws/src/all/iri_wam/iri_wam_reproduce_trajectory/config/get_food.txt

```

you already indicated the path of the file and I already tried it with error. But now I have taken all the precautions to copy the entire path of the file and that it is between the single quotes. I think the reason is not so strange, 😔 it is that I should pay more attention to the commands that I execute and even more, if they contain long strings, single quotes, double quotes etc…  
I really appreciate your dedication and help.  
Thank you very much for solving the problem for me!!! 🤩 🤩 🤩 🤩 🤩 🤩

---

<div class="post-metadata">

**Author:** ![system](https://get-help.theconstruct.ai/uploads/default/original/2X/9/9d3ce8305cc0d0d9b6e07d15767a6f245c526f1b.jpeg) [@system](https://get-help.theconstruct.ai/u/system)\
**Post date:** [August 25, 2024, 11:21am UTC](https://get-help.theconstruct.ai/t/i-would-like-to-know-how-i-can-call-the-execute-trajectory-service-from-the-terminal/31789/10 "2024-08-25T11:21:20Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
