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

Refactor out velocity limit enforcement with test #540

Merged
merged 2 commits into from
Jul 29, 2021

Conversation

tylerjw
Copy link
Member

@tylerjw tylerjw commented Jul 6, 2021

Description

While working on my parameters refactor I pulled this function (and it's test) out of the code that depends on ros so it could be tested by unit tests.

Checklist

  • Required by CI: Code is auto formatted using clang-format
  • Create tests, which fail without this PR reference
  • While waiting for someone to review your request, please help review another open pull request to support the maintainers

@codecov
Copy link

codecov bot commented Jul 6, 2021

Codecov Report

Merging #540 (2ca21cc) into main (848a936) will increase coverage by 0.06%.
The diff coverage is 93.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #540      +/-   ##
==========================================
+ Coverage   46.73%   46.78%   +0.06%     
==========================================
  Files         184      185       +1     
  Lines       19686    19689       +3     
==========================================
+ Hits         9198     9210      +12     
+ Misses      10488    10479       -9     
Impacted Files Coverage Δ
moveit_ros/moveit_servo/src/servo_calcs.cpp 0.00% <0.00%> (ø)
moveit_ros/moveit_servo/src/enforce_limits.cpp 100.00% <100.00%> (ø)
...dl_kinematics_plugin/src/kdl_kinematics_plugin.cpp 74.72% <0.00%> (-1.13%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 848a936...2ca21cc. Read the comment docs.

@AndyZe
Copy link
Member

AndyZe commented Jul 6, 2021

I can see that this gets rid of the friend class, so that makes testing a little simpler. I don't think it's a huge improvement but I guess I'm OK with it.

@@ -154,9 +154,6 @@ class ServoCalcs
void suddenHalt(trajectory_msgs::msg::JointTrajectory& joint_trajectory) const;
void suddenHalt(sensor_msgs::msg::JointState& joint_state) const;

/** \brief Scale the delta theta to match joint velocity/acceleration limits */
void enforceVelLimits(Eigen::ArrayXd& delta_theta);

/** \brief Avoid overshooting joint limits */
bool enforcePositionLimits(sensor_msgs::msg::JointState& joint_state) const;
Copy link
Member

Choose a reason for hiding this comment

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

Seems like this should be moved to the new enforce_limits.cpp too

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree. This was more about converting the test to a unit test instead of a ros test (as those take forever and are flaky on foxy).

Long term I think it would be nice to separate all the math/logic from the ros code so it could be easily tested.

Copy link
Contributor

@AdamPettinger AdamPettinger left a comment

Choose a reason for hiding this comment

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

I like this, and agree we should move as much as possible of the logic to more testable places. Probably outside the scope of this PR, but good candidates are probably:

  • calculateWorstCaseStopTime
  • checkValidCommand
  • scaleCartesianCommand
  • scaleJointCommand
  • Maybe velocityScalingFactorForSingularity
  • composeJointTrajMessage
  • insertRedundantPointsIntoTrajectory
  • removeDimension
  • removeDriftDimensions
  • enforceControlDimensions

I think a lot of unit tests for those are already written, but use a friend class. So transferring the tests should not be too bad

Eigen::ArrayXd velocity = delta_theta / publish_period;

// Get the velocity scaling factor
double velocity_scaling_factor = getVelocityScalingFactor(joint_model_group, velocity);
Copy link
Contributor

Choose a reason for hiding this comment

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

I like splitting this out into another function as well

moveit_ros/moveit_servo/test/enforce_limits_tests.cpp Outdated Show resolved Hide resolved
@tylerjw tylerjw force-pushed the functional_velocity_limits branch from 4bc17b6 to 2ca21cc Compare July 28, 2021 23:52
@tylerjw
Copy link
Member Author

tylerjw commented Jul 28, 2021

@AndyZe I rebased this on main. Would you mind reviewing this again and let me know if you like this change.

Copy link
Contributor

@AdamPettinger AdamPettinger left a comment

Choose a reason for hiding this comment

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

+1 getting rid of the ros test in favor of unit test for internal joint limit checking

@AndyZe AndyZe merged commit f2abc40 into moveit:main Jul 29, 2021
@tylerjw tylerjw deleted the functional_velocity_limits branch July 29, 2021 15:49
christianlandgraf pushed a commit to christianlandgraf/moveit2 that referenced this pull request Aug 12, 2021
* Refactor out velocity limit enforcement with test

* Update moveit_ros/moveit_servo/test/enforce_limits_tests.cpp

Co-authored-by: AdamPettinger <adam.pettinger@utexas.edu>

Co-authored-by: AdamPettinger <adam.pettinger@utexas.edu>
tylerjw added a commit to tylerjw/moveit2 that referenced this pull request Aug 27, 2021
* Refactor out velocity limit enforcement with test

* Update moveit_ros/moveit_servo/test/enforce_limits_tests.cpp

Co-authored-by: AdamPettinger <adam.pettinger@utexas.edu>

Co-authored-by: AdamPettinger <adam.pettinger@utexas.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants