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 copy() and deepCopy() methods to RobotTrajectory class. #1760

Merged
merged 7 commits into from
Dec 19, 2019

Conversation

shivaang12
Copy link
Contributor

@shivaang12 shivaang12 commented Nov 21, 2019

Description

This PR points to issue #1660. I have deprecated the "normal" copy constructors and added two new methods, RobotTrajectory::copy() and RobotTrajectory::deepCopy(). Also documented these methods.

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

@welcome
Copy link

welcome bot commented Nov 21, 2019

Thanks for helping in improving MoveIt and open source robotics!

Copy link
Member

@davetcoleman davetcoleman left a comment

Choose a reason for hiding this comment

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

Would a unit test be relevant here?


void RobotTrajectory::deepCopy(const RobotTrajectory& robot_traj)
{
this->robot_model_ = robot_traj.robot_model_;
Copy link
Member

Choose a reason for hiding this comment

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

Is this really a deep copy of the RobotModel?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review! No, this isn't a deep copy. But I observer that constructor is receiving a shared ptr so I thought I should assigned it to a same shared pointer. But now I get the picture, value should be same not the memory! Sorry, I am not much familiar with this part of the package.

Copy link
Contributor

Choose a reason for hiding this comment

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

i believe we actually want to keep the same RobotModel in the copied trajectory.

the "deep" is supposed to imply that RobotStates are copied, not the whole underlying moveit class structure.

other proposals for this name are welcome.

Copy link
Member

Choose a reason for hiding this comment

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

i believe we actually want to keep the same RobotModel in the copied trajectory.

I agree

the "deep" is supposed to imply that RobotStates are copied, not the whole underlying moveit class structure.

other proposals for this name are welcome.

I think "deep" could be a bit misleading. I would prefer something more explicit, maybe copyWithRobotStates().

Copy link
Contributor

@mlautman mlautman Dec 18, 2019

Choose a reason for hiding this comment

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

Perhaps RobotTrajectory::copy(const RobotTrajectory& other, bool copy_robot_states = false) would be more explicit. This is the approach used in robot_state/conversions.h for copy_attached_bodies.

moveit_core/robot_trajectory/src/robot_trajectory.cpp Outdated Show resolved Hide resolved
@shivaang12
Copy link
Contributor Author

shivaang12 commented Nov 21, 2019

@davetcoleman I noticed there wasn't any unit test dir for the robot_trajectory package. Is it okay if I create it?


void RobotTrajectory::deepCopy(const RobotTrajectory& robot_traj)
{
this->robot_model_ = robot_traj.robot_model_;
Copy link
Contributor

Choose a reason for hiding this comment

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

i believe we actually want to keep the same RobotModel in the copied trajectory.

the "deep" is supposed to imply that RobotStates are copied, not the whole underlying moveit class structure.

other proposals for this name are welcome.

@rhaschke
Copy link
Contributor

Sorry for the late comment, but I think we could just implement the copy constructor as a deepcopy operation on the waypoints. Is there any use case for a shallow copy, i.e. keeping the waypoints but modifying the durations only? @v4hn: What do you think?

@v4hn
Copy link
Contributor

v4hn commented Nov 21, 2019 via email

@rhaschke
Copy link
Contributor

This is the usual "should we change semantics without changing interfaces" question.

I understand this argument in general, but it is rather unlikely in this case that somebody made use of this. In my point of view, it's a simple bug fix to return a deep copy of the waypoints by the copy constructor.

Either way I would like to keep the proposed copy methods around.

IMHO, this just clutters the API in this case.

@v4hn
Copy link
Contributor

v4hn commented Nov 21, 2019 via email

@davetcoleman
Copy link
Member

I noticed there wasn't any unit test dir for the robot_trajectory package. Is it okay if I create it?

Its always ok to add more tests! :-)

We'll need a third opinion then, as I do not agree with you (nor do I strongly disagree though).

I lean towards @rhaschke 's thought that its a simple bug fix that makes the API more correct, and that should not be backported to Melodic but should be in MIGRATION.md

But I also want to hear @henningkayser 's opinion

@shivaang12
Copy link
Contributor Author

I am curious to know if we have a decision here?

@henningkayser
Copy link
Member

IMHO, this just clutters the API in this case.

Can't we just change the default copy constructor to shallow copy (here copy()) and just provide one alternative for specifically copying the robot states? I think it wouldn't clutter the API if the added functions don't appear redundant and a single added copy function doesn't seem too much to me.

@v4hn
Copy link
Contributor

v4hn commented Nov 25, 2019 via email

@henningkayser
Copy link
Member

henningkayser commented Nov 26, 2019

Can't we just change the default copy constructor to shallow copy (here copy()) and just provide one alternative for specifically copying the robot states?
If I understand your comment right, it's the exact opposite of what Robert and Dave proposed. :-)

Well, you asked for my opinion ;)

