Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reached API to read-only fleet adapter #387

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions rmf_fleet_adapter/src/read_only/FleetAdapterNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ void FleetAdapterNode::push_route(

it->second->cumulative_delay = std::chrono::seconds(0);
it->second->route = make_route(state, _traits, it->second->sitting);
// Set checkpoints for this route
std::set<uint64_t> checkpoints;
uint64_t checkpoint_id = 0;
for (const auto& wp : it->second->route->trajectory())
{
checkpoints.insert(checkpoint_id);
checkpoint_id++;
}
it->second->route->checkpoints(checkpoints);
it->second->schedule->push_routes({*it->second->route});
}

Expand All @@ -234,6 +243,40 @@ void FleetAdapterNode::update_robot(
const RobotState& state,
const ScheduleEntries::iterator& it)
{
if (it->second->route.has_value())
{
auto& participant = it->second->schedule->participant();
uint64_t route_id = participant.itinerary().size() - 1;
uint64_t last_checkpoint_reached = participant.reached()[route_id];

uint64_t checkpoint_id = 0;
for (const auto& wp : it->second->route.value().trajectory())
{
if (checkpoint_id <= last_checkpoint_reached)
{
checkpoint_id++;
continue;
}

Eigen::Vector2d current_location =
Eigen::Vector2d(state.location.x, state.location.y);
Eigen::Vector2d checkpoint_pose =
Eigen::Vector2d(wp.position()[0], wp.position()[1]);
Eigen::Vector2d diff = current_location - checkpoint_pose;
// TODO(@xiyuoh) Make this merge_waypoint_distance configurable
if (diff.norm() < 0.3)
{
// The robot is close enough to the checkpoint, mark as reached.
participant.reached(
participant.current_plan_id(), route_id, checkpoint_id);
}
else
break;

checkpoint_id++;
}
}

if (handle_delay(state, it))
return;

Expand Down
Loading