-
Notifications
You must be signed in to change notification settings - Fork 42
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
Added SNS Acceleration IK Solver Interface with UnitTest #102
base: indigo-devel
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ | |
namespace sns_ik { | ||
|
||
|
||
class SnsAccIkBase : SnsIkBase{ | ||
class SnsAccIkBase : public SnsIkBase{ | ||
|
||
public: | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/*! \file sns_acceleration_ik.hpp | ||
* \brief Basic SNS acceleration IK solver | ||
* \author Andy Park | ||
*/ | ||
/* | ||
* Copyright 2018 Rethink Robotics | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef SNS_IK_ACCELERATION_IK | ||
#define SNS_IK_ACCELERATION_IK | ||
|
||
#include <Eigen/Dense> | ||
#include <vector> | ||
#include <sns_ik/sns_acc_ik_base.hpp> | ||
|
||
namespace sns_ik { | ||
|
||
/*! \struct Task | ||
* A desired robot task | ||
*/ | ||
|
||
struct TaskAcc { | ||
Eigen::MatrixXd jacobian; //!< the task Jacobian | ||
Eigen::VectorXd dJdq; //!< the product of task Jacobian dot and joint velocity | ||
Eigen::VectorXd desired; //!< desired velocity in task space | ||
}; | ||
|
||
class SNSAccelerationIK { | ||
public: | ||
SNSAccelerationIK(int dof, double loop_period); | ||
virtual ~SNSAccelerationIK() {}; | ||
|
||
bool setJointsCapabilities(const Eigen::VectorXd limit_low, const Eigen::VectorXd limit_high, | ||
const Eigen::VectorXd maxVelocity, const Eigen::VectorXd maxAcceleration); | ||
bool setMaxJointAcceleration(const Eigen::VectorXd maxAcceleration); | ||
virtual void setNumberOfTasks(int ntasks, int dof = -1); | ||
virtual void setNumberOfDOF(int dof); | ||
|
||
// The control loop period in seconds | ||
void setLoopPeriod(double period) { loop_period = period; } | ||
|
||
// SNS Acceleration IK | ||
int getJointAcceleration(Eigen::VectorXd *jointAcceleration, const std::vector<TaskAcc> &sot, | ||
const Eigen::VectorXd &jointConfiguration, const Eigen::VectorXd &jointVelocities); | ||
|
||
std::vector<double> getTasksScaleFactor() const { return scaleFactors; } | ||
|
||
Eigen::VectorXd getJointLimitLow() { return jointLimit_low; } | ||
Eigen::VectorXd getJointLimitHigh() { return jointLimit_high; } | ||
Eigen::VectorXd getJointVelocityMax() { return maxJointVelocity; } | ||
|
||
void usePositionLimits(bool use) { m_usePositionLimits = use; } | ||
|
||
protected: | ||
|
||
// Shape the joint acceleration bound ddotQmin and ddotQmax | ||
void shapeJointAccelerationBound(const Eigen::VectorXd &actualJointConfiguration, | ||
const Eigen::VectorXd &actualJointVelocities, double margin = 0.98); | ||
|
||
int n_dof; //manipulator degree of freedom | ||
int n_tasks; //number of tasks | ||
double loop_period; //needed to compute the bounds | ||
|
||
Eigen::VectorXd jointLimit_low; // low joint limits | ||
Eigen::VectorXd jointLimit_high; // high joint limit | ||
Eigen::VectorXd maxJointVelocity; // maximum joint velocity | ||
Eigen::VectorXd maxJointAcceleration; // maximum joint acceleration | ||
bool m_usePositionLimits; | ||
|
||
Eigen::ArrayXd ddotQmin; // lower joint velocity bound | ||
Eigen::ArrayXd ddotQmax; // higher joint velocity bound | ||
std::vector<double> scaleFactors; | ||
|
||
// variables for base acc ik solver | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like most of these variables are only used in one function. They should not be member variables. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is right. I moved them inside the function now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
SnsAccIkBase::uPtr baseIkSolver; | ||
}; | ||
|
||
} // namespace sns_ik | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,10 +137,6 @@ SnsIkBase::ExitCode SnsAccIkBase::solve(const Eigen::MatrixXd& J, const Eigen::V | |
ROS_ERROR("Failed to compute task scale!"); | ||
return taskScaleExit; | ||
} | ||
if (tmpScale < MINIMUM_FINITE_SCALE_FACTOR) { // check that the solver found a feasible solution | ||
ROS_ERROR("Task is infeasible! scaling --> zero"); | ||
return ExitCode::InfeasibleTask; | ||
} | ||
|
||
if (tmpScale > 1.0) { | ||
ROS_ERROR("Task scale is %f, which is more than 1.0", tmpScale); | ||
|
@@ -172,10 +168,7 @@ SnsIkBase::ExitCode SnsAccIkBase::solve(const Eigen::MatrixXd& J, const Eigen::V | |
ddqNull(jntIdx) = (getUpperBounds())(jntIdx); | ||
} else if ((*ddq)(jntIdx) < (getLowerBounds())(jntIdx)) { | ||
ddqNull(jntIdx) = (getLowerBounds())(jntIdx); | ||
} else { | ||
ROS_ERROR("Internal error in computing task scale! ddq(%d) = %f", jntIdx, (*ddq)(jntIdx)); | ||
return ExitCode::InternalError; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this check removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From unit testing, I found out that this case was unnecessary and it caused a few tasks to fail by terminating the algorithm earlier. |
||
} | ||
} | ||
|
||
// Update the linear solver | ||
if (setLinearSolver(J*W) != ExitCode::Success) { | ||
|
@@ -189,6 +182,11 @@ SnsIkBase::ExitCode SnsAccIkBase::solve(const Eigen::MatrixXd& J, const Eigen::V | |
W = bestW; | ||
ddqNull = bestDdqNull; | ||
|
||
if (bestTaskScale < MINIMUM_FINITE_SCALE_FACTOR) { // check that the solver found a feasible solution | ||
ROS_ERROR("Task is infeasible! scaling --> zero"); | ||
return ExitCode::InfeasibleTask; | ||
} | ||
|
||
// Update the linear solver | ||
if (setLinearSolver(J * W) != ExitCode::Success) { | ||
ROS_ERROR("Solver failed to set linear solver!"); | ||
|
@@ -283,6 +281,7 @@ SnsIkBase::ExitCode SnsAccIkBase::solve(const Eigen::MatrixXd& J, const Eigen::V | |
// within the upper and lower bounds. | ||
Eigen::ArrayXd lowMargin = (getLowerBounds() - b); | ||
Eigen::ArrayXd uppMargin = (getUpperBounds() - b); | ||
|
||
for (size_t i = 0; i < getNrOfJoints(); i++) { | ||
if (jointIsFree[i]) { | ||
jntScaleFactorArr(i) = findScaleFactor(lowMargin(i), uppMargin(i), a(i)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function needs more documentation for inputs and outputs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, more documentation is still needed.