Skip to content

Commit 2d24c73

Browse files
authored
Makes sure that the reservation system always assigns nearest goal during Emergency Pullover (open-rmf#484)
Signed-off-by: Arjo Chakravarty <arjoc@intrinsic.ai>
1 parent a6cf6c5 commit 2d24c73

File tree

4 files changed

+47
-28
lines changed

4 files changed

+47
-28
lines changed

rmf_fleet_adapter/src/rmf_fleet_adapter/agv/ReservationManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ std::string ReservationManager::get_reserved_location() const
5858
bool ReservationManager::has_ticket() const
5959
{
6060
return _allocation.has_value();
61-
}
61+
}

rmf_fleet_adapter/src/rmf_fleet_adapter/events/EmergencyPullover.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ auto EmergencyPullover::Active::make(
173173
active->_context->_find_and_sort_parking_spots(true);
174174

175175
RCLCPP_INFO(active->_context->node()->get_logger(),
176-
"Creating reservation negotiator");
176+
"Creating reservation negotiator for emergency pullover");
177177
active->_reservation_client = reservation::ReservationNodeNegotiator::make(
178178
active->_context,
179179
potential_waitpoints,
@@ -194,7 +194,8 @@ auto EmergencyPullover::Active::make(
194194

195195
self->_chosen_goal = goal;
196196
self->_find_plan();
197-
}
197+
},
198+
true // Always re-plan to find the nearest spot.
198199
);
199200
}
200201
return active;

rmf_fleet_adapter/src/rmf_fleet_adapter/events/internal_ReservationNodeNegotiator.hpp

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,42 @@
2525
namespace rmf_fleet_adapter {
2626
namespace reservation {
2727

28-
/// This class implements the protocol for negotiating a spot with the "reservation"
29-
/// node. The reservation node maintains a list of spots which are free.
28+
/// This class implements the protocol for negotiating a spot with the
29+
/// "reservation" node. The reservation node maintains a list of spots which
30+
/// are free.
3031
class ReservationNodeNegotiator :
3132
public std::enable_shared_from_this<ReservationNodeNegotiator>
3233
{
3334
public:
35+
//============================================================================
36+
/// Creates a ReservationNegotiator to handle the reservation system protocol
37+
/// \param[in] context the RobotContext with all of the current robot's
38+
/// context.
39+
/// \param[in] goals a list of potential spots.
40+
/// \param[in] same_map Is the goal on the same map
41+
/// \param[in] selected_final_destination_cb A callback which is triggered
42+
/// when the final destination is selected.
43+
/// \param[in] always_recalculate_nearest_goal Always find the nearest goal
3444
static std::shared_ptr<ReservationNodeNegotiator> make(
3545
std::shared_ptr<agv::RobotContext> context,
3646
const std::vector<rmf_traffic::agv::Plan::Goal> goals,
3747
const bool same_map,
3848
const std::function<void(const rmf_traffic::agv::Plan::Goal&)>
3949
selected_final_destination_cb,
40-
const std::function<void(const rmf_traffic::agv::Plan::Goal&)> selected_waitpoint_cb)
50+
const std::function<void(const rmf_traffic::agv::Plan::Goal&)>
51+
selected_waitpoint_cb,
52+
bool always_recalculate_nearest_goal = false)
4153
{
4254
auto negotiator = std::shared_ptr<ReservationNodeNegotiator>(
4355
new ReservationNodeNegotiator(
44-
context, goals, selected_final_destination_cb, selected_waitpoint_cb));
56+
context,
57+
goals,
58+
selected_final_destination_cb,
59+
selected_waitpoint_cb));
4560

4661
negotiator->_reservation_ticket =
47-
context->node()->location_ticket_obs().observe_on(rxcpp::identity_same_worker(
48-
context->worker()))
62+
context->node()->location_ticket_obs().observe_on(
63+
rxcpp::identity_same_worker(context->worker()))
4964
.subscribe([ptr = negotiator->weak_from_this()](
5065
const std::shared_ptr<rmf_reservation_msgs::msg::Ticket>
5166
& msg)
@@ -169,22 +184,24 @@ class ReservationNodeNegotiator :
169184
}
170185
});
171186

172-
173-
for (std::size_t i = 0; i < negotiator->_goals.size(); ++i)
187+
if (!always_recalculate_nearest_goal)
174188
{
175-
if (events::wp_name(*context.get(), negotiator->_goals[i]) == context->_get_reserved_location())
189+
for (std::size_t i = 0; i < negotiator->_goals.size(); ++i)
176190
{
177-
RCLCPP_INFO(context->node()->get_logger(),
178-
"%s: Already at goal no need to engage reservation system\n",
179-
context->requester_id().c_str());
180-
context->worker().schedule([
181-
cb = negotiator->_selected_final_destination_cb,
182-
wp = negotiator->_goals[i]
183-
](const auto&)
184-
{
185-
cb(wp);
186-
});
187-
return negotiator;
191+
if (events::wp_name(*context.get(), negotiator->_goals[i]) == context->_get_reserved_location())
192+
{
193+
RCLCPP_INFO(context->node()->get_logger(),
194+
"%s: Already have a goal no need to engage reservation system\n",
195+
context->requester_id().c_str());
196+
context->worker().schedule([
197+
cb = negotiator->_selected_final_destination_cb,
198+
wp = negotiator->_goals[i]
199+
](const auto&)
200+
{
201+
cb(wp);
202+
});
203+
return negotiator;
204+
}
188205
}
189206
}
190207
RCLCPP_INFO(negotiator->_context->node()->get_logger(),
@@ -205,13 +222,14 @@ class ReservationNodeNegotiator :
205222
}
206223

207224
private:
208-
225+
//============================================================================
209226
ReservationNodeNegotiator(
210227
std::shared_ptr<agv::RobotContext> context,
211228
const std::vector<rmf_traffic::agv::Plan::Goal> goals,
212229
const std::function<void(const rmf_traffic::agv::Plan::Goal&)>
213-
selected_final_destination_cb,
214-
const std::function<void(const rmf_traffic::agv::Plan::Goal&)> selected_waitpoint_cb)
230+
selected_final_destination_cb,
231+
const std::function<void(const rmf_traffic::agv::Plan::Goal&)>
232+
selected_waitpoint_cb)
215233
{
216234
_context = context;
217235
_goals = goals;
@@ -220,6 +238,7 @@ class ReservationNodeNegotiator :
220238
_reservation_id = _context->last_reservation_request_id();
221239
}
222240

241+
//============================================================================
223242
enum class ReservationState
224243
{
225244
Pending=0,
@@ -228,7 +247,7 @@ class ReservationNodeNegotiator :
228247
ReceivedResponseProceedImmediate=3
229248
};
230249

231-
250+
//============================================================================
232251
void make_request(bool only_same_map)
233252
{
234253
auto current_location = _context->location();

rmf_reservation_node/src/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <rmf_reservation_msgs/msg/claim_request.hpp>
2828
#include <rmf_fleet_adapter/StandardNames.hpp>
2929

30-
#include <iostream>
3130
#include <sstream>
3231
#include <unordered_map>
3332
#include <vector>

0 commit comments

Comments
 (0)