Improved switching BTs with active Groot monitoring (ZMQ logger destruction)#244
Conversation
|
That latency for creating a BT was really nasty for nav2 when we have to do that relatively often when loading new BTs. My preference would be an option to |
| } | ||
| catch (zmq::error_t& err) | ||
| { | ||
| if (err.num() == ETERM) |
There was a problem hiding this comment.
Not my code base to tell you what to do, but if without brackets makes my skin crawl. Might want to make it explicit like the styling of the rest of the file (+ L177 below). I've been burned alot by this in the past when working in codebases with python developers not realizing that only the 1st line after the if is used in the condition without brackets in C++.
There was a problem hiding this comment.
The python perspective argument is really good.
This burned in somehow as a nice little c++ feature..
But better to skip stuff like that and keep it more readable / less future error prone..
There was a problem hiding this comment.
I'm also Mr. Explicit in my code, so I take the exact opposite extreme. I avoid auto unless the type is so long that I don't want to write it all out (and using it <2 times so not worth typedefing). Do as you like here, not up to me 😄
yes. this would still be a little bit nicer, but involves bigger changes to the architecture how the logger is "attached" to the tree. Also for the If interested by @facontidavide this could be tracked as future issue/future with a "nice to have" - label? |
|
it looks good to me. Thanks a lot for your contribution. Actually that logger needs a full refactoring at some point, because I am not 100% happy with the fact that the subtrees are not modelled in the serialized message. Anyway, this is another story.... |
|
??? But it builds on my machine™️ .. Also just tried with a clean build now.. Also just warnings and notes. |
|
This is the error from CI: Looks to me that the CI has an older version of the zmq library..? I'm building BT.CPP as part of the nav2_ws (including ROS2 from source and all dependencies, including BT.CPP) Edit: This is my installed version of libzmq3-dev: |
|
Don't worry, I can fix this myself later |

Switching BTs with active ZMQ logging (for Groot) enabled increased the switching time varying from ~20-99ms.
Switching is performed by destructing the zmq logger, loading a new tree based on xml with currently the same factory (plugins), and finally adding a new zmq logger to the new tree. For reference, see this PR here: ros-navigation/navigation2#1958
This is due to the timeout set for the ZMQ server. The detached thread always waits the timeout before the next while loop starts (which would end if the server is requested to end through the global variable).
BehaviorTree.CPP/src/loggers/bt_zmq_publisher.cpp
Line 68 in f54f6d8
( Timeout set in line 57 + 58 )
After consulting the ZMQ documentation, a few functions promised to directly halt any ongoing requests in the ZMQ context.
See the documentation here:
http://api.zeromq.org/master:zmq-ctx-shutdown
This successfully decreased the max blocking time of 100ms to 1 - 1,5ms for deconstructing the zmq logger.
( close() is already performed afterwards by the default constructor of the server and publisher objects ->
delete zmq_)