ros2dart / dartros1

A ROS1 client library for dart
Apache License 2.0
20 stars 11 forks source link

Issues on advertising a service #32

Closed jeff214103 closed 3 years ago

jeff214103 commented 3 years ago

Hi, I am facing an issue in advertising a service as server.

Once I advertise a service (node.advertiseService), it works pretty well. Some time later I shutdown and disconnect (service.shutdown(), service.disconnect()) the service, in rosnode info can be cleaned. However, once I would like to reconnect or re advertise the service by the same code (node.advertiseService), the service no longer be found in rosnode info. Although I can simply disconnect to ROS without running service.shutdown() nor service.disconnect(), but later the connection cannot be even established.

As I am using flutter, once I hot reload the app and do advertiseService, without re run the roscore, the service can be back.

I am not sure if it is an issue related to #18 , but I would appreciate if the fix can be made.

Edit: service will become null in second time connection. And the following message displayed. And later, shutdown cannot be called as the service variable become null Screenshot from 2021-05-21 12-40-16

TimWhiting commented 3 years ago

If you are calling shutdown and disconnect manually, you should instead be calling node.unadvertiseService(service), because there is some state internal to the node that keeps track of the services. I'm not sure that will resolve all the issues you mention, but let me know what problems still exist after that. I probably should make .shutdown and .disconnect private methods to avoid confusion.