in the final project i stucked in a bug that I don’t know how to solve respecting the points given by the text.
I produced two service server, wall follower and wall finder, and an action server for odom monitoring.
The main file (wall_follower) is a service server which turns out also as client of the second service (wall_finder). Both service have callbacks on the scan topic for moving.
So, if I activate the service client of the wall_follower, it executes also the wall_finder service serever acting as client.
However, after the accomplishment of the find wall service, the scan callback used by the wall_follower stop to publish. Therefore, once the robot try to follow the wall, it does not update the laser information and goes into the wall.
I think it is a multithreads issue. Indeed, both services worked when operate and are launched separately.
Since you have not posted any code snippets or error logs, I will just tell you what things are incorrect.
Firstly, it is a good practice to have the topics, services and actions modules separately.
So, you will have one program node dedicated for topics, one for sevices and one for actions.
Essentially, towards the end, you will have the Wall Follower logic with Topics, Find Wall Service Client and RecordOdom Action Client in the same node (one program file), but the Find Wall Service Server and the RecordOdom Action Server will remain as individual program nodes.
You should never have a server and client in the same program file. It is a bad practice. It goes for both Services and Actions. Only Topics can have both Publisher and Subscriber in the same program file. This said, please move your service server to a different file.
You are indeed getting into a “blocked callback situation” in your code. In the main file, you said you have both wall follower with service server and service client. Your program does not know how to process multiple callbacks - service server callback, service client callbacks, scan subscriber and main timer (I am assuming these are the at least 4 callbacks in your main program). You should go through the chapter on MultiThreadedExecutors and apply that concept properly. You are getting in to callback locks that blocks one callback from execution, in your case, the scan callback as you have mentioned.
The solution is to separate the service server from the main program file and implement MultiThreadedExecutor with proper Callback Groups for each callback.
Yes. Indeed I had some doubts about how to structure the project.
I think that the two servers or operation clients (i.e. find and follow) necessitate to be launched by two different launch files for the accomplishment of the project.
I did it and it works now.
In the before mentioned message I tried to include the find wall service client in the service server of the wall following operation (a service server in my case) unsuccessfully.
Indeed, in the past version, after the find_wall service is accomplished, the odom topic is no more read by the wall_following service server previosly launched by a dedicated client.
Is the solution i opted and that works ok for the accomplishment of the final project?
I can pass you the code with instructions if you want.
Otherwise, in case it is necessary to accomplish the project goal considering only one action/service client launch, I don’t know I to figure it out. I think there is a problem of number of available threads.
Before you post your code here, I recommend you to check the issues posted by others who did this project before you. You can search through this forum itself.
The ideal project file structure will be as follows:
Wall Follower - basic version with topics only in one program file
Find Wall Service Server - service server only in one program file
Find Wall Service Client - service client only in one program file
Wall Follower with Find Wall Service Client - basic version + service client in one program file
Record Odom Action Server - action server only in one program file
Record Odom Action Client - action client only in one program file
Wall Follower + Find Wall Client + Record Odom Client - wall follower program integrated with service and action clients in one program file
Following the above structure will be very helpful for you to debug your issues from time to time when using the real robot (as well as simulation).
Number of available threads is never a problem. There is no true parallelism in CPUs, so even a program that requires all 8 threads of the CPU, will work in polled mode.
That said, the maximum callbacks that you can have in a program is 7. 1 timer + 7 callbacks, total of 8.
Find Wall Service Server : service callback + scan callback = 2 threads
Find Wall Service Client : service callback only = 1 thread
Wall Follower + Find Wall Service Client : timer + scan + service = 3 threads
Record Odom Action Server : action callback + odom callback = 2 threads
Record Odom Action Client : goal callback + feedback callback + result callback = 3 threads
Wall Follower + Find Wall Client + Record Odom Client : timer + scan + odom (if needed) + service client + action goal + action feedback + action result = 6 or 7 threads
When running the robot, only 3 programs will be launched: Find Wall Service Server, Record Odom Action Server and the Integrated Wall Follower with Service and Action Clients.
I hope this gives you an idea of how to setup your project.