Skip to content

Commit

Permalink
implemented arm constraint formula
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahfredrickson committed Oct 2, 2023
1 parent c39dbd4 commit 828543d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/control/PlanarArmController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <initializer_list>
#include <mutex>
#include <numeric>
#include <cmath>
#include <optional>

#include <Eigen/Core>
Expand Down Expand Up @@ -65,13 +66,20 @@ template <unsigned int N> class PlanarArmController {

// bounds check (new pos + vel vector <= sum of joint lengths)
double radius = kin.getSegLens().sum();
Eigen::Vector2d constrainedPos = pos;
if (pos.norm() > radius) {
// new position is outside of bounds
// TODO: will need to eventually shrink velocity vector until it is within radius
// instead of just normalizing it
pos.normalize();
// new position is outside of bounds. Shrink the velocity vector until it is within
// radius setpoint = setpoint inside circle pos = new setpoint outside circle
double diffDotProd = (pos - setpoint).dot(setpoint);
double differenceNorm = (pos - setpoint).squaredNorm();
double a =
-1 * diffDotProd +
std::sqrt(std::pow(diffDotProd, 2) -
differenceNorm * (setpoint.squaredNorm() - std::pow(radius, 2))) /
differenceNorm;
constrainedPos = (1 - a) * setpoint + a * pos;
}
return pos;
return constrainedPos;
}

/**
Expand Down

0 comments on commit 828543d

Please sign in to comment.