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