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

[ros2] don't wrap continuous joint angles #16

Open
wants to merge 1 commit into
base: ros2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/bio_ik/robot_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class RobotInfo
std::vector<VariableInfo> variables;
std::vector<size_t> activeVariables;
std::vector<moveit::core::JointModel::JointType> variable_joint_types;
std::vector<bool> has_bounds;
moveit::core::RobotModelConstPtr robot_model;

__attribute__((always_inline)) static inline double clamp2(double v, double lo, double hi)
Expand Down Expand Up @@ -97,6 +98,7 @@ class RobotInfo
info.max_velocity_rcp = info.max_velocity > 0.0 ? 1.0 / info.max_velocity : 0.0;

variables.push_back(info);
has_bounds.push_back(bounded);
}

for(size_t ivar = 0; ivar < model->getVariableCount(); ivar++)
Expand All @@ -120,6 +122,7 @@ class RobotInfo

inline bool isRevolute(size_t variable_index) const { return variable_joint_types[variable_index] == moveit::core::JointModel::REVOLUTE; }
inline bool isPrismatic(size_t variable_index) const { return variable_joint_types[variable_index] == moveit::core::JointModel::PRISMATIC; }
inline bool hasBounds(size_t variable_index) const { return has_bounds[variable_index]; }
inline double getMaxVelocity(size_t i) const { return variables[i].max_velocity; }
inline double getMaxVelocityRcp(size_t i) const { return variables[i].max_velocity_rcp; }
};
Expand Down
14 changes: 9 additions & 5 deletions src/kinematics_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,8 @@ struct BioIKKinematicsPlugin : kinematics::KinematicsBase {
if (robot_info.isRevolute(ivar) &&
robot_model_->getMimicJointModels().empty()) {
auto r = problem.initial_guess[ivar];
auto lo = robot_info.getMin(ivar);
auto hi = robot_info.getMax(ivar);
auto lo = robot_info.getClipMin(ivar);
auto hi = robot_info.getClipMax(ivar);

// move close to initial guess
if (r < v - M_PI || r > v + M_PI) {
Expand All @@ -555,10 +555,14 @@ struct BioIKKinematicsPlugin : kinematics::KinematicsBase {
v = hi;
}
state[ivar] = v;
}

// wrap angles
robot_model_->enforcePositionBounds(state.data());
// wrap angles that are bounded
if(robot_info.hasBounds(ivar))
{
auto* joint_model = robot_model_->getJointOfVariable(ivar);
joint_model->enforcePositionBounds(state.data() + ivar, joint_model->getVariableBounds());
}
}

// map result to jointgroup variables
{
Expand Down