Skip to content

Commit

Permalink
Bugfixes from testing with Kinova Gen3
Browse files Browse the repository at this point in the history
  • Loading branch information
sea-bass committed Sep 29, 2023
1 parent 95bf319 commit c5051b5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/ik_gradient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,13 @@ auto step(GradientIk& self, Robot const& robot, CostFn const& cost_fn, double st
// (move along gradient direction by estimated step size)
for (size_t i = 0; i < count; ++i) {
auto const& var = robot.variables[i];
auto updated_value = self.local[i] - self.gradient[i] * joint_diff;
if (var.bounded) {
self.working[i] =
std::clamp(self.local[i] - self.gradient[i] * joint_diff, var.min, var.max);
self.working[i] = std::clamp(updated_value, var.min, var.max);
} else {
self.working[i] = std::clamp(updated_value,
self.local[i] - var.span / 2.0,
self.local[i] + var.span / 2.0);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/ik_memetic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ void MemeticIk::reproduce(Robot const& robot, CostFn const& cost_fn) {
// Clamp to valid joint values
if (joint.bounded) {
gene = std::clamp(gene, joint.min, joint.max);
} else {
gene = std::clamp(gene,
original_gene - joint.span / 2.0,
original_gene + joint.span / 2.0);
}

// Approximate gradient
Expand Down
2 changes: 1 addition & 1 deletion src/robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <moveit/robot_state/robot_state.h>

namespace {
constexpr double kUnboundedVariableSpan = 1.0;
constexpr double kUnboundedVariableSpan = 2.0 * M_PI;
constexpr double kUnboundedJointSampleSpread = M_PI;
} // namespace

Expand Down

0 comments on commit c5051b5

Please sign in to comment.