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 servo solver #2673

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Add servo solver #2673

wants to merge 5 commits into from

Conversation

sjahr
Copy link
Contributor

@sjahr sjahr commented Jan 31, 2024

Description

Ports over the servo-based local planner from the UR welding demo

Checklist

  • Required by CI: Code is auto formatted using clang-format
  • Extend the tutorials / documentation reference
  • Document API changes relevant to the user in the MIGRATION.md notes
  • Create tests, which fail without this PR reference
  • Include a screenshot if changing a GUI
  • While waiting for someone to review your request, please help review another open pull request to support the maintainers

Copy link
Contributor Author

@sjahr sjahr left a comment

Choose a reason for hiding this comment

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

Porting over @pac48's review from sjahr#16

Overall looks good! I added a few comments in the main local planner solve function on how to possibly use servo's command queue more effectively. One other thing, it may be too much work to set up, but this draft PR to ros2_control shows how to add data_tamer to log the values sent to the hardware interface ros-controls/ros2_control#1255. If the command queue is setup correctly, you should see very smooth motion.

while (!trajectory_msg)
{
// Calculate next servo command
moveit_servo::KinematicState joint_state = servo_->getNextJointState(current_state, target_twist);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This point may cause issues if not handled with caution. Servo has a parameter called publish_period which is the time difference used for numerical integration. So if you ask servo to move at a velocity of 1 m/s and publish_period was .1 sec, then servo will return a new position that correspondence to a .1 m offset from the current position. So you should consider setting a faction of local trajectory length. For example, if you are supposed to arrive at your next point in .3 sec, then the update period should be .3/n, where n is the number of points you want in the command queue. I would recommend n=3.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am setting the (hopefully) correct publish_period in the initialize() function (see diff). Do you mind validating this?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is correct as long as this loop always gets called three times. I think you should replace the whole loop with a for loop of length 3 to make sure this is the case. Then check at the end to make sure the message is not empty.

Copy link

codecov bot commented Jan 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 50.73%. Comparing base (d962501) to head (881e55c).
Report is 30 commits behind head on main.

❗ Current head 881e55c differs from pull request most recent head 975b94a. Consider uploading reports for the commit 975b94a to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2673      +/-   ##
==========================================
- Coverage   50.74%   50.73%   -0.00%     
==========================================
  Files         392      392              
  Lines       32553    32553              
==========================================
- Hits        16517    16514       -3     
- Misses      16036    16039       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -36,6 +36,7 @@
#include <moveit/local_planner/feedback_types.h>
#include <moveit/planning_scene/planning_scene.h>
#include <moveit/robot_state/conversions.h>
#include <forward_trajectory_parameters.hpp>
Copy link
Member

Choose a reason for hiding this comment

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

Is it time to do a repo-wide refactoring for .hpp file type extensions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes!

bool ServoSolver::reset()
{
RCLCPP_INFO(getLogger(), "Reset Servo Solver");
joint_cmd_rolling_window_.clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this get called on every iteration of of local planning or is it once per global plan?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only once per global plan. Would it make sense to reset the rolling window when the reference pose changes?

Copy link
Contributor

Choose a reason for hiding this comment

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

That is interesting. I thought it may have been called on each iteration. In that case, won't the joint_cmd_rolling_window_ queue grow indefinitely as solve continues to be called? In that case, what I would do is remove old commands from joint_cmd_rolling_window_ in the solve method. Then I think you can set the timestep of servo queal to the time step of the local planner.

Copy link
Contributor

@pac48 pac48 left a comment

Choose a reason for hiding this comment

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

@sjahr I added a few more comments

Copy link

mergify bot commented Feb 13, 2024

This pull request is in conflict. Could you fix it @sjahr?

Copy link

github-actions bot commented Apr 1, 2024

This PR is stale because it has been open for 45 days with no activity. Please tag a maintainer for help on completing this PR, or close it if you think it has become obsolete.

@github-actions github-actions bot added stale Inactive issues and PRs are marked as stale and may be closed automatically. and removed stale Inactive issues and PRs are marked as stale and may be closed automatically. labels Apr 1, 2024
Copy link

This PR is stale because it has been open for 45 days with no activity. Please tag a maintainer for help on completing this PR, or close it if you think it has become obsolete.

@github-actions github-actions bot added the stale Inactive issues and PRs are marked as stale and may be closed automatically. label May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Inactive issues and PRs are marked as stale and may be closed automatically.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants