3636#include < fuse_core/callback_wrapper.h>
3737#include < fuse_core/graph.h>
3838#include < fuse_core/transaction.h>
39- #include < ros/node_handle.h>
40-
41- #include < boost/make_shared.hpp>
39+ #include < rclcpp/rclcpp.hpp>
4240
4341#include < functional>
42+ #include < memory>
4443#include < utility>
4544#include < string>
4645
@@ -50,7 +49,7 @@ namespace fuse_core
5049
5150AsyncMotionModel::AsyncMotionModel (size_t thread_count) :
5251 name_ (" uninitialized" ),
53- spinner_ (thread_count, &callback_queue_ )
52+ executor_ (rclcpp::ExecutorOptions(), thread_count )
5453{
5554}
5655
@@ -62,56 +61,67 @@ bool AsyncMotionModel::apply(Transaction& transaction)
6261 // Thus, it is functionally similar to a service callback, and should be a familiar pattern for ROS developers.
6362 // This function blocks until the queryCallback() call completes, thus enforcing that motion models are generated
6463 // in order.
65- auto callback = boost ::make_shared<CallbackWrapper<bool >>(
64+ auto callback = std ::make_shared<CallbackWrapper<bool >>(
6665 std::bind (&AsyncMotionModel::applyCallback, this , std::ref (transaction)));
67- auto result = callback->getFuture ();
68- callback_queue_. addCallback (callback, reinterpret_cast < uint64_t >( this ) );
66+ auto result = callback->get_future ();
67+ waitables_interface_-> add_waitable (callback, nullptr );
6968 result.wait ();
69+ waitables_interface_->remove_waitable (callback, nullptr );
70+
7071 return result.get ();
7172}
7273
7374void AsyncMotionModel::graphCallback (Graph::ConstSharedPtr graph)
7475{
75- callback_queue_.addCallback (
76- boost::make_shared<CallbackWrapper<void >>(std::bind (&AsyncMotionModel::onGraphUpdate, this , std::move (graph))),
77- reinterpret_cast <uint64_t >(this ));
76+ auto callback = std::make_shared<CallbackWrapper<void >>(std::bind (&AsyncMotionModel::onGraphUpdate, this , std::move (graph)));
77+ auto result = callback->get_future ();
78+ waitables_interface_->add_waitable (callback, nullptr );
79+ result.wait ();
80+ waitables_interface_->remove_waitable (callback, nullptr );
81+
82+ // @todo TAM: figure out whether we needed the second argument to addCallback here
83+ // callback_queue_.addCallback(
84+ // boost::make_shared<CallbackWrapper<void>>(std::bind(&AsyncMotionModel::onGraphUpdate, this, std::move(graph))),
85+ // reinterpret_cast<uint64_t>(this));
7886}
7987
8088void AsyncMotionModel::initialize (const std::string& name)
8189{
8290 // Initialize internal state
8391 name_ = name;
84- node_handle_.setCallbackQueue (&callback_queue_);
85- private_node_handle_ = ros::NodeHandle (" ~/" + name_);
86- private_node_handle_.setCallbackQueue (&callback_queue_);
92+ node_ = rclcpp::Node::make_shared (name);
93+ waitables_interface_ = node_->get_node_waitables_interface ();
8794
8895 // Call the derived onInit() function to perform implementation-specific initialization
8996 onInit ();
9097
91- // Start the async spinner to service the local callback queue
92- spinner_.start ();
98+ executor_.add_node (node_);
9399}
94100
95101void AsyncMotionModel::start ()
96102{
97- auto callback = boost ::make_shared<CallbackWrapper<void >>(std::bind (&AsyncMotionModel::onStart, this ));
98- auto result = callback->getFuture ();
99- callback_queue_. addCallback (callback, reinterpret_cast < uint64_t >( this ) );
103+ auto callback = std ::make_shared<CallbackWrapper<void >>(std::bind (&AsyncMotionModel::onStart, this ));
104+ auto result = callback->get_future ();
105+ waitables_interface_-> add_waitable (callback, nullptr );
100106 result.wait ();
107+ waitables_interface_->remove_waitable (callback, nullptr );
101108}
102109
103110void AsyncMotionModel::stop ()
104111{
105- if (ros ::ok ())
112+ if (rclcpp ::ok ())
106113 {
107- auto callback = boost ::make_shared<CallbackWrapper<void >>(std::bind (&AsyncMotionModel::onStop, this ));
108- auto result = callback->getFuture ();
109- callback_queue_. addCallback (callback, reinterpret_cast < uint64_t >( this ) );
114+ auto callback = std ::make_shared<CallbackWrapper<void >>(std::bind (&AsyncMotionModel::onStop, this ));
115+ auto result = callback->get_future ();
116+ waitables_interface_-> add_waitable (callback, nullptr );
110117 result.wait ();
118+ waitables_interface_->remove_waitable (callback, nullptr );
111119 }
112120 else
113121 {
114- spinner_.stop ();
122+ executor_.cancel ();
123+ executor_.remove_node (node_);
124+
115125 onStop ();
116126 }
117127}
0 commit comments