Skip to content
This repository has been archived by the owner on Dec 30, 2024. It is now read-only.

Commit

Permalink
Improve OTOSLocalizer and PinpointLocalizer performance
Browse files Browse the repository at this point in the history
  • Loading branch information
TBHGodPro committed Oct 26, 2024
1 parent 6830a82 commit 4e18dae
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ public Pose getPose() {
SparkFunOTOS.Pose2D rawPose = otos.getPosition();
Pose pose = new Pose(rawPose.x, rawPose.y, rawPose.h);

Vector vec = pose.getVector();
vec.rotateVector(startPose.getHeading());

return MathFunctions.addPoses(startPose, new Pose(vec.getXComponent(), vec.getYComponent(), pose.getHeading()));
return MathFunctions.addPoses(startPose, MathFunctions.rotatePose(pose, startPose.getHeading(), false));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ public Pose getPose() {
Pose2D rawPose = odo.getPosition();
Pose pose = new Pose(rawPose.getX(DistanceUnit.INCH), rawPose.getY(DistanceUnit.INCH), rawPose.getHeading(AngleUnit.RADIANS));

Vector vec = pose.getVector();
vec.rotateVector(startPose.getHeading());

return MathFunctions.addPoses(startPose, new Pose(vec.getXComponent(), vec.getYComponent(), pose.getHeading()));
return MathFunctions.addPoses(startPose, MathFunctions.rotatePose(pose, startPose.getHeading(), false));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,22 @@ public static Pose subtractPoses(Pose one, Pose two) {
return new Pose(one.getX() - two.getX(), one.getY() - two.getY(), one.getHeading() - two.getHeading());
}

/**
* This rotates the given pose by the given theta,
*
* @param pose the Pose to rotate.
* @param theta the angle to rotate by.
* @param rotateHeading whether to adjust the Pose heading too.
* @return the rotated Pose.
*/
public static Pose rotatePose(Pose pose, double theta, boolean rotateHeading) {
double x = pose.getX() * Math.cos(theta) - pose.getY() * Math.sin(theta);
double y = pose.getX() * Math.sin(theta) + pose.getY() * Math.cos(theta);
double heading = rotateHeading ? normalizeAngle(pose.getHeading() + theta) : pose.getHeading();

return new Pose(x, y, heading);
}

/**
* This multiplies a Point by a scalar and returns the result as a Point
*
Expand Down

0 comments on commit 4e18dae

Please sign in to comment.