Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use BT.CPP recommended sleep for event-driven trees? #4736

Closed
tonynajjar opened this issue Oct 29, 2024 · 4 comments
Closed

Use BT.CPP recommended sleep for event-driven trees? #4736

tonynajjar opened this issue Oct 29, 2024 · 4 comments

Comments

@tonynajjar
Copy link
Contributor

tonynajjar commented Oct 29, 2024

Feature request

Feature description

I would be surprised if I'm the first one to bring up this discussion but I didn't find it anywhere. Why aren't we using the recommended Tree::sleep() from BT.CPP instead of the ROS rclcpp::WallRate to leverage event-driven trees?

I guess an obvious reason would be the better integration of rclcpp::WallRate with simulation time. But shouldn't we thrive to have all the benefits that both offer?

In a couple of instances we use emitWakeUpSignal, but afaik these should be useless without Tree::sleep() right @facontidavide?

Implementation considerations

@tonynajjar tonynajjar changed the title Use BT.CPP recommended sleep? Use BT.CPP recommended sleep for event-driven trees? Oct 29, 2024
@SteveMacenski
Copy link
Member

Sorry for the delay, ROSCon, ROS-I, and so forth kept me from a computer.

Why aren't we using the recommended Tree::sleep()

Because it didn't exist in BT.CPP when we created that bit of software :-) My immediate thought is that I'm perfectly happy moving to the Tree::sleep() API. We use the WallRate for this operation, so simulation time isn't even considered for the BT ticking.

After looking at the BT.CPP implementation, I don't see any downsides to that change. @tonynajjar want to submit a PR?

@facontidavide
Copy link
Contributor

Exactly! Tree::sleep() was created to potentially lower the latency, compared to a regular "sleep".

Tree::sleep() is basically a a std::condition_variable::wait_for under the hood.

This allows, as @tonynajjar point out, to wake uyp immediately when ANY node invokes emitWakeUpSignal.

Note that in general I suggest people to tick at 1 KHz using Tree::sleep(). Overhead should be minimal.

Unfortunately, there is a problem here, that prevent us ticking at high framerate.: https://github.com/ros-navigation/navigation2/blob/main/nav2_behavior_tree/src/behavior_tree_engine.cpp#L57-L74

The tick frequency is also the frequency of onLoop(); and what happens in thta callback could be arbitrarily slow 😢

Summarizing, I agree that using Tree::sleep() is an iprovement, but the latency of onLoop will also play a role.

@tonynajjar
Copy link
Contributor Author

Will give it a shot!

@SteveMacenski
Copy link
Member

Open a PR if its working well! I think it should ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants