45 #include <boost/bind.hpp> 60 constexpr
char LOGNAME[] =
"robot_state";
64 : robot_model_(robot_model)
65 , has_velocity_(false)
66 , has_acceleration_(false)
68 , dirty_link_transforms_(robot_model_->getRootJoint())
69 , dirty_collision_body_transforms_(nullptr)
93 static_assert((
sizeof(Eigen::Isometry3d) / EIGEN_MAX_ALIGN_BYTES) * EIGEN_MAX_ALIGN_BYTES ==
sizeof(Eigen::Isometry3d),
94 "sizeof(Eigen::Isometry3d) should be a multiple of EIGEN_MAX_ALIGN_BYTES");
96 constexpr
unsigned int extra_alignment_bytes = EIGEN_MAX_ALIGN_BYTES - 1;
98 const int nr_doubles_for_dirty_joint_transforms =
99 1 +
robot_model_->getJointModelCount() / (
sizeof(double) /
sizeof(
unsigned char));
103 sizeof(
double) * (
robot_model_->getVariableCount() * 3 + nr_doubles_for_dirty_joint_transforms) +
104 extra_alignment_bytes;
110 ~(uintptr_t)extra_alignment_bytes);
124 const int nr_doubles_for_dirty_joint_transforms =
125 1 +
robot_model_->getJointModelCount() / (
sizeof(double) /
sizeof(
unsigned char));
163 const int nr_doubles_for_dirty_joint_transforms =
164 1 +
robot_model_->getJointModelCount() / (
sizeof(double) /
sizeof(
unsigned char));
171 nr_doubles_for_dirty_joint_transforms);
177 for (std::map<std::string, AttachedBody*>::const_iterator it = other.
attached_body_map_.begin();
179 attachBody(it->second->getName(), it->second->getShapes(), it->second->getFixedTransforms(),
180 it->second->getTouchLinks(), it->second->getAttachedLinkName(), it->second->getDetachPosture());
301 for (std::size_t i = 0; i < joints.size(); ++i)
302 joints[i]->getVariableRandomPositions(rng,
position_ + joints[i]->getFirstVariableIndex());
307 const std::vector<double>& distances)
313 assert(distances.size() == joints.size());
314 for (std::size_t i = 0; i < joints.size(); ++i)
316 const int idx = joints[i]->getFirstVariableIndex();
317 joints[i]->getVariableRandomPositionsNearBy(rng,
position_ + joints[i]->getFirstVariableIndex(),
329 for (std::size_t i = 0; i < joints.size(); ++i)
331 const int idx = joints[i]->getFirstVariableIndex();
332 joints[i]->getVariableRandomPositionsNearBy(rng,
position_ + joints[i]->getFirstVariableIndex(),
340 std::map<std::string, double> m;
369 for (std::map<std::string, double>::const_iterator it = variable_map.begin(), end = variable_map.end(); it != end;
381 std::vector<std::string>& missing_variables)
const 383 missing_variables.clear();
384 const std::vector<std::string>& nm =
robot_model_->getVariableNames();
385 for (std::size_t i = 0; i < nm.size(); ++i)
386 if (variable_map.find(nm[i]) == variable_map.end())
387 if (
robot_model_->getJointOfVariable(nm[i])->getMimic() ==
nullptr)
388 missing_variables.push_back(nm[i]);
392 std::vector<std::string>& missing_variables)
399 const std::vector<double>& variable_position)
401 for (std::size_t i = 0; i < variable_names.size(); ++i)
414 for (std::map<std::string, double>::const_iterator it = variable_map.begin(), end = variable_map.end(); it != end;
420 std::vector<std::string>& missing_variables)
427 const std::vector<double>& variable_velocity)
430 assert(variable_names.size() == variable_velocity.size());
431 for (std::size_t i = 0; i < variable_names.size(); ++i)
438 for (std::map<std::string, double>::const_iterator it = variable_map.begin(), end = variable_map.end(); it != end;
444 std::vector<std::string>& missing_variables)
451 const std::vector<double>& variable_acceleration)
454 assert(variable_names.size() == variable_acceleration.size());
455 for (std::size_t i = 0; i < variable_names.size(); ++i)
462 for (std::map<std::string, double>::const_iterator it = variable_map.begin(), end = variable_map.end(); it != end;
468 std::vector<std::string>& missing_variables)
475 const std::vector<double>& variable_effort)
478 assert(variable_names.size() == variable_effort.size());
479 for (std::size_t i = 0; i < variable_names.size(); ++i)
487 for (
size_t i = 0; i <
robot_model_->getVariableCount(); ++i)
511 for (std::size_t i = 0; i < il.size(); ++i)
520 for (std::size_t i = 0; i < il.size(); ++i)
532 i += jm->getVariableCount();
544 i += jm->getVariableCount();
555 for (std::size_t i = 0; i < il.size(); ++i)
562 values.resize(il.size());
563 for (std::size_t i = 0; i < il.size(); ++i)
575 for (std::size_t i = 0; i < il.size(); ++i)
584 for (std::size_t i = 0; i < il.size(); ++i)
594 for (std::size_t i = 0; i < il.size(); ++i)
601 values.resize(il.size());
602 for (std::size_t i = 0; i < il.size(); ++i)
614 for (std::size_t i = 0; i < il.size(); ++i)
623 for (std::size_t i = 0; i < il.size(); ++i)
633 for (std::size_t i = 0; i < il.size(); ++i)
640 values.resize(il.size());
641 for (std::size_t i = 0; i < il.size(); ++i)
671 const std::vector<int>& ot_id = link->areCollisionOriginTransformsIdentity();
672 const int index_co = link->getFirstCollisionBodyTransformIndex();
673 const int index_l = link->getLinkIndex();
674 for (std::size_t j = 0, end = ot.size(); j != end; ++j)
704 int idx_link = link->getLinkIndex();
709 if (link->parentJointIsFixed())
714 if (link->jointOriginTransformIsIdentity())
725 if (link->jointOriginTransformIsIdentity())
729 link->getJointOriginTransform().affine() *
getJointTransform(link->getParentJointModel()).matrix();
734 for (std::map<std::string, AttachedBody*>::const_iterator it =
attached_body_map_.begin();
754 for (std::size_t i = 0; i < cj.size(); ++i)
764 child_link = parent_link;
777 for (std::size_t i = 0; i < cj.size(); ++i)
786 for (std::map<std::string, AttachedBody*>::const_iterator it =
attached_body_map_.begin();
793 const std::vector<const JointModel*>& jm =
robot_model_->getActiveJointModels();
794 for (std::size_t i = 0; i < jm.size(); ++i)
803 for (std::size_t i = 0; i < jm.size(); ++i)
811 const std::vector<const JointModel*>& jm =
robot_model_->getActiveJointModels();
812 for (std::size_t i = 0; i < jm.size(); ++i)
819 for (std::size_t i = 0; i < jm.size(); ++i)
845 std::pair<double, const JointModel*>
848 double distance = std::numeric_limits<double>::max();
850 for (std::size_t i = 0; i < joints.size(); ++i)
855 if (static_cast<const RevoluteJointModel*>(joints[i])->isContinuous())
860 std::vector<double> lower_bounds(bounds.size()), upper_bounds(bounds.size());
861 for (std::size_t j = 0; j < bounds.size(); ++j)
863 lower_bounds[j] = bounds[j].min_position_;
864 upper_bounds[j] = bounds[j].max_position_;
866 double new_distance = joints[i]->distance(joint_values, &lower_bounds[0]);
867 if (new_distance < distance)
870 distance = new_distance;
872 new_distance = joints[i]->
distance(joint_values, &upper_bounds[0]);
873 if (new_distance < distance)
876 distance = new_distance;
879 return std::make_pair(distance, index);
885 for (std::size_t joint_id = 0; joint_id < jm.size(); ++joint_id)
887 const int idx = jm[joint_id]->getFirstVariableIndex();
888 const std::vector<VariableBounds>& bounds = jm[joint_id]->getVariableBounds();
891 for (std::size_t var_id = 0; var_id < jm[joint_id]->getVariableCount(); ++var_id)
895 if (dtheta > dt * bounds[var_id].max_velocity_)
906 for (std::size_t i = 0; i < jm.size(); ++i)
908 const int idx = jm[i]->getFirstVariableIndex();
909 d += jm[i]->getDistanceFactor() * jm[i]->distance(
position_ + idx, other.
position_ + idx);
927 for (std::size_t i = 0; i < jm.size(); ++i)
929 const int idx = jm[i]->getFirstVariableIndex();
947 std::map<std::string, AttachedBody*>::const_iterator it =
attached_body_map_.find(
id);
970 const std::string& link,
const trajectory_msgs::JointTrajectory& detach_posture)
982 attached_bodies.clear();
984 for (std::map<std::string, AttachedBody*>::const_iterator it =
attached_body_map_.begin();
986 attached_bodies.push_back(it->second);
991 attached_bodies.clear();
992 for (std::map<std::string, AttachedBody*>::const_iterator it =
attached_body_map_.begin();
994 if (group->
hasLinkModel(it->second->getAttachedLinkName()))
995 attached_bodies.push_back(it->second);
1000 attached_bodies.clear();
1001 for (std::map<std::string, AttachedBody*>::const_iterator it =
attached_body_map_.begin();
1003 if (it->second->getAttachedLink() == lm)
1004 attached_bodies.push_back(it->second);
1009 for (std::map<std::string, AttachedBody*>::const_iterator it =
attached_body_map_.begin();
1024 if (it->second->getAttachedLink() != link)
1032 std::map<std::string, AttachedBody*>::iterator
del = it++;
1042 if (!group->
hasLinkModel(it->second->getAttachedLinkName()))
1050 std::map<std::string, AttachedBody*>::iterator
del = it++;
1078 if (!frame_id.empty() && frame_id[0] ==
'/')
1082 static const Eigen::Isometry3d IDENTITY_TRANSFORM = Eigen::Isometry3d::Identity();
1084 return IDENTITY_TRANSFORM;
1090 std::map<std::string, AttachedBody*>::const_iterator jt =
attached_body_map_.find(frame_id);
1094 "Transform from frame '%s' to frame '%s' is not known " 1095 "('%s' should be a link name or an attached body's id).",
1096 frame_id.c_str(),
robot_model_->getModelFrame().c_str(), frame_id.c_str());
1097 return IDENTITY_TRANSFORM;
1104 return IDENTITY_TRANSFORM;
1108 "There are multiple geometries associated to attached body '%s'. " 1109 "Returning the transform for the first one.",
1116 if (!frame_id.empty() && frame_id[0] ==
'/')
1120 std::map<std::string, AttachedBody*>::const_iterator it =
attached_body_map_.find(frame_id);
1121 return it !=
attached_body_map_.end() && !it->second->getGlobalCollisionBodyTransforms().empty();
1125 const std_msgs::ColorRGBA& color,
const std::string& ns,
const ros::Duration& dur,
1126 bool include_attached)
const 1128 std::size_t cur_num = arr.markers.size();
1130 unsigned int id = cur_num;
1131 for (std::size_t i = cur_num; i < arr.markers.size(); ++i, ++id)
1133 arr.markers[i].ns = ns;
1134 arr.markers[i].id = id;
1135 arr.markers[i].lifetime = dur;
1136 arr.markers[i].color = color;
1141 bool include_attached)
const 1144 for (std::size_t i = 0; i < link_names.size(); ++i)
1150 if (include_attached)
1151 for (std::map<std::string, AttachedBody*>::const_iterator it =
attached_body_map_.begin();
1153 if (it->second->getAttachedLink() == lm)
1155 for (std::size_t j = 0; j < it->second->getShapes().size(); ++j)
1157 visualization_msgs::Marker att_mark;
1158 att_mark.header.frame_id =
robot_model_->getModelFrame();
1159 att_mark.header.stamp = tm;
1163 if (fabs(att_mark.scale.x * att_mark.scale.y * att_mark.scale.z) < std::numeric_limits<float>::epsilon())
1165 att_mark.pose =
tf2::toMsg(it->second->getGlobalCollisionBodyTransforms()[j]);
1166 arr.markers.push_back(att_mark);
1174 for (std::size_t j = 0; j < lm->
getShapes().size(); ++j)
1176 visualization_msgs::Marker mark;
1178 mark.header.stamp = tm;
1182 if (mesh_resource.empty() || lm->
getShapes().size() > 1)
1187 if (fabs(mark.scale.x * mark.scale.y * mark.scale.z) < std::numeric_limits<float>::epsilon())
1193 mark.type = mark.MESH_RESOURCE;
1194 mark.mesh_use_embedded_materials =
false;
1195 mark.mesh_resource = mesh_resource;
1198 mark.scale.x = mesh_scale[0];
1199 mark.scale.y = mesh_scale[1];
1200 mark.scale.z = mesh_scale[2];
1204 arr.markers.push_back(mark);
1212 Eigen::MatrixXd result;
1214 throw Exception(
"Unable to compute Jacobian");
1219 const Eigen::Vector3d& reference_point_position, Eigen::MatrixXd& jacobian,
1220 bool use_quaternion_representation)
const 1232 ROS_ERROR_NAMED(
LOGNAME,
"Link name '%s' does not exist in the chain '%s' or is not a child for this chain",
1239 Eigen::Isometry3d reference_transform =
1241 int rows = use_quaternion_representation ? 7 : 6;
1243 jacobian = Eigen::MatrixXd::Zero(rows, columns);
1246 Eigen::Vector3d point_transform = link_transform * reference_point_position;
1256 Eigen::Isometry3d joint_transform;
1280 jacobian.block<3, 1>(0, joint_index) =
1281 jacobian.block<3, 1>(0, joint_index) + joint_axis.cross(point_transform - joint_transform.translation());
1282 jacobian.block<3, 1>(3, joint_index) = jacobian.block<3, 1>(3, joint_index) + joint_axis;
1288 jacobian.block<3, 1>(0, joint_index) = jacobian.block<3, 1>(0, joint_index) + joint_axis;
1294 jacobian.block<3, 1>(0, joint_index) = jacobian.block<3, 1>(0, joint_index) + joint_axis;
1296 jacobian.block<3, 1>(0, joint_index + 1) = jacobian.block<3, 1>(0, joint_index + 1) + joint_axis;
1298 jacobian.block<3, 1>(0, joint_index + 2) = jacobian.block<3, 1>(0, joint_index + 2) +
1299 joint_axis.cross(point_transform - joint_transform.translation());
1300 jacobian.block<3, 1>(3, joint_index + 2) = jacobian.block<3, 1>(3, joint_index + 2) + joint_axis;
1305 if (pjm == root_joint_model)
1309 if (use_quaternion_representation)
1316 Eigen::Quaterniond q(link_transform.rotation());
1317 double w = q.w(),
x = q.x(),
y = q.y(),
z = q.z();
1318 Eigen::MatrixXd quaternion_update_matrix(4, 3);
1319 quaternion_update_matrix << -
x, -
y, -
z, w, -z, y, z, w, -x, -y, x, w;
1320 jacobian.block(3, 0, 4, columns) = 0.5 * quaternion_update_matrix * jacobian.block(3, 0, 3, columns);
1328 Eigen::VectorXd qdot;
1336 Eigen::Matrix<double, 6, 1>
t;
1342 const Eigen::VectorXd& twist,
const LinkModel* tip)
const 1351 Eigen::MatrixXd e_wb = Eigen::ArrayXXd::Zero(6, 6);
1352 e_wb.block(0, 0, 3, 3) = e_mb.matrix().block(0, 0, 3, 3);
1353 e_wb.block(3, 3, 3, 3) = e_mb.matrix().block(0, 0, 3, 3);
1357 Eigen::JacobiSVD<Eigen::MatrixXd> svd_of_j(j, Eigen::ComputeThinU | Eigen::ComputeThinV);
1358 const Eigen::MatrixXd& u = svd_of_j.matrixU();
1359 const Eigen::MatrixXd& v = svd_of_j.matrixV();
1360 const Eigen::VectorXd&
s = svd_of_j.singularValues();
1362 Eigen::VectorXd sinv = s;
1363 static const double PINVTOLER = std::numeric_limits<float>::epsilon();
1365 for (std::size_t i = 0; i < static_cast<std::size_t>(s.rows()); ++i)
1366 if (fabs(s(i)) > maxsv)
1368 for (std::size_t i = 0; i < static_cast<std::size_t>(s.rows()); ++i)
1371 if (fabs(s(i)) > maxsv * PINVTOLER)
1372 sinv(i) = 1.0 / s(i);
1376 Eigen::MatrixXd jinv = (v * sinv.asDiagonal() * u.transpose());
1379 qdot = jinv * twist;
1393 std::vector<double>
values;
1395 return constraint(
this, jmg, &values[0]);
1411 return setFromIK(jmg, pose, solver->getTipFrame(), timeout, constraint, options);
1418 Eigen::Isometry3d mat;
1420 static std::vector<double> consistency_limits;
1421 return setFromIK(jmg, mat, tip, consistency_limits, timeout, constraint, options);
1434 static std::vector<double> consistency_limits;
1435 return setFromIK(jmg, pose, solver->getTipFrame(), consistency_limits, timeout, constraint, options);
1442 static std::vector<double> consistency_limits;
1443 return setFromIK(jmg, pose_in, tip_in, consistency_limits, timeout, constraint, options);
1450 const std::vector<double>& ik_sol, moveit_msgs::MoveItErrorCodes& error_code)
1453 std::vector<double> solution(bij.size());
1454 for (std::size_t i = 0; i < bij.size(); ++i)
1455 solution[bij[i]] = ik_sol[i];
1456 if (constraint(state, group, &solution[0]))
1457 error_code.val = moveit_msgs::MoveItErrorCodes::SUCCESS;
1474 const LinkModel* lm =
getLinkModel((!ik_frame.empty() && ik_frame[0] ==
'/') ? ik_frame.substr(1) : ik_frame);
1486 const std::vector<double>& consistency_limits_in,
double timeout,
1492 poses.push_back(pose_in);
1494 std::vector<std::string> tips;
1495 tips.push_back(tip_in);
1497 std::vector<std::vector<double> > consistency_limits;
1498 consistency_limits.push_back(consistency_limits_in);
1500 return setFromIK(jmg, poses, tips, consistency_limits, timeout, constraint, options);
1504 const std::vector<std::string>& tips_in,
double timeout,
1508 const std::vector<std::vector<double> > consistency_limits;
1509 return setFromIK(jmg, poses_in, tips_in, consistency_limits, timeout, constraint, options);
1513 const std::vector<std::string>& tips_in,
1514 const std::vector<std::vector<double> >& consistency_limit_sets,
double timeout,
1519 if (poses_in.size() != tips_in.size())
1529 bool valid_solver =
true;
1532 valid_solver =
false;
1535 else if (poses_in.size() > 1)
1537 std::string error_msg;
1538 if (!solver->supportsGroup(jmg, &error_msg))
1541 typeid(*solver).name(), jmg->
getName().c_str(), error_msg.c_str());
1542 valid_solver =
false;
1549 if (poses_in.size() > 1)
1552 return setFromIKSubgroups(jmg, poses_in, tips_in, consistency_limit_sets, timeout, constraint, options);
1562 std::vector<double> consistency_limits;
1563 if (consistency_limit_sets.size() > 1)
1566 "Invalid number (%zu) of sets of consistency limits for a setFromIK request " 1567 "that is being solved by a single IK solver",
1568 consistency_limit_sets.size());
1571 else if (consistency_limit_sets.size() == 1)
1572 consistency_limits = consistency_limit_sets[0];
1574 const std::vector<std::string>& solver_tip_frames = solver->getTipFrames();
1577 std::vector<bool> tip_frames_used(solver_tip_frames.size(),
false);
1580 std::vector<geometry_msgs::Pose> ik_queries(solver_tip_frames.size());
1583 for (std::size_t i = 0; i < poses_in.size(); ++i)
1586 Eigen::Isometry3d pose = poses_in[i];
1587 std::string pose_frame = tips_in[i];
1590 if (!pose_frame.empty() && pose_frame[0] ==
'/')
1591 pose_frame = pose_frame.substr(1);
1599 bool found_valid_frame =
false;
1600 std::size_t solver_tip_id;
1601 for (solver_tip_id = 0; solver_tip_id < solver_tip_frames.size(); ++solver_tip_id)
1604 if (tip_frames_used[solver_tip_id])
1608 std::string solver_tip_frame = solver_tip_frames[solver_tip_id];
1612 if (!solver_tip_frame.empty() && solver_tip_frame[0] ==
'/')
1613 solver_tip_frame = solver_tip_frame.substr(1);
1615 if (pose_frame != solver_tip_frame)
1621 if (ab_trans.size() != 1)
1624 "with multiple geometries as a reference frame.");
1628 pose = pose * ab_trans[0].inverse();
1630 if (pose_frame != solver_tip_frame)
1639 for (robot_model::LinkTransformMap::const_iterator it = fixed_links.begin(); it != fixed_links.end(); ++it)
1642 pose_frame = solver_tip_frame;
1643 pose = pose * it->second;
1651 if (pose_frame == solver_tip_frame)
1653 found_valid_frame =
true;
1660 if (!found_valid_frame)
1662 ROS_ERROR_NAMED(
LOGNAME,
"Cannot compute IK for query %zu pose reference frame '%s'", i, pose_frame.c_str());
1664 std::stringstream ss;
1665 for (solver_tip_id = 0; solver_tip_id < solver_tip_frames.size(); ++solver_tip_id)
1666 ss << solver_tip_frames[solver_tip_id] <<
", ";
1672 tip_frames_used[solver_tip_id] =
true;
1675 geometry_msgs::Pose ik_query;
1679 ik_queries[solver_tip_id] = ik_query;
1683 for (std::size_t solver_tip_id = 0; solver_tip_id < solver_tip_frames.size(); ++solver_tip_id)
1686 if (tip_frames_used[solver_tip_id])
1690 std::string solver_tip_frame = solver_tip_frames[solver_tip_id];
1694 if (!solver_tip_frame.empty() && solver_tip_frame[0] ==
'/')
1695 solver_tip_frame = solver_tip_frame.substr(1);
1705 geometry_msgs::Pose ik_query;
1709 ik_queries[solver_tip_id] = ik_query;
1712 tip_frames_used[solver_tip_id] =
true;
1716 if (timeout < std::numeric_limits<double>::epsilon())
1722 ik_callback_fn = boost::bind(&ikCallbackFnAdapter,
this, jmg, constraint, _1, _2, _3);
1727 std::vector<double> initial_values;
1729 std::vector<double> seed(bij.size());
1730 for (std::size_t i = 0; i < bij.size(); ++i)
1731 seed[i] = initial_values[bij[i]];
1734 std::vector<double> ik_sol;
1735 moveit_msgs::MoveItErrorCodes error;
1737 if (solver->searchPositionIK(ik_queries, seed, timeout, consistency_limits, ik_sol, ik_callback_fn, error, options,
1740 std::vector<double> solution(bij.size());
1741 for (std::size_t i = 0; i < bij.size(); ++i)
1742 solution[bij[i]] = ik_sol[i];
1750 const std::vector<std::string>& tips_in,
1751 const std::vector<std::vector<double> >& consistency_limits,
double timeout,
1758 std::vector<const JointModelGroup*> sub_groups;
1762 if (poses_in.size() != sub_groups.size())
1764 ROS_ERROR_NAMED(
LOGNAME,
"Number of poses (%zu) must be the same as number of sub-groups (%zu)", poses_in.size(),
1769 if (tips_in.size() != sub_groups.size())
1771 ROS_ERROR_NAMED(
LOGNAME,
"Number of tip names (%zu) must be same as number of sub-groups (%zu)", tips_in.size(),
1776 if (!consistency_limits.empty() && consistency_limits.size() != sub_groups.size())
1778 ROS_ERROR_NAMED(
LOGNAME,
"Number of consistency limit vectors must be the same as number of sub-groups");
1782 for (std::size_t i = 0; i < consistency_limits.size(); ++i)
1784 if (consistency_limits[i].size() != sub_groups[i]->getVariableCount())
1786 ROS_ERROR_NAMED(
LOGNAME,
"Number of joints in consistency_limits is %zu but it should be should be %u", i,
1793 std::vector<kinematics::KinematicsBaseConstPtr> solvers;
1794 for (std::size_t i = 0; i < poses_in.size(); ++i)
1796 kinematics::KinematicsBaseConstPtr solver = sub_groups[i]->getSolverInstance();
1802 solvers.push_back(solver);
1807 std::vector<std::string> pose_frames = tips_in;
1810 for (std::size_t i = 0; i < poses_in.size(); ++i)
1812 Eigen::Isometry3d& pose = transformed_poses[i];
1813 std::string& pose_frame = pose_frames[i];
1820 std::string solver_tip_frame = solvers[i]->getTipFrame();
1824 if (!solver_tip_frame.empty() && solver_tip_frame[0] ==
'/')
1825 solver_tip_frame = solver_tip_frame.substr(1);
1827 if (pose_frame != solver_tip_frame)
1833 if (ab_trans.size() != 1)
1839 pose = pose * ab_trans[0].inverse();
1841 if (pose_frame != solver_tip_frame)
1847 for (robot_model::LinkTransformMap::const_iterator it = fixed_links.begin(); it != fixed_links.end(); ++it)
1848 if (it->first->getName() == solver_tip_frame)
1850 pose_frame = solver_tip_frame;
1851 pose = pose * it->second;
1857 if (pose_frame != solver_tip_frame)
1860 pose_frame.c_str(), solver_tip_frame.c_str());
1866 std::vector<geometry_msgs::Pose> ik_queries(poses_in.size());
1869 ik_callback_fn = boost::bind(&ikCallbackFnAdapter,
this, jmg, constraint, _1, _2, _3);
1871 for (std::size_t i = 0; i < transformed_poses.size(); ++i)
1873 Eigen::Quaterniond quat(transformed_poses[i].rotation());
1875 ik_queries[i].position.x = point.x();
1876 ik_queries[i].position.y = point.y();
1877 ik_queries[i].position.z = point.z();
1878 ik_queries[i].orientation.x = quat.x();
1879 ik_queries[i].orientation.y = quat.y();
1880 ik_queries[i].orientation.z = quat.z();
1881 ik_queries[i].orientation.w = quat.w();
1885 if (timeout < std::numeric_limits<double>::epsilon())
1890 bool first_seed =
true;
1891 unsigned int attempts = 0;
1896 bool found_solution =
true;
1897 for (std::size_t sg = 0; sg < sub_groups.size(); ++sg)
1899 const std::vector<unsigned int>& bij = sub_groups[sg]->getKinematicsSolverJointBijection();
1900 std::vector<double> seed(bij.size());
1904 std::vector<double> initial_values;
1906 for (std::size_t i = 0; i < bij.size(); ++i)
1907 seed[i] = initial_values[bij[i]];
1913 std::vector<double> random_values;
1914 sub_groups[sg]->getVariableRandomPositions(rng, random_values);
1915 for (std::size_t i = 0; i < bij.size(); ++i)
1916 seed[i] = random_values[bij[i]];
1920 std::vector<double> ik_sol;
1921 moveit_msgs::MoveItErrorCodes error;
1922 const std::vector<double>& climits = consistency_limits.empty() ? std::vector<double>() : consistency_limits[sg];
1923 if (solvers[sg]->searchPositionIK(ik_queries[sg], seed, (timeout - elapsed) / sub_groups.size(), climits, ik_sol,
1926 std::vector<double> solution(bij.size());
1927 for (std::size_t i = 0; i < bij.size(); ++i)
1928 solution[bij[i]] = ik_sol[i];
1933 found_solution =
false;
1939 std::vector<double> full_solution;
1941 if (constraint ? constraint(
this, jmg, &full_solution[0]) :
true)
1949 }
while (elapsed < timeout);
1964 const Eigen::Vector3d rotated_direction = global_reference_frame ? direction : start_pose.rotation() * direction;
1967 Eigen::Isometry3d target_pose = start_pose;
1968 target_pose.translation() += rotated_direction *
distance;
1972 computeCartesianPath(group, traj, link, target_pose,
true, max_step, jump_threshold, validCallback, options));
1976 const LinkModel* link,
const Eigen::Isometry3d& target,
1977 bool global_reference_frame,
const MaxEEFStep& max_step,
1984 for (std::size_t i = 0; i < cjnt.size(); ++i)
1991 Eigen::Isometry3d rotated_target = global_reference_frame ? target : start_pose * target;
1993 Eigen::Quaterniond start_quaternion(start_pose.rotation());
1994 Eigen::Quaterniond target_quaternion(rotated_target.rotation());
1999 "Invalid MaxEEFStep passed into computeCartesianPath. Both the MaxEEFStep.rotation and " 2000 "MaxEEFStep.translation components must be non-negative and at least one component must be " 2001 "greater than zero");
2005 double rotation_distance = start_quaternion.angularDistance(target_quaternion);
2006 double translation_distance = (rotated_target.translation() - start_pose.translation()).norm();
2009 std::size_t translation_steps = 0;
2011 translation_steps = floor(translation_distance / max_step.
translation);
2013 std::size_t rotation_steps = 0;
2015 rotation_steps = floor(rotation_distance / max_step.
rotation);
2018 std::size_t steps = std::max(translation_steps, rotation_steps) + 1;
2019 if (jump_threshold.
factor > 0 && steps < MIN_STEPS_FOR_JUMP_THRESH)
2023 std::vector<double> consistency_limits;
2028 switch (jm->getType())
2040 limit = jm->getMaximumExtent();
2041 consistency_limits.push_back(limit);
2045 traj.push_back(RobotStatePtr(
new RobotState(*
this)));
2047 double last_valid_percentage = 0.0;
2048 for (std::size_t i = 1; i <= steps; ++i)
2050 double percentage = (double)i / (
double)steps;
2052 Eigen::Isometry3d pose(start_quaternion.slerp(percentage, target_quaternion));
2053 pose.translation() = percentage * rotated_target.translation() + (1 - percentage) * start_pose.translation();
2057 if (
setFromIK(group, pose, link->
getName(), consistency_limits, 0.0, validCallback, options))
2058 traj.push_back(RobotStatePtr(
new RobotState(*
this)));
2062 last_valid_percentage = percentage;
2067 return last_valid_percentage;
2072 bool global_reference_frame,
const MaxEEFStep& max_step,
2077 double percentage_solved = 0.0;
2078 for (std::size_t i = 0; i < waypoints.size(); ++i)
2082 std::vector<RobotStatePtr> waypoint_traj;
2083 double wp_percentage_solved =
computeCartesianPath(group, waypoint_traj, link, waypoints[i], global_reference_frame,
2084 max_step, NO_JOINT_SPACE_JUMP_TEST, validCallback, options);
2085 if (fabs(wp_percentage_solved - 1.0) < std::numeric_limits<double>::epsilon())
2087 percentage_solved = (double)(i + 1) / (double)waypoints.size();
2088 std::vector<RobotStatePtr>::iterator
start = waypoint_traj.begin();
2089 if (i > 0 && !waypoint_traj.empty())
2090 std::advance(start, 1);
2091 traj.insert(traj.end(), start, waypoint_traj.end());
2095 percentage_solved += wp_percentage_solved / (double)waypoints.size();
2096 std::vector<RobotStatePtr>::iterator
start = waypoint_traj.begin();
2097 if (i > 0 && !waypoint_traj.empty())
2098 std::advance(start, 1);
2099 traj.insert(traj.end(), start, waypoint_traj.end());
2106 return percentage_solved;
2112 double percentage_solved = 1.0;
2113 if (traj.size() <= 1)
2114 return percentage_solved;
2116 if (jump_threshold.
factor > 0.0)
2122 return percentage_solved;
2126 double jump_threshold_factor)
2131 "The computed trajectory is too short to detect jumps in joint-space " 2132 "Need at least %zu steps, only got %zu. Try a lower max_step.",
2133 MIN_STEPS_FOR_JUMP_THRESH, traj.size());
2136 std::vector<double> dist_vector;
2137 dist_vector.reserve(traj.size() - 1);
2138 double total_dist = 0.0;
2139 for (std::size_t i = 1; i < traj.size(); ++i)
2141 double dist_prev_point = traj[i]->distance(*traj[i - 1], group);
2142 dist_vector.push_back(dist_prev_point);
2143 total_dist += dist_prev_point;
2146 double percentage = 1.0;
2148 double thres = jump_threshold_factor * (total_dist / (double)dist_vector.size());
2149 for (std::size_t i = 0; i < dist_vector.size(); ++i)
2150 if (dist_vector[i] > thres)
2153 percentage = (double)(i + 1) / (double)(traj.size());
2162 double revolute_threshold,
double prismatic_threshold)
2169 LimitData data[2] = { { revolute_threshold, revolute_threshold > 0.0 },
2170 { prismatic_threshold, prismatic_threshold > 0.0 } };
2171 bool still_valid =
true;
2173 for (std::size_t traj_ix = 0, ix_end = traj.size() - 1; traj_ix != ix_end; ++traj_ix)
2175 for (
auto& joint : joints)
2177 unsigned int type_index;
2178 switch (joint->getType())
2188 "Joint %s has not supported type %s. \n" 2189 "testAbsoluteJointSpaceJump only supports prismatic and revolute joints.",
2190 joint->getName().c_str(), joint->getTypeName().c_str());
2193 if (!data[type_index].check_)
2196 double distance = traj[traj_ix]->distance(*traj[traj_ix + 1], joint);
2197 if (distance > data[type_index].limit_)
2199 ROS_DEBUG_NAMED(
LOGNAME,
"Truncating Cartesian path due to detected jump of %.4f > %.4f in joint %s", distance,
2200 data[type_index].limit_, joint->getName().c_str());
2201 still_valid =
false;
2208 double percent_valid = (double)(traj_ix + 1) / (double)(traj.size());
2209 traj.resize(traj_ix + 1);
2210 return percent_valid;
2221 std::vector<const LinkModel*> links =
robot_model_->getLinkModelsWithCollisionGeometry();
2222 for (std::size_t i = 0; i < links.size(); ++i)
2226 transform.translate(links[i]->getCenteredBoundingBoxOffset());
2229 for (std::map<std::string, AttachedBody*>::const_iterator it =
attached_body_map_.begin();
2233 const std::vector<shapes::ShapeConstPtr>&
shapes = it->second->getShapes();
2234 for (std::size_t i = 0; i < transforms.size(); ++i)
2242 aabb.resize(6, 0.0);
2243 if (!bounding_box.isEmpty())
2247 Eigen::Map<Eigen::VectorXd, Eigen::Unaligned, Eigen::InnerStride<2> >(aabb.data(), 3) = bounding_box.min();
2248 Eigen::Map<Eigen::VectorXd, Eigen::Unaligned, Eigen::InnerStride<2> >(aabb.data() + 1, 3) = bounding_box.max();
2254 const std::vector<std::string>& nm =
robot_model_->getVariableNames();
2255 for (std::size_t i = 0; i < nm.size(); ++i)
2256 out << nm[i] <<
"=" <<
position_[i] << std::endl;
2267 for (std::size_t i = 0; i < joints.size(); ++i)
2283 out <<
" " << std::fixed << std::setprecision(5) << bound.
min_position_ <<
"\t";
2285 double step = delta / 20.0;
2287 bool marker_shown =
false;
2291 if (!marker_shown && current_value < value)
2294 marker_shown =
true;
2303 out <<
" \t" << std::fixed << std::setprecision(5) << bound.
max_position_ <<
" \t" << joints[i]->getName()
2304 <<
" current: " << std::fixed << std::setprecision(5) << current_value << std::endl;
2313 out <<
" * Dirty Joint Transforms: " << std::endl;
2314 const std::vector<const JointModel*>& jm =
robot_model_->getJointModels();
2315 for (std::size_t i = 0; i < jm.size(); ++i)
2317 out <<
" " << jm[i]->
getName() << std::endl;
2320 out <<
" * Dirty Collision Body Transforms: " 2326 out <<
"Robot State @" <<
this << std::endl;
2331 out <<
" * Position: ";
2332 for (std::size_t i = 0; i < n; ++i)
2337 out <<
" * Position: NULL" << std::endl;
2341 out <<
" * Velocity: ";
2342 for (std::size_t i = 0; i < n; ++i)
2347 out <<
" * Velocity: NULL" << std::endl;
2351 out <<
" * Acceleration: ";
2352 for (std::size_t i = 0; i < n; ++i)
2357 out <<
" * Acceleration: NULL" << std::endl;
2361 out <<
" * Dirty Collision Body Transforms: " 2369 Eigen::Quaterniond q(transform.rotation());
2370 out <<
"T.xyz = [" << transform.translation().x() <<
", " << transform.translation().y() <<
", " 2371 << transform.translation().z() <<
"], Q.xyzw = [" << q.x() <<
", " << q.y() <<
", " << q.z() <<
", " << q.w()
2372 <<
"]" << std::endl;
2379 out <<
"No transforms computed" << std::endl;
2383 out <<
"Joint transforms:" << std::endl;
2384 const std::vector<const JointModel*>& jm =
robot_model_->getJointModels();
2385 for (std::size_t i = 0; i < jm.size(); ++i)
2387 out <<
" " << jm[i]->getName();
2388 const int idx = jm[i]->getJointIndex();
2395 out <<
"Link poses:" << std::endl;
2396 const std::vector<const LinkModel*>& lm =
robot_model_->getLinkModels();
2397 for (std::size_t i = 0; i < lm.size(); ++i)
2399 out <<
" " << lm[i]->getName() <<
": ";
2406 std::stringstream ss;
2407 ss <<
"ROBOT: " <<
robot_model_->getName() << std::endl;
2414 void getPoseString(std::ostream& ss,
const Eigen::Isometry3d& pose,
const std::string& pfx)
2417 for (
int y = 0;
y < 4; ++
y)
2420 for (
int x = 0;
x < 4; ++
x)
2422 ss << std::setw(8) << pose(
y,
x) <<
" ";
2432 std::string pfx = pfx0 +
"+--";
2434 ss << pfx <<
"Joint: " << jm->
getName() << std::endl;
2436 pfx = pfx0 + (last ?
" " :
"| ");
2446 ss << pfx <<
"Link: " << lm->
getName() << std::endl;
2454 for (std::vector<const JointModel*>::const_iterator it = lm->
getChildJointModels().begin();
void setJointPositions(const std::string &joint_name, const double *position)
random_numbers::RandomNumberGenerator & getRandomNumberGenerator()
Return the instance of a random number generator.
std::pair< double, const JointModel * > getMinDistanceToPositionBounds() const
Get the minimm distance from this state to the bounds. The minimum distance and the joint for which t...
A set of options for the kinematics solver.
Eigen::Isometry3d * variable_joint_transforms_
void updateMimicJoint(const JointModel *joint)
void zeroVelocities()
Set all velocities to 0.0.
bool knowsFrameTransform(const std::string &frame_id) const
Check if a transformation matrix from the model frame to frame frame_id is known. ...
const Eigen::Isometry3d & getVisualMeshOrigin() const
Get the transform for the visual mesh origin.
Core components of MoveIt!
const std::vector< shapes::ShapeConstPtr > & getShapes() const
Get shape associated to the collision geometry for this link.
bool checkJointTransforms(const JointModel *joint) const
This function is only called in debug mode.
void setJointGroupAccelerations(const std::string &joint_group_name, const double *gstate)
Given accelerations for the variables that make up a group, in the order found in the group (includin...
std::map< const LinkModel *, Eigen::Isometry3d, std::less< const LinkModel * >, Eigen::aligned_allocator< std::pair< const LinkModel *const, Eigen::Isometry3d > > > LinkTransformMap
Map from link model instances to Eigen transforms.
const Eigen::Isometry3d & getJointOriginTransform() const
When transforms are computed for this link, they are usually applied to the link's origin...
#define MOVEIT_CONSOLE_COLOR_RESET
double getVariablePosition(const std::string &variable) const
Get the position of a particular variable. An exception is thrown if the variable is not known...
bool setFromIKSubgroups(const JointModelGroup *group, const EigenSTL::vector_Isometry3d &poses, const std::vector< std::string > &tips, const std::vector< std::vector< double > > &consistency_limits, double timeout=0.0, const GroupStateValidityCallbackFn &constraint=GroupStateValidityCallbackFn(), const kinematics::KinematicsQueryOptions &options=kinematics::KinematicsQueryOptions())
setFromIK for multiple poses and tips (end effectors) when no solver exists for the jmg that can solv...
void harmonizePosition(const JointModel *joint)
#define ROS_ERROR_STREAM_NAMED(name, args)
void setJointEfforts(const JointModel *joint, const double *effort)
Vec3fX< details::Vec3Data< double > > Vector3d
#define ROS_WARN_NAMED(name,...)
void updateMimicJoints(const JointModelGroup *group)
Update all mimic joints within group.
const std::vector< unsigned int > & getKinematicsSolverJointBijection() const
Return the mapping between the order of the joints in this group and the order of the joints in the k...
std::vector< double > values
bool dirtyJointTransform(const JointModel *joint) const
bool hasJointModel(const std::string &joint) const
Check if a joint is part of this group.
int getJointIndex() const
Get the index of this joint within the robot model.
const JointModel * getParentJointModel() const
Get the joint model whose child this link is. There will always be a parent joint.
bool hasAttachedBody(const std::string &id) const
Check if an attached body named id exists in this state.
int getLinkIndex() const
The index of this joint when traversing the kinematic tree in depth first fashion.
bool setToIKSolverFrame(Eigen::Isometry3d &pose, const kinematics::KinematicsBaseConstPtr &solver)
Transform pose from the robot model's base frame to the reference frame of the IK solver...
void printDirtyInfo(std::ostream &out=std::cout) const
void getSubgroups(std::vector< const JointModelGroup *> &sub_groups) const
Get the groups that are subsets of this one (in terms of joints set)
void setVariableVelocities(const double *velocity)
Given an array with velocity values for all variables, set those values as the velocities in this sta...
void attachBody(AttachedBody *attached_body)
Add an attached body to this state. Ownership of the memory for the attached body is assumed by the s...
bool isValidVelocityMove(const RobotState &other, const JointModelGroup *group, double dt) const
Check that the time to move between two waypoints is sufficient given velocity limits and time step...
const JointModel * dirty_collision_body_transforms_
const Eigen::Isometry3d & getJointTransform(const std::string &joint_name)
void setJointGroupActivePositions(const JointModelGroup *group, const std::vector< double > &gstate)
Given positions for the variables of active joints that make up a group, in the order found in the gr...
void clearAttachedBodies()
Clear all attached bodies. This calls delete on the AttachedBody instances, if needed.
ROSCONSOLE_CONSOLE_IMPL_DECL std::string getName(void *handle)
void updateLinkTransformsInternal(const JointModel *start)
const std::string & getAttachedLinkName() const
Get the name of the link this body is attached to.
const std::string & getVisualMeshFilename() const
Get the filename of the mesh resource used for visual display of this link.
void harmonizePositions()
Call harmonizePosition() for all joints / all joints in group / given joint.
const AttachedBody * getAttachedBody(const std::string &name) const
Get the attached body named name. Return NULL if not found.
virtual void computeTransform(const double *joint_values, Eigen::Isometry3d &transf) const =0
Given the joint values for a joint, compute the corresponding transform.
bool checkCollisionTransforms() const
This function is only called in debug mode.
void copyJointGroupAccelerations(const std::string &joint_group_name, std::vector< double > &gstate) const
For a given group, copy the acceleration values of the variables that make up the group into another ...
Eigen::Isometry3d * global_link_transforms_
const LinkTransformMap & getAssociatedFixedTransforms() const
Get the set of links that are attached to this one via fixed transforms.
void setJointGroupVelocities(const std::string &joint_group_name, const double *gstate)
Given velocities for the variables that make up a group, in the order found in the group (including v...
static const int NO_IK_SOLUTION
double * getVariablePositions()
Get a raw pointer to the positions of the variables stored in this state. Use carefully. If you change these values externally you need to make sure you trigger a forced update for the state by calling update(true).
void printStatePositionsWithJointLimits(const moveit::core::JointModelGroup *jmg, std::ostream &out=std::cout) const
Output to console the current state of the robot's joint limits.
void setVariablePositions(const double *position)
It is assumed positions is an array containing the new positions for all variables in this state...
geometry_msgs::TransformStamped t
void markDirtyJointTransforms(const JointModel *joint)
static double testAbsoluteJointSpaceJump(const JointModelGroup *group, std::vector< RobotStatePtr > &traj, double revolute_jump_threshold, double prismatic_jump_threshold)
Tests for absolute joint space jumps of the trajectory traj.
const Eigen::Vector3d & getVisualMeshScale() const
Get the scale of the mesh resource for this link.
const LinkModel * getAttachedLink() const
Get the model of the link this body is attached to.
void setAttachedBodyUpdateCallback(const AttachedBodyCallback &callback)
bool dirtyLinkTransforms() const
void dropVelocities()
Remove velocities from this state (this differs from setting them to zero)
void computeVariableVelocity(const JointModelGroup *jmg, Eigen::VectorXd &qdot, const Eigen::VectorXd &twist, const LinkModel *tip) const
Given a twist for a particular link (tip), compute the corresponding velocity for every variable and ...
bool isChain() const
Check if this group is a linear chain.
void dropDynamics()
Reduce RobotState to kinematic information (remove velocity, acceleration and effort, if present)
bool isContiguousWithinState() const
void zeroAccelerations()
Set all accelerations to 0.0.
void setToDefaultValues()
Set all joints to their default positions. The default position is 0, or if that is not within bounds...
void copyJointGroupVelocities(const std::string &joint_group_name, std::vector< double > &gstate) const
For a given group, copy the velocity values of the variables that make up the group into another loca...
void computeAABB(std::vector< double > &aabb) const
Compute an axis-aligned bounding box that contains the current state. The format for aabb is (minx...
const std::vector< std::string > & getVariableNames() const
Get the names of the variables that make up this joint, in the order they appear in corresponding sta...
void copyFrom(const RobotState &other)
#define ROS_DEBUG_NAMED(name,...)
void getAttachedBodies(std::vector< const AttachedBody *> &attached_bodies) const
Get all bodies attached to the model corresponding to this state.
std::string getStateTreeString(const std::string &prefix="") const
void getStateTreeJointString(std::ostream &ss, const JointModel *jm, const std::string &pfx0, bool last) const
bool setFromIK(const JointModelGroup *group, const geometry_msgs::Pose &pose, double timeout=0.0, const GroupStateValidityCallbackFn &constraint=GroupStateValidityCallbackFn(), const kinematics::KinematicsQueryOptions &options=kinematics::KinematicsQueryOptions())
If the group this state corresponds to is a chain and a solver is available, then the joint values ca...
const LinkModel * getParentLinkModel() const
Get the link model whose child this link is (through some joint). There may not always be a parent li...
const std::string & getName() const
Get the name of the attached body.
Struct for containing jump_threshold.
void zeroEffort()
Set all effort values to 0.0.
virtual double distance(const double *value1, const double *value2) const =0
Compute the distance between two joint states of the same model (represented by the variable values) ...
void update(bool force=false)
Update all transforms.
boost::function< void(AttachedBody *body, bool attached)> AttachedBodyCallback
double computeCartesianPath(const JointModelGroup *group, std::vector< RobotStatePtr > &traj, const LinkModel *link, const Eigen::Vector3d &direction, bool global_reference_frame, double distance, const MaxEEFStep &max_step, const JumpThreshold &jump_threshold, const GroupStateValidityCallbackFn &validCallback=GroupStateValidityCallbackFn(), const kinematics::KinematicsQueryOptions &options=kinematics::KinematicsQueryOptions())
Compute the sequence of joint values that correspond to a straight Cartesian path for a particular gr...
void getRobotMarkers(visualization_msgs::MarkerArray &arr, const std::vector< std::string > &link_names, const std_msgs::ColorRGBA &color, const std::string &ns, const ros::Duration &dur, bool include_attached=false) const
Get a MarkerArray that fully describes the robot markers for a given robot.
TF2SIMD_FORCE_INLINE Quaternion inverse(const Quaternion &q)
static double testJointSpaceJump(const JointModelGroup *group, std::vector< RobotStatePtr > &traj, const JumpThreshold &jump_threshold)
Tests joint space jumps of a trajectory.
void setToRandomPositionsNearBy(const JointModelGroup *group, const RobotState &near, double distance)
Set all joints in group to random values near the value in . distance is the maximum amount each join...
unsigned char * dirty_joint_transforms_
void fromMsg(const A &, B &b)
std::size_t getVariableCount() const
Get the number of variables that describe this joint.
const std::string & getName() const
Get the name of the joint group.
This may be thrown if unrecoverable errors occur.
AttachedBodyCallback attached_body_update_callback_
This event is called when there is a change in the attached bodies for this state; The event specifie...
bool getJacobian(const JointModelGroup *group, const LinkModel *link, const Eigen::Vector3d &reference_point_position, Eigen::MatrixXd &jacobian, bool use_quaternion_representation=false) const
Compute the Jacobian with reference to a particular point on a given link, for a specified group...
static void checkInterpolationParamBounds(const char LOGNAME[], double t)
Struct for containing max_step for computeCartesianPath.
const LinkModel * getChildLinkModel() const
Get the link that this joint connects to. There will always be such a link.
bool integrateVariableVelocity(const JointModelGroup *jmg, const Eigen::VectorXd &qdot, double dt, const GroupStateValidityCallbackFn &constraint=GroupStateValidityCallbackFn())
Given the velocities for the variables in this group (qdot) and an amount of time (dt)...
const kinematics::KinematicsBaseConstPtr getSolverInstance() const
RobotState & operator=(const RobotState &other)
Copy operator.
static double testRelativeJointSpaceJump(const JointModelGroup *group, std::vector< RobotStatePtr > &traj, double jump_threshold_factor)
Tests for relative joint space jumps of the trajectory traj.
const std::string & getName() const
The name of this link.
#define MOVEIT_CONSOLE_COLOR_RED
bool constructMarkerFromShape(const Shape *shape, visualization_msgs::Marker &mk, bool use_mesh_triangle_list=false)
static const std::size_t MIN_STEPS_FOR_JUMP_THRESH
It is recommended that there are at least 10 steps per trajectory for testing jump thresholds with co...
boost::function< void(const geometry_msgs::Pose &ik_pose, const std::vector< double > &ik_solution, moveit_msgs::MoveItErrorCodes &error_code)> IKCallbackFn
Signature for a callback to validate an IK solution. Typically used for collision checking...
A joint from the robot. Models the transform that this joint applies in the kinematic chain...
void interpolate(const RobotState &to, double t, RobotState &state) const
void updateStateWithLinkAt(const std::string &link_name, const Eigen::Isometry3d &transform, bool backward=false)
Update the state after setting a particular link to the input global transform pose.
const Eigen::Isometry3d & getFrameTransform(const std::string &frame_id)
Get the transformation matrix from the model frame to the frame identified by frame_id.
bool getVariableDefaultPositions(const std::string &name, std::map< std::string, double > &values) const
Get the values that correspond to a named state as read from the URDF. Return false on failure...
const std::vector< const JointModel * > & getActiveJointModels() const
Get the active joints in this group (that have controllable DOF). This does not include mimic joints...
void copyJointGroupPositions(const std::string &joint_group_name, std::vector< double > &gstate) const
For a given group, copy the position values of the variables that make up the group into another loca...
RobotState(const RobotModelConstPtr &robot_model)
A state can be constructed from a specified robot model. No values are initialized. Call setToDefaultValues() if a state needs to provide valid information.
void printTransforms(std::ostream &out=std::cout) const
int getFirstCollisionBodyTransformIndex() const
const std::string LOGNAME
void printStatePositions(std::ostream &out=std::cout) const
const std::vector< const JointModel * > & getContinuousJointModels() const
Get the array of continuous joints used in this group (may include mimic joints). ...
const std::vector< const JointModel * > & getChildJointModels() const
A link may have 0 or more child joints. From those joints there will certainly be other descendant li...
bool dirtyCollisionBodyTransforms() const
ROSCPP_DECL bool del(const std::string &key)
const LinkModel * getLinkModel(const std::string &link) const
Get the model of a particular link.
void dropEffort()
Remove effort values from this state (this differs from setting them to zero)
int getVariableGroupIndex(const std::string &variable) const
Get the index of a variable within the group. Return -1 on error.
void getMissingKeys(const std::map< std::string, double > &variable_map, std::vector< std::string > &missing_variables) const
unsigned int getActiveVariableCount() const
Get the number of variables that describe the active joints in this joint group. This excludes variab...
bool setFromDiffIK(const JointModelGroup *group, const Eigen::VectorXd &twist, const std::string &tip, double dt, const GroupStateValidityCallbackFn &constraint=GroupStateValidityCallbackFn())
Set the joint values from a Cartesian velocity applied during a time dt.
void printTransform(const Eigen::Isometry3d &transform, std::ostream &out=std::cout) const
const JointModel * dirty_link_transforms_
std::size_t getVariableCount() const
Get the number of variables that make up this state.
bool isLinkUpdated(const std::string &name) const
True if this name is in the set of links that are to be updated when the state of this group changes...
bool satisfiesBounds(double margin=0.0) const
const Eigen::Isometry3d & getGlobalLinkTransform(const std::string &link_name)
void setJointGroupPositions(const std::string &joint_group_name, const double *gstate)
Given positions for the variables that make up a group, in the order found in the group (including va...
random_numbers::RandomNumberGenerator * rng_
For certain operations a state needs a random number generator. However, it may be slightly expensive...
void setToRandomPositions()
Set all joints to random values. Values will be within default bounds.
void dropAccelerations()
Remove accelerations from this state (this differs from setting them to zero)
const std::vector< int > & getVariableIndexList() const
Get the index locations in the complete robot state for all the variables in this group...
RobotModelConstPtr robot_model_
void setVariableAccelerations(const double *acceleration)
Given an array with acceleration values for all variables, set those values as the accelerations in t...
#define ROS_ERROR_NAMED(name,...)
Eigen::Isometry3d * global_collision_body_transforms_
void updateCollisionBodyTransforms()
Update the transforms for the collision bodies. This call is needed before calling collision checking...
void extendWithTransformedBox(const Eigen::Isometry3d &transform, const Eigen::Vector3d &box)
Extend with a box transformed by the given transform.
Representation of a robot's state. This includes position, velocity, acceleration and effort...
void updateLinkTransforms()
Update the reference frame transforms for links. This call is needed before using the transforms of l...
A link from the robot. Contains the constant transform applied to the link and its geometry...
std::vector< Eigen::Isometry3d, Eigen::aligned_allocator< Eigen::Isometry3d > > vector_Isometry3d
bool hasLinkModel(const std::string &link) const
Check if a link is part of this group.
void setVariableEffort(const double *effort)
Given an array with effort values for all variables, set those values as the effort in this state...
unsigned int getVariableCount() const
Get the number of variables that describe this joint group. This includes variables necessary for mim...
int getFirstVariableIndex() const
Get the index of this joint's first variable within the full robot state.
const std::vector< const LinkModel * > & getLinkModels() const
Get the links that are part of this joint group.
Main namespace for MoveIt!
const std::vector< const JointModel * > & getJointModels() const
Get all the joints in this group (including fixed and mimic joints).
Eigen::Vector3d computeShapeExtents(const ShapeMsg &shape_msg)
void computeTransform(const Eigen::Isometry3d &parent_link_global_transform)
Recompute global_collision_body_transform given the transform of the parent link. ...
bool checkLinkTransforms() const
This function is only called in debug mode.
Object defining bodies that can be attached to robot links. This is useful when handling objects pick...
const std::vector< const LinkModel * > & getDescendantLinkModels() const
Get all the link models that descend from this joint, in the kinematic tree.
std::ostream & operator<<(std::ostream &out, const VariableBounds &b)
Operator overload for printing variable bounds to a stream.
std::vector< VariableBounds > Bounds
The datatype for the joint bounds.
double distance(const RobotState &other) const
Return the sum of joint distances to "other" state. Only considers active joints. ...
const LinkModel * getParentLinkModel() const
Get the link that this joint connects to. The robot is assumed to start with a joint, so the root joint will return a NULL pointer here.
JointType getType() const
Get the type of joint.
boost::function< bool(RobotState *robot_state, const JointModelGroup *joint_group, const double *joint_group_variable_values)> GroupStateValidityCallbackFn
Signature for functions that can verify that if the group joint_group in robot_state is set to joint_...
const double * getJointPositions(const std::string &joint_name) const
std::map< std::string, AttachedBody * > attached_body_map_
All attached bodies that are part of this state, indexed by their name.
void printStateInfo(std::ostream &out=std::cout) const
double getDefaultIKTimeout() const
Get the default IK timeout.
const EigenSTL::vector_Isometry3d & getFixedTransforms() const
Get the fixed transform (the transforms to the shapes associated with this body)
bool clearAttachedBody(const std::string &id)
Remove the attached body named id. Return false if the object was not found (and thus not removed)...
void invertVelocity()
Invert velocity if present.
Represents an axis-aligned bounding box.
const std::string & getName() const
Get the name of the joint.