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

Jog cpp api fixes #1911

Merged
merged 6 commits into from
Feb 28, 2020
Merged

Jog cpp api fixes #1911

merged 6 commits into from
Feb 28, 2020

Conversation

AndyZe
Copy link
Member

@AndyZe AndyZe commented Feb 21, 2020

This cleans up a few things in jog_arm:

  • Renames JogCppApi class to JogCppInterface to match the filename

  • Fix a crash when the dimensions of the Jacobian changed

  • Doxygenize some comments

  • Make the inheritance of JogInterfaceBase public. I wanted this so I could call the functions from external C++ code, like this: jog_interface_ptr_->changeDriftDimensions(...)

@codecov-io
Copy link

Codecov Report

Merging #1911 into master will increase coverage by 0.01%.
The diff coverage is 60%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1911      +/-   ##
=========================================
+ Coverage   50.29%   50.3%   +0.01%     
=========================================
  Files         313     313              
  Lines       24652   24644       -8     
=========================================
- Hits        12398   12397       -1     
+ Misses      12254   12247       -7
Impacted Files Coverage Δ
.../moveit_jog_arm/include/moveit_jog_arm/jog_calcs.h 100% <ø> (ø) ⬆️
...og_arm/include/moveit_jog_arm/jog_interface_base.h 100% <ø> (ø) ⬆️
...erimental/moveit_jog_arm/src/jog_cpp_interface.cpp 12.04% <37.5%> (ø) ⬆️
...veit_experimental/moveit_jog_arm/src/jog_calcs.cpp 72.12% <85.71%> (+1.61%) ⬆️

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 0abd095...5b1e18a. Read the comment docs.

@AndyZe AndyZe requested a review from mlautman February 24, 2020 14:15
@@ -751,17 +750,19 @@ bool JogCalcs::addJointIncrements(sensor_msgs::JointState& output, const Eigen::

void JogCalcs::removeDimension(Eigen::MatrixXd& jacobian, Eigen::VectorXd& delta_x, unsigned int row_to_remove)
{
unsigned int num_rows = jacobian.rows() - 1;
unsigned int num_cols = jacobian.cols();
/*
Copy link
Member

Choose a reason for hiding this comment

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

Why did you remove this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, it was commented for debugging. Will restore.

@@ -500,8 +500,7 @@ double JogCalcs::decelerateForSingularity(const Eigen::VectorXd& commanded_veloc
new_theta += pseudo_inverse_ * delta_x;
kinematic_state_->setJointGroupPositions(joint_model_group_, new_theta);

jacobian_ = kinematic_state_->getJacobian(joint_model_group_);
Eigen::JacobiSVD<Eigen::MatrixXd> new_svd = Eigen::JacobiSVD<Eigen::MatrixXd>(jacobian_);
Eigen::JacobiSVD<Eigen::MatrixXd> new_svd = Eigen::JacobiSVD<Eigen::MatrixXd>(jacobian);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Eigen::JacobiSVD<Eigen::MatrixXd> new_svd = Eigen::JacobiSVD<Eigen::MatrixXd>(jacobian);
Eigen::JacobiSVD<Eigen::MatrixXd> new_svd(jacobian);

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Fix dim mismatch in decelerateForSingularity
@@ -39,13 +39,13 @@

#include "moveit_jog_arm/jog_cpp_interface.h"

// TODO(davetcoleman): rename JogCppApi to JogCppInterface to match file name
// TODO(davetcoleman): rename JogCppInterface to JogCppInterface to match file name
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this comment can be removed now.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -154,8 +154,8 @@ class JogCalcs

JogArmParameters parameters_;

// For jacobian calculations
Eigen::MatrixXd jacobian_, pseudo_inverse_, matrix_s_;
// Preallocate for jacobian calculations
Copy link
Contributor

Choose a reason for hiding this comment

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

I would reword comments since the lines below don't really pre-allocate memory but rather cache results that are calculated once(?) Correct me though if I have misunderstood the way Eigen allocates memory for dynamic matrices.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like pre-allocating memory by creating member variables unless there constructor is non-trivial (eg a RobotState variable). It seems like poor design because you never know how they may be used elsewhere and there is no reason why their values should be preserved. Seems like a use case for a static variable instead..

Copy link
Member Author

@AndyZe AndyZe Feb 24, 2020

Choose a reason for hiding this comment

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

These variables get updated frequently in a while loop (like, 100 times/second or so) so performance kind of matters. I guess I'm not clear how static variables would be better, but I want to know

I'll make them all local variables until I hear back

edit: Oh, I read up on what static does to a local variable (stays in scope until exit). OK, I'll make them static local variables

@@ -474,23 +474,24 @@ bool JogCalcs::applyVelocityScaling(const JogArmShared& shared_variables, std::m

// Possibly calculate a velocity scaling factor, due to proximity of singularity and direction of motion
double JogCalcs::decelerateForSingularity(const Eigen::VectorXd& commanded_velocity,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this function be renamed? It calculates a velocity scaling factor but it sounds like it commands the manipulator to decelerate when close to singularity. Maybe velocityScalingFactorForSingularity or something like that.

Copy link
Member Author

Choose a reason for hiding this comment

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

good idea, done

@@ -154,8 +154,8 @@ class JogCalcs

JogArmParameters parameters_;

// For jacobian calculations
Eigen::MatrixXd jacobian_, pseudo_inverse_, matrix_s_;
// Preallocate for jacobian calculations
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like pre-allocating memory by creating member variables unless there constructor is non-trivial (eg a RobotState variable). It seems like poor design because you never know how they may be used elsewhere and there is no reason why their values should be preserved. Seems like a use case for a static variable instead..

* See cpp_interface_example.cpp
*/
class JogCppApi : protected JogInterfaceBase
class JogCppInterface : public JogInterfaceBase
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is in moveit_experimental in the master branch, this is okay but in general, it is really bad practice to change public interfaces without deprecating the old one.

@henningkayser henningkayser merged commit 6eaa75d into moveit:master Feb 28, 2020
@tylerjw tylerjw mentioned this pull request May 8, 2020
20 tasks
tylerjw pushed a commit to PickNikRobotics/moveit that referenced this pull request May 12, 2020
* Rename JogCppApi->JogCppInterface to match filename
* Use public inheritance of JogInterfaceBase
* Fix crash due to different Jacobian dimensions
* Clang format, update unit test
* Fix dim mismatch in decelerateForSingularity
* Revert 'static' for several variables
tylerjw pushed a commit to PickNikRobotics/moveit that referenced this pull request May 12, 2020
* Rename JogCppApi->JogCppInterface to match filename
* Use public inheritance of JogInterfaceBase
* Fix crash due to different Jacobian dimensions
* Clang format, update unit test
* Fix dim mismatch in decelerateForSingularity
* Revert 'static' for several variables
tylerjw pushed a commit to PickNikRobotics/moveit that referenced this pull request May 20, 2020
* Rename JogCppApi->JogCppInterface to match filename
* Use public inheritance of JogInterfaceBase
* Fix crash due to different Jacobian dimensions
* Clang format, update unit test
* Fix dim mismatch in decelerateForSingularity
* Revert 'static' for several variables
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.

5 participants