12 using namespace se2ez;
19 : n_(robot->getNumJoints())
24 , weights_(KDL::MatrixXd::Identity(n_, n_))
25 , tasks_(KDL::MatrixXd::Identity(6 * t_, 6 * t_))
28 for (
unsigned int i = 0; i <
t_; ++i)
43 const auto &data =
robot_->getFrameDataConst(frame);
45 for (
unsigned int i = 0; i < data->size; ++i)
52 for (
unsigned int i = 0; i < data->size; ++i)
53 weights_(data->index + i, data->index + i) = weights[i];
58 for (
unsigned int i = 0; i <
n_; ++i)
65 for (
unsigned int i = 0; i <
n_; ++i)
73 SE2EZ_ERROR(
"Tried to set lambda value of %1%, <= 0. Value must be > 0", lambda);
83 for (
unsigned int i = 0; i <
n_; ++i)
101 tasks_(task * 6 + index, task * 6 + index) = (active) ? 1.0 : 0.0;
111 , frames_([frames]() {
113 for (
unsigned int i = 0; i < frames.
size(); ++i)
118 ,
tree_(robot->getTree())
130 for (
const auto &frame :
frames_)
133 for (
const auto &frame : frames)
135 const auto &name = frame.first;
136 const auto &entry = frames_.find(name);
138 if (entry == frames_.end())
140 SE2EZ_ERROR(
"Frame %1% specified for solve not available!", name);
144 const unsigned int index = entry->second;
150 auto req = request.
find(name);
151 if (req == request.
end())
162 bool TreeIK::doIK(KDL::JntArray &in, KDL::JntArray &out,
const KDL::Frames &goals)
166 for (
unsigned int i = 0; i <
restarts_ && d < 0; ++i)
172 d =
posIK_.CartToJnt(in, goals, out);
175 SE2EZ_ERROR(
"Frame specified for solve not available!");
189 if (!
setTask(goals, frames, request))
194 KDL::JntArray out(
n_);
196 if (
doIK(in, out, goals))
248 unsigned int iterations,
double eps)
249 :
TreeIK(robot, frames, iterations, eps)
251 , state_(
std::make_shared<
State>(robot))
260 KDL::JntArray temp(out.columns());
261 for (
unsigned int i = 0; i <
restarts_; ++i)
267 d =
posIK_.CartToJnt(in, goals, temp);
270 SE2EZ_ERROR(
"Frame specified for solve not available!");
295 unsigned int iterations,
double eps)
virtual ~CollisionAwareChainIK()
Destructor.
std::mutex mutex_
Thread mutex.
Index
KDL specific indices for different components of the task matrix.
const KDL::JntArray min_
Joint minimums.
A shared pointer wrapper for se2ez::State.
A collision aware version of tree IK.
const std::string frame_
Task frame.
void setRequest(unsigned int task, Request request)
Sets the task matrix values for a task at index task according to a request.
void setJointWeight(const std::string &frame, const Eigen::VectorXd &weights) override
Sets the weights on a specific joint in the robot for IK solving.
A representation of a state of a Robot.
bool solve(StatePtr state, const Eigen::Isometry2d &frame, Request request=ALL)
Solve an IK request.
unsigned int restarts_
Number of random restarts.
bool solve(StatePtr state, const tf::EigenMap< std::string, Eigen::Isometry2d > &frames, const std::map< std::string, Request > &request={})
Solve an IK request.
virtual void setLambda(double lambda)
Sets lambda, damping constant in WDLS.
virtual void setJointWeights(const Eigen::VectorXd &weights)
Sets the weights for all joints in the robot for IK solving.
bool solve(StatePtr state, const Eigen::Isometry2d &frame, Request request=ALL)
Solve an IK request.
const std::string frame_
Task frame.
CollisionManagerPtr cm_
Collision Manager for IK.
Z Position, Ignored as we are 2D.
Eigen::VectorXd KDLToEigenVec(const KDL::JntArray &array)
Converts an KDL vector into a Eigen vector.
A collisions manager that uses Box2D as the underlying collision checking engine. ...
const unsigned int t_
Number of tasks.
const KDL::JntArray max_
Joint maximums.
void setRestarts(unsigned int restarts)
Sets the number of random restarts to use when solving a request.
CollisionAwareTreeIK(const RobotPtr &robot, const std::vector< std::string > &frames, unsigned int iterations=50, double eps=1e-4)
Constructor.
const KDL::Tree tree_
KDL tree used for solving.
Y Rotation, Ignored as we are 2D.
X Rotation, Ignored as we are 2D.
Common components of IK solvers.
virtual void setJointWeight(const std::string &frame, const Eigen::VectorXd &weights)
Sets the weights on a specific joint in the robot for IK solving.
double lambda_
Lambda, WDLS constant.
virtual ~ChainIK()
Destructor.
virtual bool doIK(KDL::JntArray &in, KDL::JntArray &out, const KDL::Frames &goals)
Actually solve an IK query.
void setRandom(KDL::JntArray &array) const
Sets a KDL array to random values between joint limits.
KDL::TreeIkSolverVel_wdls velIK_
Inverse velocity solver.
void setJointWeights(const Eigen::VectorXd &weights) override
Sets the weights for all joints in the robot for IK solving.
TreeIK(const RobotPtr &robot, const std::vector< std::string > &frames, unsigned int iterations=50, double eps=1e-4)
Constructor.
KDL::JntArray EigenToKDLVec(const Eigen::VectorXd &vec)
Converts an Eigen vector into a KDL vector.
A shared pointer wrapper for se2ez::Robot.
IKSolver(const IKSolver &)=delete
std::string printVector(const Eigen::VectorXd &v, unsigned int precision=4)
Returns a string of a vector's contents.
KDL::Frame EigenToKDLFrame(const Eigen::Isometry2d &iso)
Converts an Eigen transformation into a KDL transformation.
KDL::MatrixXd weights_
Joint variable weights.
#define SE2EZ_ERROR(fmt,...)
const unsigned int n_
Number of joint variables.
void setLambda(double lambda) override
Sets lambda, damping constant in WDLS.
KDL::TreeIkSolverPos_NR_JL posIK_
Inverse position solver.
KDL::MatrixXd tasks_
Task weights.
bool setTask(KDL::Frames &goals, const tf::EigenMap< std::string, Eigen::Isometry2d > &frames, const std::map< std::string, Request > &request)
Sets current task matrix and goals according to request.
Request
A bitmask specification of what task components should this IK request satisfy.
KDL::TreeFkSolverPos_recursive fk_
Forward kinematics solver.
CollisionAwareChainIK(const RobotPtr &robot, const std::string &frame, unsigned int iterations=50, double eps=1e-4)
Constructor.
const RobotPtr robot_
Reference to robot.
const std::map< std::string, unsigned int > frames_
Mapping of task frame name to index.
bool doIK(KDL::JntArray &in, KDL::JntArray &out, const KDL::Frames &goals) override
Actually solve an IK query.
ChainIK(const RobotPtr &robot, const std::string &frame, unsigned int iterations=50, double eps=1e-4)
Constructor.
StatePtr state_
Work state.
void setTask(unsigned int task, Index index, bool active)
Sets the specific index component of a task to active.