ros-drivers / rosserial

A ROS client library for small, embedded devices, such as Arduino. See: http://wiki.ros.org/rosserial
508 stars 526 forks source link

[WIP] Implement rosservice server in rosserial_server #453

Open tongtybj opened 4 years ago

tongtybj commented 4 years ago

Use topic_tools::ShapeShifter to create proxy service servers in rosserial server.

Also, during the implementation, I found a very interesting phenomenon. When the callback function of a proxy service server is called, all process related to boost::asio seem to be paused, meaning that no response can be caught from rosserial client unless this service callback function is over. This can be check in c32952f .

So I replace boost::asio::deadline_timer ros_spin_timer_ with ros::AsyncSpinner which has 2 threads. I know this might be a trivial reverting action. But can anyone tell me the motivation to use boost::asio::deadline_timer ros_spin_timer_ and what this comment means?

romainreignier commented 4 years ago

Hi, nice PR! I have never needed a service server on the rosserial_client side but it is nice to see this feature added.

About the async spinner, from what I understand, the current implementation is using the io_service to keep only one thread to simplify the design and avoid synchronization issues. In your implementation, there is now 3 threads and I do not see any synchronization primitives to protect the resources.

tongtybj commented 3 years ago

@romainreignier

In your implementation, there is now 3 threads and I do not see any synchronization primitives to protect the resources.

I think the only shared resource that should be protected is the write (async_write) process, since the ros callback functions and several dealine_timers do the write process from different threads.

So I add a mutex to lock the following part:

https://github.com/ros-drivers/rosserial/blob/50a94094e334e7c99d41e6138a5bb5dcdd02b7ab/rosserial_server/include/rosserial_server/session.h#L267-L270