@@ -54,6 +54,50 @@ namespace executors
54
54
using rclcpp::executors::MultiThreadedExecutor;
55
55
using rclcpp::executors::SingleThreadedExecutor;
56
56
57
+ // / Spin (blocking) until the conditon is complete, it times out waiting, or rclcpp is interrupted.
58
+ /* *
59
+ * \param[in] executor The executor which will spin the node.
60
+ * \param[in] node_ptr The node to spin.
61
+ * \param[in] condition The callable or future to wait on. If `SUCCESS`, the condition is safe to
62
+ * access after this function
63
+ * \param[in] timeout Optional timeout parameter, which gets passed to
64
+ * Executor::spin_node_once.
65
+ * `-1` is block forever, `0` is non-blocking.
66
+ * If the time spent inside the blocking loop exceeds this timeout, return a `TIMEOUT` return code.
67
+ * \return The return code, one of `SUCCESS`, `INTERRUPTED`, or `TIMEOUT`.
68
+ */
69
+ template <typename Condition, typename DurationT = std::chrono::milliseconds>
70
+ rclcpp::FutureReturnCode
71
+ spin_node_until_complete (
72
+ rclcpp::Executor & executor,
73
+ rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
74
+ const Condition & condition,
75
+ DurationT timeout = DurationT(-1 ))
76
+ {
77
+ // TODO(wjwwood): does not work recursively; can't call spin_node_until_complete
78
+ // inside a callback executed by an executor.
79
+ executor.add_node (node_ptr);
80
+ auto retcode = executor.spin_until_complete (condition, timeout);
81
+ executor.remove_node (node_ptr);
82
+ return retcode;
83
+ }
84
+
85
+ template <typename NodeT = rclcpp::Node, typename ConditionT,
86
+ typename DurationT = std::chrono::milliseconds>
87
+ rclcpp::FutureReturnCode
88
+ spin_node_until_complete (
89
+ rclcpp::Executor & executor,
90
+ std::shared_ptr<NodeT> node_ptr,
91
+ const ConditionT & condition,
92
+ DurationT timeout = DurationT(-1 ))
93
+ {
94
+ return rclcpp::executors::spin_node_until_complete (
95
+ executor,
96
+ node_ptr->get_node_base_interface (),
97
+ condition,
98
+ timeout);
99
+ }
100
+
57
101
// / Spin (blocking) until the future is complete, it times out waiting, or rclcpp is interrupted.
58
102
/* *
59
103
* \param[in] executor The executor which will spin the node.
@@ -67,31 +111,28 @@ using rclcpp::executors::SingleThreadedExecutor;
67
111
* \return The return code, one of `SUCCESS`, `INTERRUPTED`, or `TIMEOUT`.
68
112
*/
69
113
template <typename FutureT, typename TimeRepT = int64_t , typename TimeT = std::milli>
114
+ [[deprecated(" use spin_node_until_complete(Executor &, node_interfaces::NodeBaseInterface::SharedPtr, const Condition &, DurationT) instead" )]]
70
115
rclcpp::FutureReturnCode
71
116
spin_node_until_future_complete (
72
117
rclcpp::Executor & executor,
73
118
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
74
119
const FutureT & future,
75
120
std::chrono::duration<TimeRepT, TimeT> timeout = std::chrono::duration<TimeRepT, TimeT>(-1 ))
76
121
{
77
- // TODO(wjwwood): does not work recursively; can't call spin_node_until_future_complete
78
- // inside a callback executed by an executor.
79
- executor.add_node (node_ptr);
80
- auto retcode = executor.spin_until_future_complete (future, timeout);
81
- executor.remove_node (node_ptr);
82
- return retcode;
122
+ return spin_until_complete (executor, node_ptr, future, timeout);
83
123
}
84
124
85
125
template <typename NodeT = rclcpp::Node, typename FutureT, typename TimeRepT = int64_t ,
86
126
typename TimeT = std::milli>
127
+ [[deprecated(" use spin_node_until_complete(Executor &, std::shared_ptr<NodeT>, const Condition &, DurationT) instead" )]]
87
128
rclcpp::FutureReturnCode
88
129
spin_node_until_future_complete (
89
130
rclcpp::Executor & executor,
90
131
std::shared_ptr<NodeT> node_ptr,
91
132
const FutureT & future,
92
133
std::chrono::duration<TimeRepT, TimeT> timeout = std::chrono::duration<TimeRepT, TimeT>(-1 ))
93
134
{
94
- return rclcpp::executors::spin_node_until_future_complete (
135
+ return rclcpp::executors::spin_node_until_complete (
95
136
executor,
96
137
node_ptr->get_node_base_interface (),
97
138
future,
@@ -100,26 +141,50 @@ spin_node_until_future_complete(
100
141
101
142
} // namespace executors
102
143
144
+ template <typename Condition, typename DurationT = std::chrono::milliseconds>
145
+ rclcpp::FutureReturnCode
146
+ spin_until_complete (
147
+ rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
148
+ const Condition & condition,
149
+ DurationT timeout = DurationT(-1 ))
150
+ {
151
+ rclcpp::executors::SingleThreadedExecutor executor;
152
+ return executors::spin_node_until_complete<Condition>(executor, node_ptr, condition, timeout);
153
+ }
154
+
155
+ template <typename NodeT = rclcpp::Node, typename Condition,
156
+ typename DurationT = std::chrono::milliseconds>
157
+ rclcpp::FutureReturnCode
158
+ spin_until_complete (
159
+ std::shared_ptr<NodeT> node_ptr,
160
+ const Condition & condition,
161
+ DurationT timeout = DurationT(-1 ))
162
+ {
163
+ return rclcpp::spin_until_complete (node_ptr->get_node_base_interface (), condition, timeout);
164
+ }
165
+
103
166
template <typename FutureT, typename TimeRepT = int64_t , typename TimeT = std::milli>
167
+ [[deprecated(" use spin_until_complete(node_interfaces::NodeBaseInterface::SharedPtr, const Condition &, DurationT) instead" )]]
104
168
rclcpp::FutureReturnCode
105
169
spin_until_future_complete (
106
170
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
107
171
const FutureT & future,
108
172
std::chrono::duration<TimeRepT, TimeT> timeout = std::chrono::duration<TimeRepT, TimeT>(-1 ))
109
173
{
110
174
rclcpp::executors::SingleThreadedExecutor executor;
111
- return executors::spin_node_until_future_complete <FutureT>(executor, node_ptr, future, timeout);
175
+ return executors::spin_node_until_complete <FutureT>(executor, node_ptr, future, timeout);
112
176
}
113
177
114
178
template <typename NodeT = rclcpp::Node, typename FutureT, typename TimeRepT = int64_t ,
115
179
typename TimeT = std::milli>
180
+ [[deprecated(" use spin_until_complete(std::shared_ptr<NodeT>, const Condition &, DurationT) instead" )]]
116
181
rclcpp::FutureReturnCode
117
182
spin_until_future_complete (
118
183
std::shared_ptr<NodeT> node_ptr,
119
184
const FutureT & future,
120
185
std::chrono::duration<TimeRepT, TimeT> timeout = std::chrono::duration<TimeRepT, TimeT>(-1 ))
121
186
{
122
- return rclcpp::spin_until_future_complete (node_ptr->get_node_base_interface (), future, timeout);
187
+ return rclcpp::spin_until_complete (node_ptr->get_node_base_interface (), future, timeout);
123
188
}
124
189
125
190
} // namespace rclcpp
0 commit comments