They argue copy() is not needed at all (I'm unsure about that)

I think shallow copy is probably the most needed of them all.
If I copy a trajectory I do this in order to modify the waypoint sequence, i.e. by adding or removing robot states. Deep copy is only needed if the actual waypoints are modified. Running different time parametrization algorithms (or similar processing methods) is the only valid use case I see here. In this case the semantics should be clear that you need a deep copy, but I wouldn't expect it as a default.

and copyWithRobotStates should be the semantics of the copy constructor.

This is arguable, I would not expect that. It's fine if properly documented.

@rhaschke
Copy link
Contributor

I think shallow copy is probably the most needed of them all.
If I copy a trajectory I do this in order to modify the waypoint sequence, i.e. by adding or removing robot states.

Good point. Adding or removing states doesn't require a deep copy.
So, we keep the shallow copy behavior in the (default) copy constructor and we add a new deepCopy() method to achieve deep copy. Naming it copyWithRobotStates is somewhat too verbose in my opinion.

@v4hn
Copy link
Contributor

v4hn commented Dec 1, 2019

Good point. Adding or removing states doesn't require a deep copy.
So, we keep the shallow copy behavior in the (default) copy constructor and we add a new deepCopy() method to achieve deep copy. Naming it copyWithRobotStates is somewhat too verbose in my opinion.

The problem with this solution is that users will probably still make the same silly mistake and perform a shallow copy, using the copy constructor - I did so two years ago and a colleague of mine did some months ago.
I believe nobody will read through the API first to discover the deepCopy method and infer that copy construction does something different.
This is the original pitfall I wanted to remove from the API with this patch...

@shivaang12
Copy link
Contributor Author

I have revived the copy constructor which calls method copy(). Let me know if everyone is fine with it.

@shivaang12 shivaang12 requested a review from v4hn December 4, 2019 16:43
- Assign the deprecated attribute to copy constructor which forwards the call to the member method called copy().
@codecov-io
Copy link

codecov-io commented Dec 16, 2019

Codecov Report

Merging #1760 into master will increase coverage by 0.07%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1760      +/-   ##
==========================================
+ Coverage   48.36%   48.44%   +0.07%     
==========================================
  Files         297      297              
  Lines       23261    23278      +17     
==========================================
+ Hits        11250    11276      +26     
+ Misses      12011    12002       -9
Impacted Files Coverage Δ
...include/moveit/robot_trajectory/robot_trajectory.h 95.65% <ø> (ø) ⬆️
...eit_core/robot_trajectory/src/robot_trajectory.cpp 41.81% <100%> (+3.75%) ⬆️
...e/collision_detection_fcl/src/collision_common.cpp 73.53% <0%> (+0.3%) ⬆️
...bot_state/include/moveit/robot_state/robot_state.h 90.9% <0%> (+0.69%) ⬆️
...dl_kinematics_plugin/src/kdl_kinematics_plugin.cpp 78.73% <0%> (+1.35%) ⬆️

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 76c16e6...0241d77. Read the comment docs.

Copy link
Contributor

@mlautman mlautman left a comment

Choose a reason for hiding this comment

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

See proposed changes in #1813

- keep assigmentment operator (performing a shallow copy)
- add a deepcopy flag to the copy constructor
@rhaschke
Copy link
Contributor

Additionally to @mlautman's fixups I restored the assignment operator (performing a shallow copy),
and implemented the copy operation(s) as a copy constructor with an additional deepcopy parameter that is false by default, thus maintaining the old behavior.

@rhaschke rhaschke merged commit 01ff035 into moveit:master Dec 19, 2019
@welcome
Copy link

welcome bot commented Dec 19, 2019

Congrats on getting your first MoveIt pull request merged and improving open source robotics!

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.

None yet

7 participants