Skip to content

Commit

Permalink
inserted formula in victors method
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahfredrickson committed Oct 28, 2023
1 parent 68c9c5b commit 05b8a0a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/control/PlanarArmController.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,19 @@ template <unsigned int N> class PlanarArmController {
double radius = kin.getSegLens().sum() * safetyFactor;

if (eePos.norm() > radius) {
// TODO: will need to eventually shrink velocity vector until it is within radius
// instead of just normalizing it.

eePos.normalize();
eePos *= radius;
double radius = kin.getSegLens().sum();
// new position is outside of bounds. Set new EE setpoint so it will follow the velocity
// vector instead of drifting along the radius.
// setpoint = setpoint inside circle
// eePos = new setpoint outside circle
double diffDotProd = (eePos - setpoint).dot(setpoint);
double differenceNorm = (eePos - setpoint).squaredNorm();
double discriminant =
std::pow(diffDotProd, 2) -
differenceNorm * (setpoint.squaredNorm() - std::pow(radius, 2));
double a = -diffDotProd + std::sqrt(discriminant) / differenceNorm;
eePos = (1 - a) * setpoint + a * eePos;
}

return eePos;
}
};
Expand Down

0 comments on commit 05b8a0a

Please sign in to comment.