Skip to content

Commit

Permalink
RobotState interpolation: warn if interpolation parameter is out of r…
Browse files Browse the repository at this point in the history
…ange [0, 1] (moveit#2664)
  • Loading branch information
John Stechschulte authored and rhaschke committed May 23, 2021
1 parent 5b96982 commit eb6b630
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ namespace core
{
MOVEIT_CLASS_FORWARD(RobotModel); // Defines RobotModelPtr, ConstPtr, WeakPtr... etc

static inline void checkInterpolationParamBounds(const char LOGNAME[], double t)
{
if (std::isnan(t) || std::isinf(t))
{
throw Exception("Interpolation parameter is NaN or inf.");
}
ROS_WARN_STREAM_COND_NAMED(t < 0. || t > 1., LOGNAME, "Interpolation parameter is not in the range [0, 1]: " << t);
}

/** \brief Definition of a kinematic model. This class is not thread
safe, however multiple instances can be created */
class RobotModel
Expand Down
6 changes: 5 additions & 1 deletion moveit_core/robot_model/src/robot_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ namespace moveit
{
namespace core
{
const std::string LOGNAME = "robot_model";
namespace
{
constexpr char LOGNAME[] = "robot_model";
} // namespace

RobotModel::RobotModel(const urdf::ModelInterfaceSharedPtr& urdf_model, const srdf::ModelConstSharedPtr& srdf_model)
{
Expand Down Expand Up @@ -1275,6 +1278,7 @@ double RobotModel::distance(const double* state1, const double* state2) const

void RobotModel::interpolate(const double* from, const double* to, double t, double* state) const
{
moveit::core::checkInterpolationParamBounds(LOGNAME, t);
// we interpolate values only for active joint models (non-mimic)
for (std::size_t i = 0; i < active_joint_model_vector_.size(); ++i)
active_joint_model_vector_[i]->interpolate(from + active_joint_model_start_index_[i],
Expand Down
7 changes: 6 additions & 1 deletion moveit_core/robot_state/src/robot_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ namespace core
* valid paths from paths with large joint space jumps. */
static const std::size_t MIN_STEPS_FOR_JUMP_THRESH = 10;

const std::string LOGNAME = "robot_state";
namespace
{
constexpr char LOGNAME[] = "robot_state";
} // namespace

RobotState::RobotState(const RobotModelConstPtr& robot_model)
: robot_model_(robot_model)
Expand Down Expand Up @@ -910,6 +913,7 @@ double RobotState::distance(const RobotState& other, const JointModelGroup* join

void RobotState::interpolate(const RobotState& to, double t, RobotState& state) const
{
moveit::core::checkInterpolationParamBounds(LOGNAME, t);
robot_model_->interpolate(getVariablePositions(), to.getVariablePositions(), t, state.getVariablePositions());

memset(state.dirty_joint_transforms_, 1, state.robot_model_->getJointModelCount() * sizeof(unsigned char));
Expand All @@ -918,6 +922,7 @@ void RobotState::interpolate(const RobotState& to, double t, RobotState& state)

void RobotState::interpolate(const RobotState& to, double t, RobotState& state, const JointModelGroup* joint_group) const
{
moveit::core::checkInterpolationParamBounds(LOGNAME, t);
const std::vector<const JointModel*>& jm = joint_group->getActiveJointModels();
for (std::size_t i = 0; i < jm.size(); ++i)
{
Expand Down

0 comments on commit eb6b630

Please sign in to comment.