@@ -94,7 +94,9 @@ class RosServiceNode : public BT::ActionNodeBase
94
94
static PortsList providedBasicPorts (PortsList addition)
95
95
{
96
96
PortsList basic = {
97
- InputPort<std::string>(" service_name" , " __default__placeholder__" , " Service name" )
97
+ InputPort<std::string>(" service_name" , " __default__placeholder__" , " Service name" ),
98
+ InputPort<int >(" server_timeout" , " Service server goal timeout (mSec)" ),
99
+ InputPort<int >(" wait_for_server_timeout" , " Service server discovery timeout (mSec)" )
98
100
};
99
101
basic.insert (addition.begin (), addition.end ());
100
102
return basic;
@@ -133,7 +135,7 @@ class RosServiceNode : public BT::ActionNodeBase
133
135
* It must return either SUCCESS or FAILURE.
134
136
*/
135
137
virtual BT::NodeStatus onFailure (ServiceNodeErrorCode /* error*/ )
136
- {
138
+ {
137
139
return NodeStatus::FAILURE;
138
140
}
139
141
@@ -142,8 +144,8 @@ class RosServiceNode : public BT::ActionNodeBase
142
144
std::shared_ptr<rclcpp::Node> node_;
143
145
std::string prev_service_name_;
144
146
bool service_name_may_change_ = false ;
145
- const std::chrono::milliseconds service_timeout_;
146
- const std::chrono::milliseconds wait_for_service_timeout_;
147
+ std::chrono::milliseconds service_timeout_;
148
+ std::chrono::milliseconds wait_for_service_timeout_;
147
149
148
150
private:
149
151
@@ -174,8 +176,37 @@ template<class T> inline
174
176
service_timeout_(params.server_timeout),
175
177
wait_for_service_timeout_(params.wait_for_server_timeout)
176
178
{
179
+ // update service_timeout_ if set throuh port and greater than 0
180
+ auto portIt = config ().input_ports .find (" server_timeout" );
181
+ if (portIt != config ().input_ports .end ())
182
+ {
183
+ int timeout = 0 ;
184
+ getInput (" server_timeout" , timeout);
185
+ if (timeout > 0 ) {
186
+ service_timeout_ = std::chrono::milliseconds (timeout);
187
+ }
188
+ else {
189
+ RCLCPP_WARN (node_->get_logger (), " %s: Port `server_timeout` is not greater than zero. "
190
+ " Defaulting to %d mSec." , name ().c_str (), static_cast <int >(service_timeout_.count ()));
191
+ }
192
+ }
193
+ // update wait_for_service_timeout_ if set throuh port and greater than 0
194
+ portIt = config ().input_ports .find (" wait_for_server_timeout" );
195
+ if (portIt != config ().input_ports .end ())
196
+ {
197
+ int timeout = 0 ;
198
+ getInput (" wait_for_server_timeout" , timeout);
199
+ if (timeout > 0 ) {
200
+ wait_for_service_timeout_ = std::chrono::milliseconds (timeout);
201
+ }
202
+ else {
203
+ RCLCPP_WARN (node_->get_logger (), " %s: Port `wait_for_server_timeout` is not greater than zero. "
204
+ " Defaulting to %d mSec." , name ().c_str (), static_cast <int >(wait_for_service_timeout_.count ()));
205
+ }
206
+ }
207
+
177
208
// check port remapping
178
- auto portIt = config ().input_ports .find (" service_name" );
209
+ portIt = config ().input_ports .find (" service_name" );
179
210
if (portIt != config ().input_ports .end ())
180
211
{
181
212
const std::string& bb_service_name = portIt->second ;
0 commit comments