@@ -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,31 @@ 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 &,"
115
+ " node_interfaces::NodeBaseInterface::SharedPtr,"
116
+ " const Condition &, DurationT) instead" )]]
70
117
rclcpp::FutureReturnCode
71
118
spin_node_until_future_complete (
72
119
rclcpp::Executor & executor,
73
120
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
74
121
const FutureT & future,
75
122
std::chrono::duration<TimeRepT, TimeT> timeout = std::chrono::duration<TimeRepT, TimeT>(-1 ))
76
123
{
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;
124
+ return spin_until_complete (executor, node_ptr, future, timeout);
83
125
}
84
126
85
127
template <typename NodeT = rclcpp::Node, typename FutureT, typename TimeRepT = int64_t ,
86
128
typename TimeT = std::milli>
129
+ [[deprecated(" use spin_node_until_complete(Executor &, std::shared_ptr<NodeT>,"
130
+ " const Condition &, DurationT) instead" )]]
87
131
rclcpp::FutureReturnCode
88
132
spin_node_until_future_complete (
89
133
rclcpp::Executor & executor,
90
134
std::shared_ptr<NodeT> node_ptr,
91
135
const FutureT & future,
92
136
std::chrono::duration<TimeRepT, TimeT> timeout = std::chrono::duration<TimeRepT, TimeT>(-1 ))
93
137
{
94
- return rclcpp::executors::spin_node_until_future_complete (
138
+ return rclcpp::executors::spin_node_until_complete (
95
139
executor,
96
140
node_ptr->get_node_base_interface (),
97
141
future,
@@ -100,26 +144,52 @@ spin_node_until_future_complete(
100
144
101
145
} // namespace executors
102
146
147
+ template <typename Condition, typename DurationT = std::chrono::milliseconds>
148
+ rclcpp::FutureReturnCode
149
+ spin_until_complete (
150
+ rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
151
+ const Condition & condition,
152
+ DurationT timeout = DurationT(-1 ))
153
+ {
154
+ rclcpp::executors::SingleThreadedExecutor executor;
155
+ return executors::spin_node_until_complete<Condition>(executor, node_ptr, condition, timeout);
156
+ }
157
+
158
+ template <typename NodeT = rclcpp::Node, typename Condition,
159
+ typename DurationT = std::chrono::milliseconds>
160
+ rclcpp::FutureReturnCode
161
+ spin_until_complete (
162
+ std::shared_ptr<NodeT> node_ptr,
163
+ const Condition & condition,
164
+ DurationT timeout = DurationT(-1 ))
165
+ {
166
+ return rclcpp::spin_until_complete (node_ptr->get_node_base_interface (), condition, timeout);
167
+ }
168
+
103
169
template <typename FutureT, typename TimeRepT = int64_t , typename TimeT = std::milli>
170
+ [[deprecated(" use spin_until_complete(node_interfaces::NodeBaseInterface::SharedPtr,"
171
+ " const Condition &,DurationT) instead" )]]
104
172
rclcpp::FutureReturnCode
105
173
spin_until_future_complete (
106
174
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_ptr,
107
175
const FutureT & future,
108
176
std::chrono::duration<TimeRepT, TimeT> timeout = std::chrono::duration<TimeRepT, TimeT>(-1 ))
109
177
{
110
178
rclcpp::executors::SingleThreadedExecutor executor;
111
- return executors::spin_node_until_future_complete <FutureT>(executor, node_ptr, future, timeout);
179
+ return executors::spin_node_until_complete <FutureT>(executor, node_ptr, future, timeout);
112
180
}
113
181
114
182
template <typename NodeT = rclcpp::Node, typename FutureT, typename TimeRepT = int64_t ,
115
183
typename TimeT = std::milli>
184
+ [[deprecated(" use spin_until_complete(std::shared_ptr<NodeT>, const Condition &,"
185
+ " DurationT) instead" )]]
116
186
rclcpp::FutureReturnCode
117
187
spin_until_future_complete (
118
188
std::shared_ptr<NodeT> node_ptr,
119
189
const FutureT & future,
120
190
std::chrono::duration<TimeRepT, TimeT> timeout = std::chrono::duration<TimeRepT, TimeT>(-1 ))
121
191
{
122
- return rclcpp::spin_until_future_complete (node_ptr->get_node_base_interface (), future, timeout);
192
+ return rclcpp::spin_until_complete (node_ptr->get_node_base_interface (), future, timeout);
123
193
}
124
194
125
195
} // namespace rclcpp
0 commit comments