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

Allow robot-specific finishing request and specify parking spots #379

Merged
merged 13 commits into from
Oct 4, 2024

Conversation

xiyuoh
Copy link
Member

@xiyuoh xiyuoh commented Jul 29, 2024

This PR provides a way for users to specify different finishing requests for individual robots. Currently all robots in a fleet follow the fleet-wide finishing request configured. If the finishing request is either park or charge, the robots will head to their assigned charger waypoint to perform their respective ParkRobotIndefinitely or ChargeBattery tasks.

With this PR, users can:

  • Configure different finishing requests for robots in the same fleet, and
  • Configure parking spots that are different from the robot's designated charger.

Relevant issue ticket: open-rmf/rmf_task#115

Signed-off-by: Xiyu Oh <xiyu@openrobotics.org>
Signed-off-by: Xiyu Oh <xiyu@openrobotics.org>
@xiyuoh
Copy link
Member Author

xiyuoh commented Jul 29, 2024

One edge case not resolved is if the fleet-wide finishing request is either park or charge, and the robot's configured finishing request is nothing, the robot's idle behavior will only take effect after completing its first task.

@xiyuoh xiyuoh requested a review from mxgrey July 29, 2024 09:27
@xiyuoh
Copy link
Member Author

xiyuoh commented Jul 31, 2024

The edge case mentioned above is fixed in 337b79f.

Signed-off-by: Xiyu Oh <xiyu@openrobotics.org>
Copy link
Contributor

@mxgrey mxgrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very elegant solution to a long-standing issue within RMF.

I have some points of feedback, mostly just cleaning up some implementation details.

@@ -264,7 +264,8 @@ class EasyFullControl::RobotConfiguration
std::optional<bool> responsive_wait = std::nullopt,
std::optional<double> max_merge_waypoint_distance = 1e-3,
std::optional<double> max_merge_lane_distance = 0.3,
std::optional<double> min_lane_length = 1e-8);
std::optional<double> min_lane_length = 1e-8,
std::optional<rmf_task::ConstRequestFactoryPtr> finishing_request = std::nullopt);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't add a new argument to this constructor without breaking ABI stability, even if we give it a default value.

Unfortunately we'll need to remove this and rely on the set_finishing_request method while parsing the config file.

std::nullopt;
const YAML::Node& finishing_request_yaml =
robot_config_yaml["finishing_request"];
if (finishing_request_yaml)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit concerned about how much parsing logic we're duplicating between here and the fleet-level parsing for finishing requests. If we find a bug or make a change in one, we'll need to remember to update the other, which is an easy thing to forget after months or years from now. I have some suggestions which could help eliminate the duplication:

  • Define one new separate function that parses finishing requests. The signature should be something like:
std::optional<rmf_task::ConstRequestFactoryPtr> parse_finishing_request(
  const YAML::Node& finishing_request_yaml,
  const rmf_traffic::agv::Graph& graph,
  /* ... any other variables needed during parsing ... */
  bool robot_specific,
  bool& error)
  • If robot_specific is true then we allow the new format, i.e. { type: park, parking_spot: 0 }. Otherwise the presence of that format should produce an error.
  • If a parsing error happens, the error argument should be set to true, and we should check that immediately after the function is called so we know to immediately return a nullptr
  • The error messages should take advantage of the YAML::Node::Mark() function (example here) to tell the user precisely where the error happened. Then there is no need for us to explicitly mention the robot or fleet information in the error messages.

Copy link
Member Author

@xiyuoh xiyuoh Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I've implemented this in 6b655d8 but changed bool robot_specific to std::optional<std::string> robot_name to specify which robot's finishing request we are parsing.

// We will need to know the configured parking spot for this
// robot.
const YAML::Node& parking_spot_yaml =
finishing_request_yaml["parking_spot"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nitpick, I think we should call this waypoint_name instead to make the meaning of the value more explicit.

@mxgrey
Copy link
Contributor

mxgrey commented Sep 24, 2024

One last issue I just realized after submitting the previous review:

When users call FleetUpdateHandle::set_task_planner_params the idle_task given there will clobber any robot-specific idle behavior that has been set.

To fix that we should add some kind of flag to RobotContext to keep track of whether it has been assigned a robot-specific idle behavior, and then FleetUpdateHandle::set_task_planner_params should skip over-writing the task manager's idle behavior if that flag is set.

Signed-off-by: Xiyu Oh <xiyu@openrobotics.org>
Signed-off-by: Xiyu Oh <xiyu@openrobotics.org>
@xiyuoh xiyuoh requested a review from mxgrey September 27, 2024 08:19
Signed-off-by: Michael X. Grey <mxgrey@intrinsic.ai>
Signed-off-by: Michael X. Grey <mxgrey@intrinsic.ai>
Signed-off-by: Michael X. Grey <mxgrey@intrinsic.ai>
Copy link
Contributor

@mxgrey mxgrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for iterating on this. I've made two sets of changes to bring this to a state that I think is ready to merge. Take a look over them and if they seem good then go ahead and merge:

  • f61c220: This tweaks the parsing behavior to be stricter in some ways (some of the fallback behaviors that you programmed are now errors that will cause the parsing to fail) but also more consistent (the { type: _, .. } format can be used to express all finishing requests in all situations). Hopefully we never have to manually program a parser ever again after this since we're transitioning to Rust.
  • 92f1f17: The public API functions of RobotUpdateHandle will schedule their actions on the worker to avoid potential data races with other activities that may be happening in the fleet adapter.

@xiyuoh
Copy link
Member Author

xiyuoh commented Oct 4, 2024

@mxgrey The changes look good, thanks for helping to add them in!

@xiyuoh xiyuoh merged commit 6ab83a2 into main Oct 4, 2024
6 checks passed
@xiyuoh xiyuoh deleted the xiyu/robot_idle_task branch October 4, 2024 04:59
xiyuoh added a commit that referenced this pull request Oct 4, 2024
* Allow robot-specific finishing request

Signed-off-by: Xiyu Oh <xiyu@openrobotics.org>

* Add printout for configured finishing request without parking spot

Signed-off-by: Xiyu Oh <xiyu@openrobotics.org>

* Cancel existing waiting behavior if new idle task is nothing

Signed-off-by: Xiyu Oh <xiyu@openrobotics.org>

* Add brackets

Signed-off-by: Xiyu Oh <xiyu@openrobotics.org>

* Refactor based on review comments

Signed-off-by: Xiyu Oh <xiyu@openrobotics.org>

* Cleanup

Signed-off-by: Xiyu Oh <xiyu@openrobotics.org>

* Tweak finishing_request parsing

Signed-off-by: Michael X. Grey <mxgrey@intrinsic.ai>

* Schedule all API activity on the worker

Signed-off-by: Michael X. Grey <mxgrey@intrinsic.ai>

* Small fixes

Signed-off-by: Michael X. Grey <mxgrey@intrinsic.ai>

---------

Signed-off-by: Xiyu Oh <xiyu@openrobotics.org>
Signed-off-by: Michael X. Grey <mxgrey@intrinsic.ai>
Co-authored-by: Michael X. Grey <mxgrey@intrinsic.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants